Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2021-09-13 13:50:27 +0000
committerMickael Istria2021-09-14 15:09:22 +0000
commite57e5530453240142e96f9755a4f5b66e3a07a9e (patch)
treef71ed042e84521bb3f7452ad40d7d0ccb232dc7c /org.eclipse.jface.text/src
parente0c27e6ed1c36e22b5d75c0ab470ace2d1a6125f (diff)
downloadeclipse.platform.text-e57e5530453240142e96f9755a4f5b66e3a07a9e.tar.gz
eclipse.platform.text-e57e5530453240142e96f9755a4f5b66e3a07a9e.tar.xz
eclipse.platform.text-e57e5530453240142e96f9755a4f5b66e3a07a9e.zip
Bug 575520 - Fix CodeFormatterTest tests
Change-Id: I259ed992d4754a7eb72fe9216270ad1d214cd27d Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/185400 Tested-by: Platform Bot <platform-bot@eclipse.org> Reviewed-by: Mickael Istria <mistria@redhat.com>
Diffstat (limited to 'org.eclipse.jface.text/src')
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
index 58768f9dff1..7938bc5888e 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
@@ -1120,8 +1120,12 @@ public class TextViewer extends Viewer implements
*/
public void updateSelection(Position[] selections) {
fSelectionSet= true;
- if (fSelections == null) {
- fSelections= Arrays.copyOf(selections, selections.length);
+ if (selections == null) {
+ fSelections = new Position[0];
+ } else if (fSelections != null && fSelections.length == selections.length) {
+ for (int i = 0; i < fSelections.length; i++) {
+ updatePosition(fSelections[i], selections[i].getOffset(), selections[i].getLength());
+ }
} else {
fSelections= Arrays.stream(selections)
.map(position -> new Position(position.getOffset(), position.getLength())) /*force deleted=false*/
@@ -1252,6 +1256,20 @@ public class TextViewer extends Viewer implements
}
/**
+ * Updates a position with the given information and clears its deletion state.
+ *
+ * @param position the position to update
+ * @param offset the new selection offset
+ * @param length the new selection length
+ */
+ private void updatePosition(Position position, int offset, int length) {
+ position.setOffset(offset);
+ position.setLength(length);
+ // http://bugs.eclipse.org/bugs/show_bug.cgi?id=32795
+ position.isDeleted= false;
+ }
+
+ /**
* Returns the document line to keep visually stable. If the caret line is (partially)
* visible, it is returned, otherwise the topmost (partially) visible line is returned.
*
@@ -2496,6 +2514,9 @@ public class TextViewer extends Viewer implements
}
}
+ if (!redraws() && fViewerState != null) {
+ return toSelection(Arrays.stream(fViewerState.getSelection()).map(point -> new Region(point.x, point.y)).toArray(IRegion[]::new));
+ }
int[] ranges= fTextWidget.getSelectionRanges();
IRegion[] selectedRanges= new IRegion[ranges.length / 2];
for (int i= 0; i < selectedRanges.length; i++) {

Back to the top