Skip to content

Fix note editor jumps html focus#4687

Open
Yuukidiv wants to merge 2 commits intoankitects:mainfrom
Yuukidiv:fix-note-editor-jumps-html-focus
Open

Fix note editor jumps html focus#4687
Yuukidiv wants to merge 2 commits intoankitects:mainfrom
Yuukidiv:fix-note-editor-jumps-html-focus

Conversation

@Yuukidiv
Copy link
Copy Markdown
Contributor

Linked issue (required)

Closes #4234

Summary / motivation (required)

When the HTML editor (</>) is open and focused in the browser's note editor, switching to a different note and then scrolling and then clicking (anywhere) causes the view to jump back to the HTML editor's position. This happens because the refocus() triggers both the browser's native scroll to focused element and CodeMirror's internal scroll to cursor behavior.

The fix prevents scrolling during refocus in two places:

PlainTextInput.svelte: use focus({ preventScroll: true }) instead of editor.focus() in refocus() to prevent the browser from scrolling the focused element into view
code-mirror.ts: pass { scroll: false } to setSelections() in the focus handler to prevent CodeMirror from internally scrolling to the restored cursor position.

Steps to reproduce (required, use N/A if not applicable)

(Following the original issue instructions)
In the browser:

  1. Open HTML editor for any field
  2. Click inside, putting focus in the HTML editor input
  3. Select a different note
  4. Scroll to a different part in the note editor and click anywhere
    The view jumps to the position of the HTML editor where the focus was previously

How to test (required)

Follow the original issue related to this pull request. There is a video showing the problem.

Checklist (minimum)

  • I ran ./ninja check or an equivalent relevant check locally.

Details

Risk / compatibility / migration (optional)

Changes are scoped to two lines in two files. Only the refocus() code path is affected. User's focus behavior is unchanged.

Scope

  • This PR is focused on one change (no unrelated edits).

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.

Note editor jumps when previous focus was in HTML editor

1 participant