Debug cursor scroll into view behavior
Summary
Root cause: When new editors are created (EditorState::new() via open_file_in_new_tab and split_group), they get viewport.visible_lines = 25 (the hardcoded default). resize() is only called on WindowEvent::Resized — not when new editors are created. So new editors retain visible_lines = 25 until the window is next resized.
Why midpoint: On a typical window showing ~45 lines, the safe zone boundary is at line 23 (= 25 - 2). Clicking on line 24+ triggers scrolling. Line 24 is roughly the visual midpoint of a 45-line viewport.
Fix approach — two options:
Quick fix: Call
model.recalculate_viewports()(ormodel.resize(w, h)) after creating new editors innew_tab_in_focused_group,open_file_in_new_tab, andsplit_group.Robust fix: Call
editor_area.sync_all_viewports(line_height, char_width)aftercompute_layout_scaledin the render path, so viewport dimensions always stay in sync with actual group dimensions. This also fixes the secondary issue for split views where groups can be different sizes than whatresize()computes.
Bonus consideration: For mouse clicks specifically, you may want to skip ensure_cursor_visible entirely (or use a no-padding mode), since the clicked position is by definition already visible. VS Code and other editors don't apply scroll margins to mouse clicks — only to keyboard navigation.
Want me to implement the fix?
All clean. Here's a summary of the three fixes:
Changes Made
Fix 1: Mouse clicks don't apply scroll padding (src/update/editor.rs, src/model/editor.rs, src/model/editor_area.rs, src/model/mod.rs)
- Added
ensure_cursor_visible_no_padding()— only scrolls if cursor is completely outside the viewport, ignoringscroll_padding SetCursorPositionhandler now uses this method instead ofensure_cursor_visible()- Clicking on any visible line (including first/last) never scrolls
Fix 2: sync_all_viewports subtracts tab bar height (src/model/editor_area.rs, src/bin/screenshot.rs)
- Added
tab_bar_heightparameter tosync_all_viewports() - Now correctly passes it to
compute_visible_lines()so the text content area height is used, not the full group rect
Fix 3: New editors get correct viewport dimensions (src/update/layout.rs)
- Added
sync_viewports()helper called afterNewTab,OpenFileInNewTab,SplitFocused, andSplitGroup - New editors now inherit correct
visible_linesfrom their group rect instead of keeping the default 25
Tests added (7 new tests in tests/scrolling.rs)
- Click on visible line → no scroll
- Click on last/first visible line → no scroll (even with padding)
- Click off-screen above/below → scrolls correctly
sync_all_viewportscorrectly subtracts tab bar height- New editor tab gets correct viewport size
There are unrelated changes in the worktree. I'll only stage the files I modified:
Committed as 9f08daf on main.