@@ -1078,6 +1078,8 @@ export class QuickInputController extends Disposable {
10781078 private onHideEmitter = new Emitter < void > ( ) ;
10791079 readonly onHide = this . onHideEmitter . event ;
10801080
1081+ private previousFocusElement ?: HTMLElement ;
1082+
10811083 constructor ( private options : IQuickInputOptions ) {
10821084 super ( ) ;
10831085 this . idPrefix = options . idPrefix ;
@@ -1194,7 +1196,11 @@ export class QuickInputController extends Disposable {
11941196
11951197 const focusTracker = dom . trackFocus ( container ) ;
11961198 this . _register ( focusTracker ) ;
1199+ this . _register ( dom . addDisposableListener ( container , dom . EventType . FOCUS , e => {
1200+ this . previousFocusElement = e . relatedTarget instanceof HTMLElement ? e . relatedTarget : undefined ;
1201+ } , true ) ) ;
11971202 this . _register ( focusTracker . onDidBlur ( ( ) => {
1203+ this . previousFocusElement = undefined ;
11981204 if ( ! this . getUI ( ) . ignoreFocusOut && ! this . options . ignoreFocusOut ( ) ) {
11991205 this . hide ( true ) ;
12001206 }
@@ -1544,7 +1550,12 @@ export class QuickInputController extends Disposable {
15441550 this . onHideEmitter . fire ( ) ;
15451551 this . getUI ( ) . container . style . display = 'none' ;
15461552 if ( ! focusLost ) {
1547- this . options . returnFocus ( ) ;
1553+ if ( this . previousFocusElement && this . previousFocusElement . offsetParent ) {
1554+ this . previousFocusElement . focus ( ) ;
1555+ this . previousFocusElement = undefined ;
1556+ } else {
1557+ this . options . returnFocus ( ) ;
1558+ }
15481559 }
15491560 controller . didHide ( ) ;
15501561 }
0 commit comments