Skip to content

Fix regression in ProjectionViewer.setVisibleRegion for empty ranges#3670

Closed
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:fix-3667
Closed

Fix regression in ProjectionViewer.setVisibleRegion for empty ranges#3670
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:fix-3667

Conversation

@vogella

@vogella vogella commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

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).

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).
@vogella

vogella commented Jan 13, 2026

Copy link
Copy Markdown
Contributor Author

@danthe1st WDYT?

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 3 015 files  ±0   3 015 suites  ±0   2h 15m 33s ⏱️ - 6m 47s
 8 266 tests ±0   8 018 ✅ +1  248 💤 ±0  0 ❌  - 1 
23 622 runs  ±0  22 831 ✅ +1  791 💤 ±0  0 ❌  - 1 

Results for commit 0009523. ± Comparison against base commit 3d42a70.

@danthe1st

danthe1st commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

@danthe1st WDYT?

I think it looks good as a bugfix in general but I think it would make sense to do more.
If the selected end is directly after the line break, I guess it doesn't really make sense to include the last line as well so I guess something like the following might make more sense:

		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 (org.eclipse.xtend.ide.tests.autoedit.AutoEditTest in xtext, FoldingTestSuite in JDT-UI, DocumentLinkReconcilingTest in lsp4e) and at least they don't seem to break either.

@vogella

vogella commented Jan 13, 2026

Copy link
Copy Markdown
Contributor Author

@danthe1st can you push a new PR for your suggestion (or update mine, not sure if that will work)?

@danthe1st

Copy link
Copy Markdown
Contributor

@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

@vogella vogella closed this Jan 13, 2026
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.

2 participants