提交 c5ab3210 编写于 作者: J Johannes Rieken
上级 444f79cc
......@@ -152,43 +152,51 @@ export class SuggestWidget implements IDisposable {
this._contentWidget = new SuggestContentWidget(this, editor);
this._persistedSize = new PersistedWidgetSize(_storageService, editor);
let persistedSize: dom.Dimension | undefined;
let currentSize: dom.Dimension | undefined;
let persistHeight = false;
let persistWidth = false;
class ResizeState {
constructor(
readonly persistedSize: dom.Dimension | undefined,
readonly currentSize: dom.Dimension,
public persistHeight = false,
public persistWidth = false,
) { }
}
let state: ResizeState | undefined;
this._disposables.add(this.element.onDidWillResize(() => {
this._contentWidget.lockPreference();
persistedSize = this._persistedSize.restore();
currentSize = this.element.size;
state = new ResizeState(this._persistedSize.restore(), this.element.size);
}));
this._disposables.add(this.element.onDidResize(e => {
this._resize(e.dimension.width, e.dimension.height);
persistHeight = persistHeight || !!e.north || !!e.south;
persistWidth = persistWidth || !!e.east || !!e.west;
if (e.done) {
if (state) {
state.persistHeight = state.persistHeight || !!e.north || !!e.south;
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 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;
if (persistedSize && currentSize) {
if (!persistHeight || Math.abs(currentSize.height - height) <= threshold) {
height = persistedSize.height;
}
if (!persistWidth || Math.abs(currentSize.width - width) <= threshold) {
width = persistedSize.width;
}
if (!state.persistHeight || Math.abs(state.currentSize.height - height) <= threshold) {
height = state.persistedSize?.height ?? defaultSize.height;
}
if (!state.persistWidth || Math.abs(state.currentSize.width - width) <= threshold) {
width = state.persistedSize?.width ?? defaultSize.width;
}
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'));
......@@ -738,7 +746,7 @@ export class SuggestWidget implements IDisposable {
if (this._state === State.Empty || this._state === State.Loading) {
// showing a message only
height = info.itemHeight + info.borderHeight;
width = 230;
width = info.defaultSize.width / 2;
this.element.enableSashes(false, false, false, false);
this.element.minSize = this.element.maxSize = new dom.Dimension(width, height);
this._contentWidget.setPreference(ContentWidgetPositionPreference.BELOW);
......@@ -749,7 +757,7 @@ export class SuggestWidget implements IDisposable {
// width math
const maxWidth = bodyBox.width - info.borderHeight - 2 * info.horizontalPadding;
if (width === undefined) {
width = 430;
width = info.defaultSize.width;
}
if (width > maxWidth) {
width = maxWidth;
......@@ -758,7 +766,7 @@ export class SuggestWidget implements IDisposable {
// height math
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 editorBox = dom.getDomNodePagePosition(this.editor.getDomNode());
const cursorBox = this.editor.getScrolledVisiblePosition(this.editor.getPosition());
......@@ -842,7 +850,8 @@ export class SuggestWidget implements IDisposable {
borderHeight,
typicalHalfwidthCharacterWidth: fontInfo.typicalHalfwidthCharacterWidth,
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.
先完成此消息的编辑!
想要评论请 注册