Skip to content

Keep the horizontal scroll position when the text viewer redraws again - #4564

Open
gerdleon wants to merge 1 commit into
eclipse-platform:masterfrom
gerdleon:keep-horizontal-scroll-on-redraw
Open

gerdleon wants to merge 1 commit into
eclipse-platform:masterfrom
gerdleon:keep-horizontal-scroll-on-redraw

Conversation

@gerdleon

Copy link
Copy Markdown

Re-enabling the redraw of a TextViewer resumes the forwarding of the
document changes, which resets the content of the StyledText and
scrolls it back to the start of the lines. The top index, selection and
caret are restored afterwards, but the horizontal scroll position is
lost. The same happens when a ProjectionViewer replaces its visible
document.

So while typing at the end of a long line, the editor jumps back to the
start of the line whenever the redraw is toggled, for example when the
folding regions of a large file are updated or a rewrite session is
used, although the caret stays in place.

Remember the horizontal scroll position when the redraw is disabled and
restore it when the redraw is enabled again, unless a selection set in
the meantime has been revealed. Do the same when the ProjectionViewer
replaces its visible document.

Fixes #3856

Assisted-by: GitHub Copilot Claude (claude-opus-5.5)

Re-enabling the redraw of a TextViewer resumes the forwarding of the
document changes, which resets the content of the StyledText and
scrolls it back to the start of the lines. The top index, selection and
caret are restored afterwards, but the horizontal scroll position is
lost. The same happens when a ProjectionViewer replaces its visible
document.

So while typing at the end of a long line, the editor jumps back to the
start of the line whenever the redraw is toggled, for example when the
folding regions of a large file are updated or a rewrite session is
used, although the caret stays in place.

Remember the horizontal scroll position when the redraw is disabled and
restore it when the redraw is enabled again, unless a selection set in
the meantime has been revealed. Do the same when the ProjectionViewer
replaces its visible document.

Fixes eclipse-platform#3856

Assisted-by: GitHub Copilot Claude (claude-opus-5.5)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the horizontal-scroll preservation changes.

No open issues 🎉

What changed in this PR

Preserves horizontal scrolling in JFace text viewers when redraw resumes or a projection document is replaced, addressing the editor jumping reported in #3856.

Changes:

  • Saves and restores the horizontal scroll offset across redraw toggles, while allowing explicitly revealed selections to take precedence.
  • Preserves horizontal scrolling when ProjectionViewer replaces its visible document.
  • Adds regression tests for redraw toggles, selection reveals, projection reinitialization, and bulk folding-annotation updates.
File Description
tests/​org.eclipse.jface.text.tests/​src/​org/​eclipse/​jface/​text/​tests/​TextViewerTest.java Tests scroll preservation and selection reveal behavior across redraw toggles.
tests/​org.eclipse.jface.text.tests/​src/​org/​eclipse/​jface/​text/​tests/​ProjectionViewerTest.java Tests scroll preservation during projection and folding updates.
bundles/​org.eclipse.jface.text/​src/​org/​eclipse/​jface/​text/​TextViewer.java Saves and restores horizontal scrolling around redraw suspension.
bundles/​org.eclipse.jface.text/​projection/​org/​eclipse/​jface/​text/​source/​projection/​ProjectionViewer.java Restores horizontal scrolling after replacing the visible document.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

   867 files  ± 0     867 suites  ±0   1h 0m 15s ⏱️ + 7m 59s
 8 549 tests + 4   8 309 ✅ + 4  240 💤 ±0  0 ❌ ±0 
21 519 runs  +12  20 843 ✅ +12  676 💤 ±0  0 ❌ ±0 

Results for commit 747d2bb. ± Comparison against base commit 53ecbfe.

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.

Generic text editor jumping on every edit on scroll right

2 participants