Skip to content

Commit bdeb6a3

Browse files
committed
Spin the event loop to process the paste operation completely.
Manually when copy and paste done on combo it works as expected. But while calling copy and paste API on combo there is an inconsistency. It is due to pending UI events before we check text on combo. see #2485
1 parent fdbb769 commit bdeb6a3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ Point computeNativeSize (long h, int wHint, int hHint, boolean changed) {
494494
* <p>
495495
* The current selection is copied to the clipboard.
496496
* </p>
497+
* <strong>Note:</strong> On GTK4, clipboard updates may be asynchronous. This
498+
* means that the new clipboard content may not be immediately available right
499+
* after calling this method. To ensure the update is visible, spin the event
500+
* loop (e.g., using {@link Display#readAndDispatch()} or
501+
* {@link Display#asyncExec(Runnable)} before accessing the clipboard.
502+
* </p>
497503
*
498504
* @exception SWTException <ul>
499505
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
@@ -1955,6 +1961,13 @@ long paintSurface () {
19551961
* The selected text is deleted from the widget
19561962
* and new text inserted from the clipboard.
19571963
* </p>
1964+
* <p>
1965+
* <strong>Note:</strong> On GTK4, pasting occurs asynchronously. The widget
1966+
* text may not reflect the updated value immediately after calling this method.
1967+
* The new text will appear once pending events are processed in the event loop.
1968+
* If you need to assert the new value right after calling {@code paste()}, use
1969+
* {@link Display#readAndDispatch()} or {@link Display#asyncExec(Runnable)}.
1970+
* </p>
19581971
*
19591972
* @exception SWTException <ul>
19601973
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Combo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.eclipse.swt.graphics.Point;
3535
import org.eclipse.swt.graphics.Rectangle;
3636
import org.eclipse.swt.widgets.Combo;
37+
import org.eclipse.swt.widgets.Display;
3738
import org.junit.Before;
3839
import org.junit.Test;
3940

@@ -236,6 +237,11 @@ public void test_copy() {
236237
combo.copy();
237238
combo.setSelection(new Point(0,0));
238239
combo.paste();
240+
// Spin the event loop to let GTK process the clipboard + entry update
241+
Display display = combo.getDisplay();
242+
while (display.readAndDispatch()) {
243+
// loop until no more events
244+
}
239245
assertEquals("23123456", combo.getText());
240246
}
241247

@@ -501,6 +507,11 @@ public void test_paste() {
501507
combo.cut();
502508
assertEquals("1456", combo.getText());
503509
combo.paste();
510+
// Spin the event loop to let GTK process the clipboard + entry update
511+
Display display = combo.getDisplay();
512+
while (display.readAndDispatch()) {
513+
// loop until no more events
514+
}
504515
assertEquals("123456", combo.getText());
505516
}
506517

0 commit comments

Comments
 (0)