Skip to content
Open
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 @@ -471,6 +471,7 @@ private LineDrawInfo makeLineDrawInfo(int lineIndex) {
}

int drawLines(int startLine, int endLine, int begX, int begY, int endY, GC gc, Color widgetBackground, Color widgetForeground) {
final int[] selectionRanges = styledText.getSelectionRanges();
// When fixed line metrics is in effect, tall unicode characters
// will not always fit line's height. In this case, they will
// draw out of line's bounds. To prevent them from being clipped
Expand Down Expand Up @@ -503,7 +504,7 @@ int drawLines(int startLine, int endLine, int begX, int begY, int endY, GC gc, C
// Draw foreground
y = begY;
for (LineDrawInfo lineInfo : drawInfos) {
drawLineForeground(lineInfo, begX, y, gc, widgetForeground);
drawLineForeground(lineInfo, begX, y, gc, widgetForeground, selectionRanges);
y += lineInfo.height;
}

Expand All @@ -519,7 +520,7 @@ int drawLines(int startLine, int endLine, int begX, int begY, int endY, GC gc, C
for (int iLine = startLine; y < endY && iLine < endLine; iLine++) {
LineDrawInfo lineInfo = makeLineDrawInfo(iLine);
drawLineBackground(lineInfo, y, gc, widgetBackground);
drawLineForeground(lineInfo, begX, y, gc, widgetForeground);
drawLineForeground(lineInfo, begX, y, gc, widgetForeground, selectionRanges);
disposeTextLayout(lineInfo.layout);
y += lineInfo.height;
}
Expand All @@ -546,10 +547,10 @@ private void drawLineBackground(LineDrawInfo lineInfo, int paintY, GC gc, Color
}
}

private void drawLineForeground(LineDrawInfo lineInfo, int paintX, int paintY, GC gc, Color widgetForeground) {
private void drawLineForeground(LineDrawInfo lineInfo, int paintX, int paintY, GC gc, Color widgetForeground, int[] selectionRanges) {
int lineLength = lineInfo.text.length();
gc.setForeground(widgetForeground);
Point[] selection = intersectingRelativeNonEmptySelections(lineInfo.offset, lineInfo.offset + lineLength);
Point[] selection = intersectingRelativeNonEmptySelections(lineInfo.offset, lineInfo.offset + lineLength, selectionRanges);
if (styledText.getBlockSelection() || selection.length == 0) {
lineInfo.layout.draw(gc, paintX, paintY);
} else {
Expand Down Expand Up @@ -614,16 +615,15 @@ private void drawLineForeground(LineDrawInfo lineInfo, int paintX, int paintY, G
}
}

private Point[] intersectingRelativeNonEmptySelections(int fromOffset, int toOffset) {
int[] selectionRanges = styledText.getSelectionRanges();
private Point[] intersectingRelativeNonEmptySelections(int fromOffset, int toOffset, int[] selectionRanges) {
int lineLength = toOffset - fromOffset;
List<Point> res = new ArrayList<>();
for (int i = 0; i < selectionRanges.length; i += 2) {
// ranges are assumed to be sorted by start offset, then (positive)length or higher end offset
Point relativeSelection = new Point(selectionRanges[i] - fromOffset, selectionRanges[i] + selectionRanges[i + 1] - fromOffset);
if (relativeSelection.x != relativeSelection.y &&
relativeSelection.x <= lineLength && relativeSelection.y >= 0) {
res.add(relativeSelection);
// ranges are assumed to be sorted by start offset, then (positive) length or higher end offset
final int x = selectionRanges[i] - fromOffset;
final int y = selectionRanges[i] + selectionRanges[i + 1] - fromOffset;
if (x != y && x <= lineLength && y >= 0) {
res.add(new Point(x, y));
}
}
return res.toArray(new Point[res.size()]);
Expand Down
Loading