提交 c5ab3210 编写于 作者: J Johannes Rieken
上级 444f79cc
...@@ -152,43 +152,51 @@ export class SuggestWidget implements IDisposable { ...@@ -152,43 +152,51 @@ export class SuggestWidget implements IDisposable {
this._contentWidget = new SuggestContentWidget(this, editor); this._contentWidget = new SuggestContentWidget(this, editor);
this._persistedSize = new PersistedWidgetSize(_storageService, editor); this._persistedSize = new PersistedWidgetSize(_storageService, editor);
let persistedSize: dom.Dimension | undefined; class ResizeState {
let currentSize: dom.Dimension | undefined; constructor(
let persistHeight = false; readonly persistedSize: dom.Dimension | undefined,
let persistWidth = false; readonly currentSize: dom.Dimension,
public persistHeight = false,
public persistWidth = false,
) { }
}
let state: ResizeState | undefined;
this._disposables.add(this.element.onDidWillResize(() => { this._disposables.add(this.element.onDidWillResize(() => {
this._contentWidget.lockPreference(); this._contentWidget.lockPreference();
persistedSize = this._persistedSize.restore(); state = new ResizeState(this._persistedSize.restore(), this.element.size);
currentSize = this.element.size;
})); }));
this._disposables.add(this.element.onDidResize(e => { this._disposables.add(this.element.onDidResize(e => {
this._resize(e.dimension.width, e.dimension.height); this._resize(e.dimension.width, e.dimension.height);
persistHeight = persistHeight || !!e.north || !!e.south; if (state) {
persistWidth = persistWidth || !!e.east || !!e.west; state.persistHeight = state.persistHeight || !!e.north || !!e.south;
if (e.done) { state.persistWidth = state.persistWidth || !!e.east || !!e.west;
}
if (!e.done) {
return;
}
if (state) {
// only store width or height value that have changed and also // only store width or height value that have changed and also
// only store changes that are above a certain threshold // only store changes that are above a certain threshold
const threshold = Math.floor(this.getLayoutInfo().itemHeight / 2); const { itemHeight, defaultSize } = this.getLayoutInfo();
const threshold = Math.round(itemHeight / 2);
let { width, height } = this.element.size; let { width, height } = this.element.size;
if (persistedSize && currentSize) { if (!state.persistHeight || Math.abs(state.currentSize.height - height) <= threshold) {
if (!persistHeight || Math.abs(currentSize.height - height) <= threshold) { height = state.persistedSize?.height ?? defaultSize.height;
height = persistedSize.height; }
} if (!state.persistWidth || Math.abs(state.currentSize.width - width) <= threshold) {
if (!persistWidth || Math.abs(currentSize.width - width) <= threshold) { width = state.persistedSize?.width ?? defaultSize.width;
width = persistedSize.width;
}
} }
this._persistedSize.store(new dom.Dimension(width, height)); this._persistedSize.store(new dom.Dimension(width, height));
// reset working state
this._contentWidget.unlockPreference();
persistedSize = undefined;
currentSize = undefined;
persistHeight = false;
persistWidth = false;
} }
// reset working state
this._contentWidget.unlockPreference();
state = undefined;
})); }));
this._messageElement = dom.append(this.element.domNode, dom.$('.message')); this._messageElement = dom.append(this.element.domNode, dom.$('.message'));
...@@ -738,7 +746,7 @@ export class SuggestWidget implements IDisposable { ...@@ -738,7 +746,7 @@ export class SuggestWidget implements IDisposable {
if (this._state === State.Empty || this._state === State.Loading) { if (this._state === State.Empty || this._state === State.Loading) {
// showing a message only // showing a message only
height = info.itemHeight + info.borderHeight; height = info.itemHeight + info.borderHeight;
width = 230; width = info.defaultSize.width / 2;
this.element.enableSashes(false, false, false, false); this.element.enableSashes(false, false, false, false);
this.element.minSize = this.element.maxSize = new dom.Dimension(width, height); this.element.minSize = this.element.maxSize = new dom.Dimension(width, height);
this._contentWidget.setPreference(ContentWidgetPositionPreference.BELOW); this._contentWidget.setPreference(ContentWidgetPositionPreference.BELOW);
...@@ -749,7 +757,7 @@ export class SuggestWidget implements IDisposable { ...@@ -749,7 +757,7 @@ export class SuggestWidget implements IDisposable {
// width math // width math
const maxWidth = bodyBox.width - info.borderHeight - 2 * info.horizontalPadding; const maxWidth = bodyBox.width - info.borderHeight - 2 * info.horizontalPadding;
if (width === undefined) { if (width === undefined) {
width = 430; width = info.defaultSize.width;
} }
if (width > maxWidth) { if (width > maxWidth) {
width = maxWidth; width = maxWidth;
...@@ -758,7 +766,7 @@ export class SuggestWidget implements IDisposable { ...@@ -758,7 +766,7 @@ export class SuggestWidget implements IDisposable {
// height math // height math
const fullHeight = info.statusBarHeight + this._list.contentHeight + info.borderHeight; const fullHeight = info.statusBarHeight + this._list.contentHeight + info.borderHeight;
const preferredHeight = info.statusBarHeight + 12 * info.itemHeight + info.borderHeight; const preferredHeight = info.defaultSize.height;
const minHeight = info.itemHeight + info.statusBarHeight; const minHeight = info.itemHeight + info.statusBarHeight;
const editorBox = dom.getDomNodePagePosition(this.editor.getDomNode()); const editorBox = dom.getDomNodePagePosition(this.editor.getDomNode());
const cursorBox = this.editor.getScrolledVisiblePosition(this.editor.getPosition()); const cursorBox = this.editor.getScrolledVisiblePosition(this.editor.getPosition());
...@@ -842,7 +850,8 @@ export class SuggestWidget implements IDisposable { ...@@ -842,7 +850,8 @@ export class SuggestWidget implements IDisposable {
borderHeight, borderHeight,
typicalHalfwidthCharacterWidth: fontInfo.typicalHalfwidthCharacterWidth, typicalHalfwidthCharacterWidth: fontInfo.typicalHalfwidthCharacterWidth,
verticalPadding: 22, verticalPadding: 22,
horizontalPadding: 14 horizontalPadding: 14,
defaultSize: new dom.Dimension(430, statusBarHeight + 12 * itemHeight + borderHeight)
}; };
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册