[codex] Restore notebook cell focus#206
Conversation
Signed-off-by: Jeremy lewi <jeremy@lewi.us>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d36fa4905
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| setRendered(true); | ||
| setPendingRestoreTarget("rendered"); | ||
| }, [restoreFocusRequest, restoreFocusRole, value]); |
There was a problem hiding this comment.
Gate focus-restore effect to new requests only
This effect re-applies restore logic whenever value changes while restoreFocusRequest > 0, so after a single restore event the markdown cell can be forced back into rendered mode on each keystroke when restoreFocusRole is "rendered". In practice: focus a rendered markdown cell, switch away and back (request increments), then enter edit mode and type — the value update retriggers this effect and immediately flips the cell out of the editor. The restore behavior should run only when the request counter changes, not on content edits.
Useful? React with 👍 / 👎.
Signed-off-by: Jeremy lewi <jeremy@lewi.us>
Signed-off-by: Jeremy lewi <jeremy@lewi.us>
Signed-off-by: Jeremy lewi <jeremy@lewi.us>
Signed-off-by: Jeremy lewi <jeremy@lewi.us>
Signed-off-by: Jeremy lewi <jeremy@lewi.us>
Summary
localStorageWhy
Switching away from the browser tab while editing markdown caused the cell to blur back into rendered mode, which made note-taking and copy/paste workflows awkward. The original counter-based restore path was also fragile because unrelated re-renders could replay restore logic. Persisting
{ docUri -> activeCellId, focusRole }gives a simpler model and better refresh behavior.Design
Validation
runme run build testpnpm -C app exec vitest run src/components/Actions/Actions.test.tsx src/components/Actions/MarkdownCell.test.tsx src/lib/notebookActiveCellState.test.tspnpm -C app exec tsc --target es2020 --module nodenext --moduleResolution nodenext --esModuleInterop --skipLibCheck --outDir test/browser/.generated test/browser/test-scenario-notebook-focus-persistence.tsCUJ_FRONTEND_URL=http://localhost:4173 node app/test/browser/.generated/test-scenario-notebook-focus-persistence.jsapp/test/browser/test-output/scenario-notebook-focus-persistence-walkthrough.webm