Skip to content

Revert "fix(markdown): return focus to editor from find bar" (#23175) - #24500

Merged
AmethystLiang merged 1 commit into
mainfrom
markdown-jumps-when-clicking-into
Oct 2, 2026
Merged

AmethystLiang merged 1 commit into
mainfrom
markdown-jumps-when-clicking-into

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 0 0 0 0
Prod 1 0 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13

ELI5

In the rich Markdown editor, clicking somewhere in the document could throw you back to the top of the file. This undoes the recent change that caused it.

What Changed

Reverts #23175.

  • Before: switch a Markdown file from code view to editor view, scroll down, and click (or drag to select) in the text. The editor jumps to the top of the document, and a selection can appear near the start of the file instead of where you clicked.
  • After: the click puts the cursor where you clicked and the view stays put.

Mechanism: #23175 added a mousedown handler on the rich editor's scroll area. On every left-click inside the document it called Tiptap's editor.commands.focus(). If the editor isn't focused yet (for example, right after switching from code view, when focus is still on the view toggle), that call:

  1. keeps the editor's current selection, which is still at the start of the document, because nothing has moved it since mount;
  2. focuses the editor and runs scrollIntoView() on the next animation frame. That frame fires before ProseMirror handles the mouseup, which is when the click actually moves the caret.

So the view scrolls to the old caret at the top of the document. Removing the handler lets the browser and ProseMirror focus the editor and place the caret themselves.

Why

#23175 was a narrow workaround for #22693 (with the find bar open, keystrokes went to the find bar instead of the document). It caused a worse regression: the editor jumps to the top whenever you click in a document that isn't focused. Reverting is the smallest safe change.

Trade-off: #22693 may come back in rich Markdown mode while the find bar is open. That issue also reports the same focus problem in .ts/.json files, which use the code editor and were never covered by #23175, so the real fix for #22693 is to find what pulls focus back to the find bar. That will be a separate change.

Underlying problem, for a follow-up: after a code → editor switch, the rich editor's selection is left at the start of the document while scroll is restored to the middle. Any focus()/scrollIntoView() call without a position will jump to the top. Carrying the cursor across mode switches (and keeping cursor and scroll together) would fix that whole class of bugs; it's related to #14800 / #14940.

Linked Issue

Fixes #23596

Visual Proof

Pending. A before/after recording will be added.

Testing

  • pnpm tc:web passes; oxlint is clean on the changed file.

  • Not yet manually verified in the running app.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

No tests added: this is a pure revert of a 13-line handler that had no tests.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Renderer-only change that removes code. No impact on SSH/remote, mobile, or cross-platform paths beyond the possible return of #22693 described above.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Reverts focus-handling logic in the markdown editor.

The revert appears safe to merge, with a non-blocking test gap for the reported interaction.

Findings

  1. P2 Click regression lacks a test ▶

Summary

This PR reverts the rich Markdown editor’s document-mousedown focus handler to avoid scrolling to a stale caret before a click places the new one.

  • The remaining mousedown handler still focuses an empty editor when its blank surface is clicked.
  • The reported click-and-scroll regression lacks an automated interaction test.

Reviews (1) · Last reviewed commit: "Revert "fix(markdown): return focus to e..."

Comment on lines 211 to 212
onMouseDown={(event) => {
if (shouldReturnFocusToEditor(event)) {
// Keep the find bar open while handing keyboard focus back to the document.
searchState.searchInputRef.current?.blur()
editor?.commands.focus()
}
if (!shouldFocusEmptyEditorFromSurfaceClick(event, editor)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Click regression lacks a test The existing scroll-restoration test checks the viewport after a tab switch but never clicks the document. A test that switches from code view, scrolls down, then clicks or drags in the rich editor could check both the viewport and caret position. Without it, a future focus change could bring back the jump to the top without being caught.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Revert of #23175 in RichMarkdownEditorSurface.tsx — deletes the shouldReturnFocusToEditor helper and the onMouseDown branch that blurred the find input and called editor.commands.focus() on any left-click in .ProseMirror, restoring pre-#23175 click behavior.

The deletion is an exact inverse of the #23175 merge commit d9d5993 (same file, +13/-0), and no test referenced the removed helper, so the revert is complete and leaves no dead code (searchState.searchInputRef is still consumed by RichMarkdownSearchBar). The handler left behind (shouldFocusEmptyEditorFromSurfaceClick) is pre-existing and unchanged.

One process note: #22693 was closed by #23175, so reverting returns that bug (rich Markdown while the find bar is open) while the issue stays closed. Since the PR already frames the real fix as a separate change, it is worth reopening or re-linking #22693 so the regression is not lost. Not blocking — the trade-off is explicit and the analysis is sound.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c71e2f4f-d642-4c19-a413-65b51e5b7aab

📥 Commits

Reviewing files that changed from the base of the PR and between 4534087 and 3ca1e08.

📒 Files selected for processing (1)
  • src/renderer/src/components/editor/RichMarkdownEditorSurface.tsx
💤 Files with no reviewable changes (1)
  • src/renderer/src/components/editor/RichMarkdownEditorSurface.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The rich Markdown editor no longer blurs the search input and returns focus to the editor when a left-click occurs inside .ProseMirror. The existing empty-editor click handling remains.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 3ca1e

Normal clicks can return focus to the editor without the removed focus command that caused the reported scroll jump. No merge-blocking issue is established.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: reverting the focus-handling fix that caused the rich Markdown editor regression.
Description check ✅ Passed The description is complete and focused. It explains the user impact, mechanism, rationale, linked issue, trade-off, testing status, and scope. Visual proof and manual verification remain pending, but…
Linked Issues check ✅ Passed The PR addresses [#23596]. It removes the scroll-area mousedown path that called editor?.commands.focus() for clicks inside .ProseMirror. Browser and ProseMirror can therefore keep the clicked sel…
Out of Scope Changes check ✅ Passed The whole-PR diff changes only RichMarkdownEditorSurface.tsx. It removes the focus-and-blur handler that can cause the reported rich Markdown selection jump. The remaining empty-editor focus behavio…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AmethystLiang
AmethystLiang merged commit 9e34bd0 into main Oct 2, 2026
26 of 28 checks passed
Jinwoo-H pushed a commit that referenced this pull request Oct 2, 2026
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.

[Bug]: Rich Markdown editor jumps to top of document when selecting/copying text

1 participant