Ensure the last line is included in projection-based visible regions #3585
+74
−11
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.
As noticed in #3074 (comment) by @totomomo18, there are situations where the projection-based folding introduced in #3074 hides the last line where it should be shown. In that example, it was due to Windows line endings (
\r\n) where the last line was missing and it only moved past the\rbut not the\n(it didn't account for the second character).However, there is another situation where this can happen which is the case if there is additional (non-whitespace) text in the last line after the visible region. In the following example, assume that the visible region starts with
{and ends with}:Here, the
}would be hidden.An example where this could happen with JDT is enum constants (because of the
,after the constants):The problem with these situations is that projections/folding cannot hide partial lines at the end so it has to show the entire last line. When I implemented #3074, I was assuming that this was an issue with whitespace at the end but I didn't account for further text (it worked perfectly fine with comments and other things in JDT because comments at the end seem to be included in the visible regions set by JDT).
This change ensures that setting the visible region with projections enabled does not hide the last line in case there is additional text at the end of the line or the file is using Windows line endings by fixing the logic for computing the end of the visible region.