Skip to content

[codex] Restore notebook cell focus#206

Merged
jlewi merged 6 commits into
mainfrom
codex/restore-notebook-focus
May 15, 2026
Merged

[codex] Restore notebook cell focus#206
jlewi merged 6 commits into
mainfrom
codex/restore-notebook-focus

Conversation

@jlewi
Copy link
Copy Markdown
Collaborator

@jlewi jlewi commented May 13, 2026

Summary

  • persist per-notebook active cell UI state in localStorage
  • restore focus only for the visible notebook tab instead of replaying a restore counter
  • reopen markdown cells in editor mode on refresh when the editor was the last active surface
  • persist markdown editor focus explicitly when Monaco takes focus, so markdown reload restores the editor reliably
  • add a design note and a Chromium CUJ scenario for notebook focus persistence

Why

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 test
  • pnpm -C app exec vitest run src/components/Actions/Actions.test.tsx src/components/Actions/MarkdownCell.test.tsx src/lib/notebookActiveCellState.test.ts
  • pnpm -C app exec tsc --target es2020 --module nodenext --moduleResolution nodenext --esModuleInterop --skipLibCheck --outDir test/browser/.generated test/browser/test-scenario-notebook-focus-persistence.ts
  • CUJ_FRONTEND_URL=http://localhost:4173 node app/test/browser/.generated/test-scenario-notebook-focus-persistence.js
  • Chromium walkthrough artifact: app/test/browser/test-output/scenario-notebook-focus-persistence-walkthrough.webm

Signed-off-by: Jeremy lewi <jeremy@lewi.us>
@jlewi jlewi marked this pull request as ready for review May 14, 2026 00:45
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +249 to +251
setRendered(true);
setPendingRestoreTarget("rendered");
}, [restoreFocusRequest, restoreFocusRole, value]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

jlewi added 5 commits May 13, 2026 23:12
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>
@jlewi jlewi enabled auto-merge (squash) May 15, 2026 00:48
@jlewi jlewi merged commit 89f866a into main May 15, 2026
3 checks passed
@jlewi jlewi deleted the codex/restore-notebook-focus branch May 15, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant