Bug 579225 - org.eclipse.swt.widget.Caret doesn't call OS.SetCaretPos if
primary caret of multiple carets has changed (win32)
- performs early returns in set...()-methods only when the called caret
is the currentCaret, and thus should be in sync with the OS-level
Change-Id: I408cdd368a7554924c6b48c04bbdb8146fb93b65
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/191799
Tested-by: Platform Bot <platform-bot@eclipse.org>
Tested-by: Mickael Istria <mistria@redhat.com>
Reviewed-by: Mickael Istria <mistria@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java
index bc0f470..5b5342b 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java
@@ -38,6 +38,9 @@
* @noextend This class is not intended to be subclassed by clients.
*/
public class Caret extends Widget {
+ /** The Caret last updated on the OS-level */
+ private static Caret currentCaret;
+
Canvas parent;
int x, y, width, height;
boolean moved, resized;
@@ -285,6 +288,7 @@
void move () {
moved = false;
+ setCurrentCaret(this);
if (!OS.SetCaretPos (x, y)) return;
resizeIME ();
}
@@ -332,6 +336,9 @@
@Override
void releaseWidget () {
super.releaseWidget ();
+ if (isCurrentCaret()) {
+ setCurrentCaret(null);
+ }
parent = null;
image = null;
font = null;
@@ -390,7 +397,7 @@
void setBoundsInPixels (int x, int y, int width, int height) {
boolean samePosition = this.x == x && this.y == y;
boolean sameExtent = this.width == width && this.height == height;
- if (samePosition && sameExtent) return;
+ if (samePosition && sameExtent && isCurrentCaret()) return;
this.x = x;
this.y = y;
this.width = width;
@@ -530,12 +537,20 @@
}
void setLocationInPixels (int x, int y) {
- if (this.x == x && this.y == y) return;
+ if (this.x == x && this.y == y && isCurrentCaret()) return;
this.x = x; this.y = y;
moved = true;
if (isVisible && hasFocus ()) move ();
}
+private boolean isCurrentCaret() {
+ return Caret.currentCaret == this;
+}
+
+private void setCurrentCaret(Caret caret) {
+ Caret.currentCaret = caret;
+}
+
/**
* Sets the receiver's location to the point specified by
* the argument which is relative to the receiver's
@@ -572,7 +587,7 @@
}
void setSizeInPixels (int width, int height) {
- if (this.width == width && this.height == height) return;
+ if (this.width == width && this.height == height && isCurrentCaret()) return;
this.width = width; this.height = height;
resized = true;
if (isVisible && hasFocus ()) resize ();