| ... | @@ -514,19 +514,27 @@ export default function Sidebar() { | ... | @@ -514,19 +514,27 @@ export default function Sidebar() { |
| 514 | | 514 | |
| 515 | const commitRename = useCallback( | 515 | const commitRename = useCallback( |
| 516 | async (threadId: ThreadId, newTitle: string, originalTitle: string) => { | 516 | async (threadId: ThreadId, newTitle: string, originalTitle: string) => { |
| | 517 | const finishRename = () => { |
| | 518 | setRenamingThreadId((current) => { |
| | 519 | if (current !== threadId) return current; |
| | 520 | renamingInputRef.current = null; |
| | 521 | return null; |
| | 522 | }); |
| | 523 | }; |
| | 524 | |
| 517 | const trimmed = newTitle.trim(); | 525 | const trimmed = newTitle.trim(); |
| 518 | if (trimmed.length === 0) { | 526 | if (trimmed.length === 0) { |
| 519 | toastManager.add({ type: "warning", title: "Thread title cannot be empty" }); | 527 | toastManager.add({ type: "warning", title: "Thread title cannot be empty" }); |
| 520 | cancelRename(); | 528 | finishRename(); |
| 521 | return; | 529 | return; |
| 522 | } | 530 | } |
| 523 | if (trimmed === originalTitle) { | 531 | if (trimmed === originalTitle) { |
| 524 | cancelRename(); | 532 | finishRename(); |
| 525 | return; | 533 | return; |
| 526 | } | 534 | } |
| 527 | const api = readNativeApi(); | 535 | const api = readNativeApi(); |
| 528 | if (!api) { | 536 | if (!api) { |
| 529 | cancelRename(); | 537 | finishRename(); |
| 530 | return; | 538 | return; |
| 531 | } | 539 | } |
| 532 | try { | 540 | try { |
| ... | @@ -543,13 +551,9 @@ export default function Sidebar() { | ... | @@ -543,13 +551,9 @@ export default function Sidebar() { |
| 543 | description: error instanceof Error ? error.message : "An error occurred.", | 551 | description: error instanceof Error ? error.message : "An error occurred.", |
| 544 | }); | 552 | }); |
| 545 | } | 553 | } |
| 546 | setRenamingThreadId((current) => { | 554 | finishRename(); |
| 547 | if (current !== threadId) return current; | | |
| 548 | renamingInputRef.current = null; | | |
| 549 | return null; | | |
| 550 | }); | | |
| 551 | }, | 555 | }, |
| 552 | [cancelRename], | 556 | [], |
| 553 | ); | 557 | ); |
| 554 | | 558 | |
| 555 | const handleThreadContextMenu = useCallback( | 559 | const handleThreadContextMenu = useCallback( |