-
Notifications
You must be signed in to change notification settings - Fork 226
Move empty document range at EOF to start of removed range #3390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
abf1ac7
to
aeacce6
Compare
This should be now fixed on master, so I've rebased the branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a text insertion behavior in ProjectionDocument
when removing ranges at the end of file. When a region is removed/hidden and results in an empty range at EOF, the empty range is now positioned at the start of the removed range instead of at the end, ensuring text typed at that position appears in the correct location.
Key changes:
- Modified the fragment offset positioning logic when removing master document ranges
- Added condition to detect when removed range ends at EOF and reposition empty fragments accordingly
bundles/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java
Outdated
Show resolved
Hide resolved
14e6f5f
to
5712747
Compare
I also added additional tests for the behavior in this PR. |
fe231df
to
f4b89fe
Compare
@iloveeclipse ping as the PR is ready for re-review so the test stops failing btw |
Could you please check eclipse-xtext/xtext#3531 ? |
Given the amount of issues it caused, it may be better to revert #3074. |
4.38 M2 is planned for October 24. It would be nice to have a fix PR a day before that or a revert PR, if there will be no fix. See also comment from @cdietrich regarding the paerticular problem with Xtext: eclipse-xtext/xtext#3531 (comment) |
56c86aa
to
7e8ec0d
Compare
I have updated the code in an attempt to fix eclipse-xtext/xtext#3531. I changed The change to [ <text
text
> ] text In this case, it should still be possible to collapse the part in I have no idea whether the GH Actions test failures are related to my PR. CC @iloveeclipse |
Oh also it would probably be good if someone could verify whether this actually fixes eclipse-xtext/xtext#3531 |
document range at EOF to start of removed range Fixes eclipse-platform#3380 and eclipse-xtext/xtext#3531
7e8ec0d
to
a327306
Compare
Because this part of the codebase isn't frequently modified, I'll try to describe this in a way that is reasonable to understand without being too familiar with these parts.
Description of the change
ProjectionViewer
/ProjectionDocument
allows hiding ranges/regions within the document.When a region is removed/hidden, it keeps an empty range which is used when e.g. typing text at that position (if there is no visible region left, it should still be possible to type new text).
Currently, this range is put at the end of the removed range causing typed letters to be inserted at the end of the last removed range.
This PR changes this behavior to put the zero-length range at the beginning of the "removed" range if the entire range is "removed" (from being visible) and the removed range ends at the end of the file (so if you remove the last part of the file and the part before the removed range is removed already).
The
offsetInMaster != 0 && offsetInMaster + lengthInMaster == getMasterDocument().getLength()
part of the condition is my attempt of not changing any behavior that is not wanted/keeping impact as low as possible:Reasoning
With my previous change in #3074,
ProjectionViewer#setVisibleRegion
is based on projection regions if projections are enabled (to allow using these two features together). This caused a regression (#3380) which resulted in setting an empty "visible region" to cause entered text appear at the end (failingSegmentedModeTest#testSegmentation
).Other considerations
This doesn't fix the issue that (assuming projections are enabled for the editor) setting a visible region still allows editing text at the end of the file.
For example, if projections are enabled for the editor and
setVisibleRegion
is used to only show theX
class, it is possible to type after the end of theY
class by moving the cursor to the very end:The code responsible for that is in the
else
block but I wasn't (yet) able to make that work.If this change is considered too risky/invasive (by changing behavior for people relying on removing the end region - though I have no idea why someone would rely on that), I can understand still reverting #3074 instead of merging this PR.
Also note that I cannot run the tests locally (I think because of the JUnit 6 issue).
Fixes #3380