Skip to content

Commit

Permalink
[fix] #27649 pin intellisense documentation widget to top (#62115)
Browse files Browse the repository at this point in the history
Fixes: #27649

Long docs when cursor is near the bottom will jump to the top to allow for more space, but if the next suggestion docs are smaller it will jump back down creating a jarring experience when flipping through suggestions quickly. Pin the widget to the top if it flips to the top once so that the experience is more fluid.

This is just one way we might handle it. Open to suggestions as this is my first PR to VSCode.
  • Loading branch information
riltsken authored and ramya-rao-a committed Dec 3, 2018
1 parent 5303738 commit 9e62a05
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/vs/editor/contrib/suggest/suggestWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<IComp

private firstFocusInCurrentList: boolean = false;

private preferDocPositionTop: boolean = false;
private docsPositionPreviousWidgetY: number;

constructor(
private editor: ICodeEditor,
@ITelemetryService private telemetryService: ITelemetryService,
Expand Down Expand Up @@ -706,6 +709,9 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<IComp
}

showSuggestions(completionModel: CompletionModel, selectionIndex: number, isFrozen: boolean, isAuto: boolean): void {
this.preferDocPositionTop = false;
this.docsPositionPreviousWidgetY = null;

if (this.loadingTimeout) {
clearTimeout(this.loadingTimeout);
this.loadingTimeout = null;
Expand Down Expand Up @@ -984,9 +990,14 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<IComp
return null;
}

let preference = [ContentWidgetPositionPreference.BELOW, ContentWidgetPositionPreference.ABOVE];
if (this.preferDocPositionTop) {
preference = [ContentWidgetPositionPreference.ABOVE];
}

return {
position: this.editor.getPosition(),
preference: [ContentWidgetPositionPreference.BELOW, ContentWidgetPositionPreference.ABOVE]
preference: preference
};
}

Expand Down Expand Up @@ -1027,6 +1038,17 @@ export class SuggestWidget implements IContentWidget, IListVirtualDelegate<IComp
const widgetX = widgetCoords.left;
const widgetY = widgetCoords.top;

// Fixes #27649
// Check if the Y changed to the top of the cursor and keep the widget flagged to prefer top
if (this.docsPositionPreviousWidgetY &&
this.docsPositionPreviousWidgetY < widgetY &&
!this.preferDocPositionTop) {
this.preferDocPositionTop = true;
this.adjustDocsPosition();
return;
}
this.docsPositionPreviousWidgetY = widgetY;

if (widgetX < cursorX - this.listWidth) {
// Widget is too far to the left of cursor, swap list and docs
addClass(this.element, 'list-right');
Expand Down

0 comments on commit 9e62a05

Please sign in to comment.