From 29c913b5d071149d7f0eb2f98ba2087136998c6e Mon Sep 17 00:00:00 2001
From: raghucssit
Date: Thu, 11 Sep 2025 11:41:59 +0200
Subject: [PATCH] Spin event loop to process pending UI updates before checking
the pasted content on the Text.
As content copy/paste works well manually junit fails because junit
checks the text content well before it is updated by GTK. So it is a
timing delay. Processing all the pending events make sure text is
updated(Either by introducing some delay in junit or really processing
any pending UI updates).
see https://github.com/eclipse-platform/eclipse.platform.swt/issues/2491
---
.../Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java | 6 ------
.../Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java | 8 ++++++--
.../tests/junit/Test_org_eclipse_swt_widgets_Text.java | 8 ++++++++
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
index c36471d39a5..b75a838fd32 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
@@ -494,12 +494,6 @@ Point computeNativeSize (long h, int wHint, int hHint, boolean changed) {
*
* The current selection is copied to the clipboard.
*
- *
- * Note: Copy data to the Clipboard may be asynchronous. This
- * means that the new clipboard content may not be immediately available right
- * after calling this method. To ensure the update is visible, use
- * {@link Display#asyncExec(Runnable)} before accessing the clipboard data.
- *
* @exception SWTException
- *
+ *
+ * Note: Pasting data to controls may occurs asynchronously. The widget
+ * text may not reflect the updated value immediately after calling this method.
+ * The new text will appear once pending events are processed in the event loop.
+ * Use {@link Display#asyncExec(Runnable)} before accessing getText()
.
+ *
* @exception SWTException
* - ERROR_WIDGET_DISPOSED - if the receiver has been disposed
* - ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java
index 0800292f628..e17b33e3ebf 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java
@@ -288,6 +288,11 @@ public void test_copy() {
text.setText("");
text.paste();
+ // Spin the event loop to let GTK process the clipboard + entry update
+ Display display = text.getDisplay();
+ while (display.readAndDispatch()) {
+ // loop until no more events
+ }
assertEquals("00000", text.getText());
// tests a SINGLE line text editor
@@ -307,6 +312,9 @@ public void test_copy() {
text.setText("");
text.paste();
+ while (display.readAndDispatch()) {
+ // loop until no more events
+ }
assertEquals("00000", text.getText());
}