Skip to content

Keep cursor and page motion out of folded Org drawers - #340

Merged
eval-exec merged 3 commits into
eval-exec:mainfrom
ArthurHeymans:fix/org-fold-motion
Sep 4, 2026
Merged

eval-exec merged 3 commits into
eval-exec:mainfrom
ArthurHeymans:fix/org-fold-motion

Conversation

@ArthurHeymans

Copy link
Copy Markdown
Contributor

Collapsed Org drawers could still affect display motion as if their hidden source lines were visible. Cursor movement could enter a LOGBOOK, expose its contents, recenter the viewport inside the drawer, or make Page Up return to its previous position.

Treat both ordinary invisible runs and ellipsis-bearing runs as hidden during vertical motion. The viewport preflight now also measures point visibility across folded runs before deciding to recenter, so a large hidden LOGBOOK counts as an ellipsis instead of hundreds of visible lines.

@eval-exec
eval-exec self-requested a review September 3, 2026 06:24
@eval-exec

eval-exec commented Sep 4, 2026 •

Copy link
Copy Markdown
Owner

I pushed the ideal follow-up in d97107e and rebased the complete PR onto current main.\n\nThe root problem was broader than Org folding: source-newline counts are not valid display-row measurements across invisibility, selective display, or replacing display properties. The original preflight workaround also did not protect the post-layout retry, which could still move window-start into an unmeasured fold.\n\nThe follow-up now:\n\n- uses a typed SourceLineEstimate versus DisplayRowsRequired contract in both pre-layout selection and post-layout retry;\n- advances through canonical measured display rows whenever source can collapse;\n- centralizes visible, hidden, and hidden-with-ellipsis classification for Lisp, motion, and layout;\n- preserves the GNU Emacs distinction between window display motion and nil-window column scans;\n- retains the newer main-branch invisibility-origin model for GNU boundary overlay strings;\n- scopes collapse detection to effective properties in the relevant range, so harmless overlays do not exhaust the visibility retry limit;\n- adds regressions for large folds, replacing display spans, ellipsis-bearing column semantics, and distant motion with a face-only overlay.\n\nGNU reference for the window-sensitive invisible-source behavior: https://github.com/emacs-mirror/emacs/blob/master/src/indent.c\n\nAfter resolving the rebase conflicts, I verified 8 focused layout tests, 15 focused neovm-core motion tests, cargo check for neovm-core and neomacs-layout-engine, cargo fmt --all -- --check, and git diff --check. The pre-push workspace check also passed.

ArthurHeymans and others added 3 commits September 4, 2026 00:58
Measure point visibility across invisible runs before recentering a window.
This prevents large folded Org drawers from being counted as visible logical
rows, which could move the window start into LOGBOOK contents and make cursor
and page motion bounce.
Org folds and other display properties can collapse many source lines into one rendered row. The PR's preflight workaround approximated glyph widths and protected only the initial viewport decision; the post-layout visibility retry could still count hidden newlines, move window-start into an unmeasured fold, and accept an invalid viewport.

Introduce ForwardScrollMeasurement as the typed contract shared by source preflight and visibility retry. Source-line estimates remain available for monotonic text, while effective invisibility, selective display, and replacing display properties require progress through rows produced by the canonical display walk. Make the collapse scan range- and semantics-aware so an unrelated face overlay does not degrade a distant jump into more than the retry limit of screen-sized layouts.

Centralize GNU's visible/hidden/hidden-with-ellipsis result in the Invisibility enum and reuse it from Lisp, editor motion, and layout. Preserve GNU skip_invisible semantics explicitly with InvisibleRunContext: display motion elides both hidden forms, whereas current-column and move-to-column count source text for ellipsis-bearing invisibility when no window is supplied.

Add regressions for preflight over folded and replacing spans, post-layout retries across a large fold, distant motion with a harmless overlay, and the GNU-compatible column/motion distinction. These tests failed before the corresponding fixes and now exercise the public layout and Lisp seams.
@eval-exec
eval-exec merged commit 7c0d483 into eval-exec:main Sep 4, 2026
20 of 24 checks passed
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.

2 participants