Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ private void calculateAndSetStickyLinesCanvasBounds() {
StyledText textWidget= sourceViewer.getTextWidget();

int numberStickyLines= getNumberStickyLines();
int lineHeight= stickyLineText.getLineHeight() * numberStickyLines;
int lineHeight = 0;
for (int i = 0; i < numberStickyLines; i++) {
lineHeight += stickyLineText.getLineHeight(stickyLineText.getOffsetAtLine(i));
}
int spacingHeight= stickyLineText.getLineSpacing() * (numberStickyLines - 1);
int separatorHeight= bottomSeparator.getBounds().height;

Expand Down Expand Up @@ -450,7 +453,8 @@ private boolean areStickyLinesOutDated(StyledText textWidget) {
}

private void limitVisibleStickyLinesToTextWidgetHeight(StyledText textWidget) {
int lineHeight= textWidget.getLineHeight() + textWidget.getLineSpacing();
int topOffset = textWidget.getOffsetAtLine(textWidget.getTopIndex());
int lineHeight = textWidget.getLineHeight(topOffset) + textWidget.getLineSpacing();
int textWidgetHeight= textWidget.getBounds().height;

int visibleLinesInTextWidget= textWidgetHeight / lineHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -236,6 +237,33 @@ void testStyling() {
assertEquals(hoverColor, stickyLineText.getForeground());
}

@Test
void testCanvasBoundsHeightAdjustsForVariableLineHeights() {
sourceViewer.getTextWidget().setBounds(0, 0, 200, 200);

// Step 1: Set 2 plain-text sticky lines and record canvas height
List<IStickyLine> plainLines = List.of(new StickyLineStub("line 1", 0), new StickyLineStub("line 2", 1));
stickyScrollingControl.setStickyLines(plainLines);
Canvas stickyControlCanvas = getStickyControlCanvas(shell);
int heightWithPlainText = stickyControlCanvas.getBounds().height;

// Step 2: Replace second sticky line with line requiring space
Font largerFont = new Font(Display.getDefault(),
new FontData(shell.getFont().getFontData()[0].getName(), 40, SWT.NORMAL));
String bigText = "line 2 big"; //$NON-NLS-1$
StyleRange bigFontRange = new StyleRange(0, bigText.length(), null, null);
bigFontRange.font = largerFont;
List<IStickyLine> linesWithLargerFont = List.of(new StickyLineStub("line 1", 0),
new StickyLineStub(bigText, 1, new StyleRange[] { bigFontRange }));
stickyScrollingControl.setStickyLines(linesWithLargerFont);
int heightWithLargerFont = getStickyControlCanvas(shell).getBounds().height;

assertTrue(heightWithLargerFont > heightWithPlainText,
"Canvas height must increase when one sticky line has a larger font"); //$NON-NLS-1$

largerFont.dispose();
}

@Test
void testLayoutStickyLinesCanvasOnResize() {
sourceViewer.getTextWidget().setBounds(0, 0, 200, 200);
Expand Down
Loading