Skip to content

Commit 88f4209

Browse files
Move the quick pick closer to what invoked it
1 parent d707be9 commit 88f4209

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

src/vs/platform/quickinput/browser/quickInputController.ts

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,9 @@ export class QuickInputController extends Disposable {
664664
const backKeybindingLabel = this.options.backKeybindingLabel();
665665
backButton.tooltip = backKeybindingLabel ? localize('quickInput.backWithKeybinding', "Back ({0})", backKeybindingLabel) : localize('quickInput.back', "Back");
666666

667+
ui.inputBox.setFocus();
667668
ui.container.style.display = '';
668669
this.updateLayout();
669-
ui.inputBox.setFocus();
670670
this.quickInputTypeContext.set(controller.type);
671671
}
672672

@@ -797,8 +797,64 @@ export class QuickInputController extends Disposable {
797797
style.width = width + 'px';
798798

799799
// 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+
}
802858

803859
this.ui.inputBox.layout();
804860
this.ui.list.layout(this.dimension && this.dimension.height * 0.4);

0 commit comments

Comments
 (0)