Repository navigation
Conversation
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)
There was a problem hiding this comment.
🟢 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
ProjectionViewerreplaces 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
Contributor
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.
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)