@@ -664,9 +664,9 @@ export class QuickInputController extends Disposable {
664
664
const backKeybindingLabel = this . options . backKeybindingLabel ( ) ;
665
665
backButton . tooltip = backKeybindingLabel ? localize ( 'quickInput.backWithKeybinding' , "Back ({0})" , backKeybindingLabel ) : localize ( 'quickInput.back' , "Back" ) ;
666
666
667
+ ui . inputBox . setFocus ( ) ;
667
668
ui . container . style . display = '' ;
668
669
this . updateLayout ( ) ;
669
- ui . inputBox . setFocus ( ) ;
670
670
this . quickInputTypeContext . set ( controller . type ) ;
671
671
}
672
672
@@ -797,8 +797,64 @@ export class QuickInputController extends Disposable {
797
797
style . width = width + 'px' ;
798
798
799
799
// Position
800
- style . top = `${ this . viewState ?. top ? Math . round ( this . dimension ! . height * this . viewState . top ) : this . titleBarOffset } px` ;
801
- style . left = `${ Math . round ( ( this . dimension ! . width * ( this . viewState ?. left ?? 0.5 /* center */ ) ) - ( width / 2 ) ) } px` ;
800
+ if ( this . previousFocusElement ?. offsetParent ) {
801
+ let rect = this . previousFocusElement . getBoundingClientRect ( ) ;
802
+ if ( ! rect . width ) {
803
+ rect = this . previousFocusElement . offsetParent . getBoundingClientRect ( ) ;
804
+ }
805
+
806
+ const containerRect = this . _container . getBoundingClientRect ( ) ;
807
+ const centerX = containerRect . width / 2 ;
808
+ const centerY = containerRect . height / 2 ;
809
+ const outer30Percent = containerRect . width * 0.3 ;
810
+
811
+ let top = rect . top ;
812
+ let left = rect . left ;
813
+
814
+ if ( rect . right <= outer30Percent || rect . left >= containerRect . width - outer30Percent ) {
815
+ if ( rect . left < centerX ) {
816
+ left = rect . right ; // Position to the right of the element
817
+ } else {
818
+ left = rect . left - width ; // Position to the left of the element
819
+ }
820
+
821
+ if ( rect . top < centerY ) {
822
+ top = rect . bottom ; // Position below the element
823
+ } else {
824
+ top = rect . top - this . ui . container . offsetHeight ; // Position above the element
825
+ }
826
+
827
+ // Ensure the quick input is within the container bounds and does not overlap on the X axis
828
+ top = Math . max ( 0 , Math . min ( top , containerRect . height - this . ui . container . offsetHeight ) ) ;
829
+ if ( left < rect . right && left + width > rect . left ) {
830
+ if ( rect . left < centerX ) {
831
+ left = rect . right ; // Position to the right of the element
832
+ } else {
833
+ left = rect . left - width ; // Position to the left of the element
834
+ }
835
+ }
836
+ left = Math . max ( 0 , Math . min ( left , containerRect . width - width ) ) ;
837
+
838
+ // Adjust left to ensure no overlap on the X axis
839
+ if ( left >= rect . left && left <= rect . right ) {
840
+ if ( rect . left < centerX ) {
841
+ left = rect . right ; // Position to the right of the element
842
+ } else {
843
+ left = rect . left - width ; // Position to the left of the element
844
+ }
845
+ }
846
+ } else {
847
+ // Default positioning logic if not in the outer 30% of the X axis
848
+ top = this . viewState ?. top ? Math . round ( this . dimension ! . height * this . viewState . top ) : this . titleBarOffset ! ;
849
+ left = Math . round ( ( this . dimension ! . width * ( this . viewState ?. left ?? 0.5 /* center */ ) ) - ( width / 2 ) ) ;
850
+ }
851
+
852
+ style . top = `${ top } px` ;
853
+ style . left = `${ left } px` ;
854
+ } else {
855
+ style . top = `${ this . viewState ?. top ? Math . round ( this . dimension ! . height * this . viewState . top ) : this . titleBarOffset } px` ;
856
+ style . left = `${ Math . round ( ( this . dimension ! . width * ( this . viewState ?. left ?? 0.5 /* center */ ) ) - ( width / 2 ) ) } px` ;
857
+ }
802
858
803
859
this . ui . inputBox . layout ( ) ;
804
860
this . ui . list . layout ( this . dimension && this . dimension . height * 0.4 ) ;
0 commit comments