fix(ui): preserve draft and effort selections

This commit is contained in:
Iuliia Ivashko
2026-09-03 17:32:24 +03:00
parent 5995802fe3
commit 77d756aebb
12 changed files with 367 additions and 73 deletions
@@ -347,6 +347,8 @@ function SessionNodeItemComponent(props: SessionNodeItemProps): React.ReactNode
const renameDraftRef = React.useRef(renameDraft);
renameDraftRef.current = renameDraft;
const renameTargetRef = React.useRef<string | null>(null);
const pendingRenameSelectRef = React.useRef(false);
const renameInputRef = React.useRef<HTMLInputElement>(null);
const formRef = React.useRef<HTMLFormElement>(null);
const session = node.session;
@@ -633,9 +635,24 @@ function SessionNodeItemComponent(props: SessionNodeItemProps): React.ReactNode
}
if (renameTargetRef.current === session.id) return;
renameTargetRef.current = session.id;
pendingRenameSelectRef.current = true;
setRenameDraft(editTitle);
}, [editingId, editTitle, session.id]);
// Entering rename mode selects the whole title, so the first keystroke
// replaces it instead of appending to it. The selection waits for the commit
// that actually renders `editTitle`: the draft state above is seeded when the
// row mounts, so on a session whose title changed since then the input still
// holds the old text during the commit that opens the form.
React.useLayoutEffect(() => {
if (editingId !== session.id || !pendingRenameSelectRef.current) return;
const input = renameInputRef.current;
if (!input || input.value !== editTitle) return;
pendingRenameSelectRef.current = false;
input.focus();
input.select();
}, [editingId, editTitle, renameDraft, session.id]);
if (editingId === session.id) {
return (
<div
@@ -656,6 +673,7 @@ function SessionNodeItemComponent(props: SessionNodeItemProps): React.ReactNode
}}
>
<input
ref={renameInputRef}
value={renameDraft}
onChange={(event) => setRenameDraft(event.target.value)}
className="flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground"