fix: scroll to document start/end on Ctrl+Home/End in Rendered view#137
Conversation
Rendered view renders each block (paragraph, heading, list item, etc.) as an inline TextEdit. With focus inside one of those widgets, Ctrl+Home / Ctrl+End were consumed by the TextEdit and moved the cursor to the start or end of that single block instead of the document. Intercept these keys at the ScrollArea level — before inner TextEdits see them — and apply vertical_scroll_offset: - Ctrl+Home: 0.0 - Ctrl+End: cached total_height from the prior frame's ViewportCullingState (falls back to a large finite value on the first frame; f32::INFINITY breaks egui's scrollbar arithmetic and was avoided) The event is then removed from the input queue so the focused TextEdit does not also react.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe editor in rendered mode now supports document navigation shortcuts: Ctrl+Home jumps to the document start and Ctrl+End jumps to the document end. The implementation detects these key presses, computes appropriate scroll offsets (using cached viewport dimensions for accurate end-of-document positioning), and prevents the key events from being consumed by inline editors so navigation is not trapped within focused text blocks. ChangesDocument Edge Navigation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Thanks for this PR! Currently working on Egui upgrade, its going well, so 0.3.0 will be expected this weekend. |
Add CHANGELOG entry and README contributor line for rendered-view document navigation (PR #137). Co-authored-by: Cursor <cursoragent@cursor.com>
Description
In Rendered view, each markdown block (paragraph, heading, list item, etc.) is rendered as an inline
TextEdit. When focus is inside one of those widgets, Ctrl+Home and Ctrl+End are consumed by the innerTextEditand move the cursor to the start/end of that single block — not to the start/end of the document, as users expect.This PR intercepts those keys at the
ScrollArealevel — before the innerTextEdits see them — and applies the appropriatevertical_scroll_offset.Raw view was already correct (handled in
src/editor/ferrite/input/keyboard.rs), so this only touches the Rendered/Split path.Type of Change
Changes Made
Ctrl+Home/Ctrl+EndinMarkdownEditor::show_rendered_editor(insrc/markdown/editor.rs) before theScrollAreais built.Ctrl+Home: setvertical_scroll_offset(0.0).Ctrl+End: read the cachedtotal_heightfrom the prior frame'sViewportCullingState(falls back to a large finite value on the first frame).f32::INFINITYwas tried first but broke egui's scrollbar arithmetic — content area collapsed and the scrollbar disappeared — so a finite value (clamped by egui) is used instead.Key::Home/Key::Endevents from the input queue so the focusedTextEditdoesn't also navigate within its block.Checklist
cargo fmtand it produces no changes to the lines this PR touches (pre-existing trailing-whitespace findings elsewhere in the tree are not addressed here to keep the diff focused).cargo clippy— no new warnings from this change (the existing 471 pre-existing warnings in the tree are unchanged).cargo testand all tests pass (1477 passed, 0 failed, 2 ignored).cargo build --releasesuccessfully.ScrollAreainteraction that's hard to assert without a UI harness; verified manually as described below).Testing
Verified manually on Windows 10 with a
cargo build --releasebuild:EditorMode::Renderedpath) → works. ✓src/editor/ferrite/input/keyboard.rs). ✓Additional Notes
Ctrl+Endis pressed on the very first frame after opening a file (beforeViewportCullingStatehas measured any blocks), the scroll uses the1.0e9fallback. egui clamps this to the actual max scroll position, but if the culling state hasn't measured everything yet, the bottom may be approximate; a second press lands precisely. In practice this is hard to hit — by the time a user can press a shortcut, at least one render frame has measured the culling state. Happy to add arequest_repaint+ second-frame application if reviewers prefer a stricter guarantee.ShortcutCommandso it would be user-configurable from the settings UI, but that adds more surface area for what is essentially a fix to match expected behavior. Open to that direction if the maintainer prefers.Summary by CodeRabbit