Skip to content

Commit 5b4b502

Browse files
committed
Bug 575383 - [StyledText] A mouse action to add a caret
Change-Id: I209f2bead80135d513a25e3f5b7c898ad8b6f9aa Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/185731 Tested-by: Platform Bot <[email protected]> Reviewed-by: Mickael Istria <[email protected]>
1 parent 14f2205 commit 5b4b502

File tree

1 file changed

+34
-4
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom

1 file changed

+34
-4
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6327,9 +6327,16 @@ void handleMouseDown(Event event) {
63276327
return;
63286328
}
63296329
clickCount = event.count;
6330+
boolean addSelection = (event.stateMask & SWT.MOD3) != 0;
63306331
if (clickCount == 1) {
6331-
boolean select = (event.stateMask & SWT.MOD2) != 0;
6332-
doMouseLocationChange(event.x, event.y, select);
6332+
if (addSelection && !blockSelection) {
6333+
int offset = getOffsetAtPoint(event.x, event.y, null);
6334+
addSelection(offset, 0);
6335+
sendSelectionEvent();
6336+
} else {
6337+
boolean expandSelection = (event.stateMask & SWT.MOD2) != 0;
6338+
doMouseLocationChange(event.x, event.y, expandSelection);
6339+
}
63336340
} else {
63346341
if (doubleClickEnabled) {
63356342
boolean wordSelect = (clickCount & 1) == 0;
@@ -6349,7 +6356,14 @@ void handleMouseDown(Event event) {
63496356
}
63506357
int start = Math.max(min, getWordPrevious(offset, SWT.MOVEMENT_WORD_START));
63516358
int end = Math.min(max, getWordNext(start, SWT.MOVEMENT_WORD_END));
6352-
setSelection(new int[] {start, end - start }, false, true);
6359+
int[] regions = new int[2];
6360+
if (addSelection) {
6361+
int[] current = getSelectionRanges();
6362+
regions = Arrays.copyOf(current, current.length + 2);
6363+
}
6364+
regions[regions.length - 2] = start;
6365+
regions[regions.length - 1] = end - start;
6366+
setSelection(regions, false, true);
63536367
sendSelectionEvent();
63546368
} else {
63556369
if (blockSelection) {
@@ -6359,7 +6373,14 @@ void handleMouseDown(Event event) {
63596373
if (lineIndex + 1 < content.getLineCount()) {
63606374
lineEnd = content.getOffsetAtLine(lineIndex + 1);
63616375
}
6362-
setSelection(new int[] {lineOffset, lineEnd - lineOffset}, false, false);
6376+
int[] regions = new int[2];
6377+
if (addSelection) {
6378+
int[] current = getSelectionRanges();
6379+
regions = Arrays.copyOf(current, current.length + 2);
6380+
}
6381+
regions[regions.length - 2] = lineOffset;
6382+
regions[regions.length - 1] = lineEnd - lineOffset;
6383+
setSelection(regions, false, false);
63636384
sendSelectionEvent();
63646385
}
63656386
}
@@ -6368,6 +6389,15 @@ void handleMouseDown(Event event) {
63686389
}
63696390
}
63706391
}
6392+
6393+
void addSelection(int offset, int length) {
6394+
int[] ranges = getSelectionRanges();
6395+
ranges = Arrays.copyOf(ranges, ranges.length + 2);
6396+
ranges[ranges.length - 2] = offset;
6397+
ranges[ranges.length - 1] = length;
6398+
setSelection(ranges, true, true);
6399+
}
6400+
63716401
/**
63726402
* Updates the caret location and selection if mouse button 1 is pressed
63736403
* during the mouse move.

0 commit comments

Comments
 (0)