Skip to content

Commit 508ad4a

Browse files
raghucssitiloveeclipse
authored andcommitted
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 #2491
1 parent e2fbdb5 commit 508ad4a

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,6 @@ Point computeNativeSize (long h, int wHint, int hHint, boolean changed) {
494494
* <p>
495495
* The current selection is copied to the clipboard.
496496
* </p>
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>
503497
* @exception SWTException <ul>
504498
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
505499
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,6 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
739739
* <p>
740740
* The current selection is copied to the clipboard.
741741
* </p>
742-
*
743742
* @exception SWTException <ul>
744743
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
745744
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
@@ -2105,7 +2104,12 @@ long paintWindow () {
21052104
* The selected text is deleted from the widget
21062105
* and new text inserted from the clipboard.
21072106
* </p>
2108-
*
2107+
* <p>
2108+
* <strong>Note:</strong> Pasting data to controls may occurs asynchronously. The widget
2109+
* text may not reflect the updated value immediately after calling this method.
2110+
* The new text will appear once pending events are processed in the event loop.
2111+
* Use {@link Display#asyncExec(Runnable)} before accessing <code>getText()</code>.
2112+
* </p>
21092113
* @exception SWTException <ul>
21102114
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
21112115
* <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_Text.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ public void test_copy() {
288288

289289
text.setText("");
290290
text.paste();
291+
// Spin the event loop to let GTK process the clipboard + entry update
292+
Display display = text.getDisplay();
293+
while (display.readAndDispatch()) {
294+
// loop until no more events
295+
}
291296
assertEquals("00000", text.getText());
292297

293298
// tests a SINGLE line text editor
@@ -307,6 +312,9 @@ public void test_copy() {
307312

308313
text.setText("");
309314
text.paste();
315+
while (display.readAndDispatch()) {
316+
// loop until no more events
317+
}
310318
assertEquals("00000", text.getText());
311319
}
312320

0 commit comments

Comments
 (0)