Fix regression in ProjectionViewer.setVisibleRegion for empty ranges#3670
Fix regression in ProjectionViewer.setVisibleRegion for empty ranges#3670vogella wants to merge 1 commit into
Conversation
Commit 59dbd43 introduced a regression where setVisibleRegion(0, 0) would expand to include the full line, causing SegmentedModeTest.testShowNothing to fail. This change ensures that empty ranges (length 0) are not expanded to the end of the line, restoring the previous behavior for this case while keeping the fix for partial lines (length > 0).
|
@danthe1st WDYT? |
I think it looks good as a bugfix in general but I think it would make sense to do more. if (length == 0 || isLineBreak(document.getChar(end - 1))) {
return end + 1;
}That could be tested as follows (the test in this example is parameterized to show that the result is the same both with and without projections): @ParameterizedTest
@CsvSource({ "true", "false" })
void testEndWithStartOfLine(boolean enableProjections) {
Shell shell= new Shell();
shell.setLayout(new FillLayout());
TestProjectionViewer viewer= new TestProjectionViewer(shell, null, null, false, SWT.NONE);
String documentContent= """
Hello
World
123
456
""";
Document document= new Document(documentContent);
viewer.setDocument(document, new AnnotationModel());
if (enableProjections) {
viewer.enableProjection();
}
viewer.setVisibleRegion(documentContent.indexOf("World"), documentContent.indexOf("123") - documentContent.indexOf("World"));
shell.setVisible(true);
try {
assertEquals("World\n", viewer.getVisibleDocument().get());
} finally {
shell.dispose();
}
}I also ran some relevant tests I know in other projects ( |
|
@danthe1st can you push a new PR for your suggestion (or update mine, not sure if that will work)? |
I can't update your PR but I created #3671 |
Commit 59dbd43 introduced a regression where setVisibleRegion(0, 0) would expand to include the full line, causing SegmentedModeTest.testShowNothing to fail. This change ensures that empty ranges (length 0) are not expanded to the end of the line, restoring the previous behavior for this case while keeping the fix for partial lines (length > 0).