Skip to content

Commit f858239

Browse files
raghucssitiloveeclipse
authored andcommitted
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 f858239

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +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-
*
497+
* <p>
498+
* <strong>Note:</strong> Copy data to the Clipboard may be asynchronous. This
499+
* means that the new clipboard content may not be immediately available right
500+
* after calling this method. To ensure the update is visible, use
501+
* {@link Display#asyncExec(Runnable)} before accessing the clipboard data.
502+
* </p>
498503
* @exception SWTException <ul>
499504
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
500505
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -1955,7 +1960,12 @@ long paintSurface () {
19551960
* The selected text is deleted from the widget
19561961
* and new text inserted from the clipboard.
19571962
* </p>
1958-
*
1963+
* <p>
1964+
* <strong>Note:</strong> Pasting data to controls may occurs asynchronously. The widget
1965+
* text may not reflect the updated value immediately after calling this method.
1966+
* The new text will appear once pending events are processed in the event loop.
1967+
* Use {@link Display#asyncExec(Runnable)} before accessing <code>getText()</code>.
1968+
* </p>
19591969
* @exception SWTException <ul>
19601970
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
19611971
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</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)