fix(frontend): prevent markdown editor from scrolling to bottom on Enter key#3843
Draft
fix(frontend): prevent markdown editor from scrolling to bottom on Enter key#3843
Conversation
…ter key
Two issues fixed in the KEY_ENTER_COMMAND handler in markdownPlugin:
1. insertRawText("\n") causes Lexical to reconcile the DOM and set the
browser selection at the new cursor position, which triggers the
browser's native scroll-into-view behavior. Fix: save scrollTop
before the insertion and restore it via requestAnimationFrame after
both the discrete update and the merge-back update listener.
2. The command handler unconditionally returned true, claiming to handle
the Enter key even when the cursor was not in a markdown code node.
This prevented Lexical's default rich-text Enter behavior from
running. Fix: use a read-only check first and return false early
when not in a markdown CodeNode.
Also adds scroll protection to the registerUpdateListener that merges
trailing nodes back into the markdown CodeNode, since that second
editor.update() can trigger its own scroll jump.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Railway Preview Environment
Updated at 2026-02-26T18:34:35.088Z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where pressing Enter in the markdown editing mode of the prompt editor causes it to scroll to the bottom of the text, forcing the user to re-scroll after every newline.
Root Cause
Two issues in the
KEY_ENTER_COMMANDhandler inmarkdownPlugin.tsx:Scroll jump from
insertRawText("\n")— Lexical reconciles the DOM and sets the browser selection at the new cursor position, which triggers the browser's native scroll-into-view behavior on the caret.Command handler always returned
true— The handler unconditionally claimed to handle the Enter key even when the cursor was NOT in a markdown CodeNode, preventing Lexical's default rich-text Enter behavior from running in non-markdown mode.Merge-back update listener — A
registerUpdateListenerthat merges trailing nodes back into the CodeNode runs a secondeditor.update()cycle, causing an additional scroll jump after the first restore.Fix
editor.getEditorState().read()) to determine if we're in a markdown CodeNode before entering the updatefalseearly when not in markdown mode, so Lexical's default Enter handling works normally{discrete: true}, then restore viarequestAnimationFrameregisterUpdateListenerFiles Changed
web/packages/agenta-ui/src/Editor/plugins/markdown/markdownPlugin.tsxweb/oss/src/components/Editor/plugins/markdown/markdownPlugin.tsx