Skip to content
Merged
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 @@ -144,7 +144,9 @@ public void dispose() {
public Point draw(GC gc, StyledText textWidget, Color color, int x, int y) {
String title= getLabel() != null ? getLabel() : "no command"; //$NON-NLS-1$
gc.drawString(title, x, y, true);
return gc.stringExtent(title);
Point result= gc.stringExtent(title);
result.y+= textWidget.getLineSpacing();
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static Point draw(String label, GC gc, StyledText textWidget, int x, int y, Call
gc.drawString(line, x, y, true);
Point ext= gc.stringExtent(line);
result.x= Math.max(result.x, ext.x);
result.y+= ext.y;
result.y+= ext.y + textWidget.getLineSpacing();
y+= ext.y + textWidget.getLineSpacing();
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.jface.text.tests.codemining;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import java.util.Arrays;
Expand All @@ -21,6 +22,8 @@

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
Expand Down Expand Up @@ -72,6 +75,37 @@ public void tearDown() {
fViewer= null;
}

@Test
public void testDrawTakesLineSpacingForSingleLineIntoAccount() throws Exception {
assertDrawTakesLineSpacingIntoAccount("line1\nline2\nline3", "code mining single line");
}

@Test
public void testDrawTakesLineSpacingForMultiLineIntoAccount() throws Exception {
assertDrawTakesLineSpacingIntoAccount("line1\nline2\nline3", "code mining line1\ncode mining line2");
}

private void assertDrawTakesLineSpacingIntoAccount(String source, String codeMiningLabel) throws Exception {
var doc= fViewer.getDocument();
doc.set(source);
var textWidget= fViewer.getTextWidget();
textWidget.setLineSpacing(10);
var mining= new LineHeaderCodeMining(0, doc, null, null) {
@Override
public String getLabel() {
return codeMiningLabel;
}
};
var gc= new GC(textWidget);
try {
Point result= mining.draw(gc, textWidget, null, 0, 0);
String[] codeMiningLabelsByLine= codeMiningLabel.split("\n");
assertEquals(codeMiningLabelsByLine.length * (gc.stringExtent(codeMiningLabelsByLine[0]).y + textWidget.getLineSpacing()), result.y);
} finally {
gc.dispose();
}
}

@Test
public void testGetHeightDoesNotReturnZero() throws Exception {
var cut= new CodeMiningLineHeaderAnnotation(new Position(0, 0), fViewer);
Expand Down
Loading