Skip to content

Commit

Permalink
Merge pull request #109961 from microsoft/joh/fix/109906
Browse files Browse the repository at this point in the history
Fix 109906
  • Loading branch information
jrieken authored Nov 4, 2020
2 parents 271026e + 9a44531 commit fcac248
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
21 changes: 21 additions & 0 deletions src/vs/editor/contrib/suggest/suggestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ export class SuggestController implements IEditorContribution {
toggleSuggestionFocus(): void {
this.widget.value.toggleDetailsFocus();
}

resetWidgetSize(): void {
this.widget.value.resetPersistedSize();
}
}

export class TriggerSuggestAction extends EditorAction {
Expand Down Expand Up @@ -875,3 +879,20 @@ registerEditorCommand(new SuggestCommand({
primary: KeyMod.Shift | KeyCode.Tab
}
}));


registerEditorAction(class extends EditorAction {

constructor() {
super({
id: 'editor.action.resetSuggestSize',
label: nls.localize('suggest.reset.label', "Reset Suggest Widget Size"),
alias: 'Reset Suggest Widget Size',
precondition: undefined
});
}

run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
SuggestController.get(editor).resetWidgetSize();
}
});
22 changes: 17 additions & 5 deletions src/vs/editor/contrib/suggest/suggestWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class PersistedWidgetSize {
store(size: dom.Dimension) {
this._service.store(this._key, JSON.stringify(size), StorageScope.GLOBAL);
}

reset(): void {
this._service.remove(this._key, StorageScope.GLOBAL);
}
}

export class SuggestWidget implements IDisposable {
Expand Down Expand Up @@ -149,11 +153,13 @@ export class SuggestWidget implements IDisposable {
this._persistedSize = new PersistedWidgetSize(_storageService, editor);

let persistedSize: dom.Dimension | undefined;
let currentSize: dom.Dimension | undefined;
let persistHeight = false;
let persistWidth = false;
this._disposables.add(this.element.onDidWillResize(() => {
this._contentWidget.lockPreference();
persistedSize = this._persistedSize.restore();
currentSize = this.element.size;
}));
this._disposables.add(this.element.onDidResize(e => {

Expand All @@ -162,14 +168,15 @@ export class SuggestWidget implements IDisposable {
persistHeight = persistHeight || !!e.north || !!e.south;
persistWidth = persistWidth || !!e.east || !!e.west;
if (e.done) {

// only store width or height value that have changed
// only store width or height value that have changed and also
// only store changes that are above a certain threshold
const threshold = Math.floor(this.getLayoutInfo().itemHeight / 2);
let { width, height } = this.element.size;
if (persistedSize) {
if (!persistHeight) {
if (persistedSize && currentSize) {
if (!persistHeight || Math.abs(currentSize.height - height) <= threshold) {
height = persistedSize.height;
}
if (!persistWidth) {
if (!persistWidth || Math.abs(currentSize.width - width) <= threshold) {
width = persistedSize.width;
}
}
Expand All @@ -178,6 +185,7 @@ export class SuggestWidget implements IDisposable {
// reset working state
this._contentWidget.unlockPreference();
persistedSize = undefined;
currentSize = undefined;
persistHeight = false;
persistWidth = false;
}
Expand Down Expand Up @@ -683,6 +691,10 @@ export class SuggestWidget implements IDisposable {
}
}

resetPersistedSize(): void {
this._persistedSize.reset();
}

hideWidget(): void {
this.loadingTimeout.dispose();
this._setState(State.Hidden);
Expand Down

0 comments on commit fcac248

Please sign in to comment.