mirror of
https://github.com/Microsoft/vscode
synced 2024-09-18 01:58:27 +00:00
This commit is contained in:
parent
444f79cc3a
commit
c5ab321020
|
@ -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)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue