Skip to content

Commit d817936

Browse files
trancexpressiloveeclipse
authored andcommitted
Restore focus that is lost during Control.setParent()
When calling Control.setParent() during a perspective switch, focus is lost on GTK3. This change restores the focus to the last control that had it, after the reparenting operation. Fixes: #1915 Signed-off-by: Simeon Andreev <[email protected]>
1 parent 4184369 commit d817936

File tree

1 file changed

+6
-0
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5840,6 +5840,8 @@ public boolean setParent (Composite parent) {
58405840
if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
58415841
if (this.parent == parent) return true;
58425842
if (!isReparentable ()) return false;
5843+
// preserve focus when re-parenting
5844+
Control focusControlBeforeReparent = display.getFocusControl();
58435845
GTK.gtk_widget_realize (parent.handle);
58445846
long topHandle = topHandle ();
58455847
GtkAllocation allocation = new GtkAllocation ();
@@ -5888,6 +5890,10 @@ public boolean setParent (Composite parent) {
58885890
this.parent = parent;
58895891
setZOrder (null, false, true);
58905892
reskin (SWT.ALL);
5893+
// restore focus to the last Control that had it, if focus is now gone
5894+
if (focusControlBeforeReparent != null && !focusControlBeforeReparent.isDisposed() && display.getFocusControl() == null) {
5895+
focusControlBeforeReparent.setFocus();
5896+
}
58915897
return true;
58925898
}
58935899

0 commit comments

Comments
 (0)