mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 01:25:39 -05:00
Merge from vscode 52dcb723a39ae75bee1bd56b3312d7fcdc87aeed (#6719)
This commit is contained in:
@@ -19,6 +19,9 @@ import { Color } from 'vs/base/common/color';
|
||||
import { mixin } from 'vs/base/common/objects';
|
||||
import { HistoryNavigator } from 'vs/base/common/history';
|
||||
import { IHistoryNavigationWidget } from 'vs/base/browser/history';
|
||||
import { ScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
|
||||
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
|
||||
import { domEvent } from 'vs/base/browser/event';
|
||||
|
||||
const $ = dom.$;
|
||||
|
||||
@@ -28,6 +31,7 @@ export interface IInputOptions extends IInputBoxStyles {
|
||||
readonly type?: string;
|
||||
readonly validationOptions?: IInputValidationOptions;
|
||||
readonly flexibleHeight?: boolean;
|
||||
readonly flexibleMaxHeight?: number;
|
||||
readonly actions?: ReadonlyArray<IAction>;
|
||||
|
||||
|
||||
@@ -93,7 +97,6 @@ export class InputBox extends Widget {
|
||||
private contextViewProvider?: IContextViewProvider;
|
||||
element: HTMLElement;
|
||||
private input: HTMLInputElement;
|
||||
private mirror: HTMLElement;
|
||||
private actionbar?: ActionBar;
|
||||
private options: IInputOptions;
|
||||
private message: IMessage | null;
|
||||
@@ -101,7 +104,12 @@ export class InputBox extends Widget {
|
||||
private ariaLabel: string;
|
||||
private validation?: IInputValidator;
|
||||
private state: 'idle' | 'open' | 'closed' = 'idle';
|
||||
private cachedHeight: number | null;
|
||||
|
||||
private mirror: HTMLElement | undefined;
|
||||
private cachedHeight: number | undefined;
|
||||
private cachedContentHeight: number | undefined;
|
||||
private maxHeight: number = Number.POSITIVE_INFINITY;
|
||||
private scrollableElement: ScrollableElement | undefined;
|
||||
|
||||
// {{SQL CARBON EDIT}} - Add showValidationMessage and set inputBackground, inputForeground, and inputBorder as protected
|
||||
protected showValidationMessage: boolean;
|
||||
@@ -133,7 +141,6 @@ export class InputBox extends Widget {
|
||||
this.options = options || Object.create(null);
|
||||
mixin(this.options, defaultOpts, false);
|
||||
this.message = null;
|
||||
this.cachedHeight = null;
|
||||
this.placeholder = this.options.placeholder || '';
|
||||
this.ariaLabel = this.options.ariaLabel || '';
|
||||
|
||||
@@ -171,8 +178,26 @@ export class InputBox extends Widget {
|
||||
this.onblur(this.input, () => dom.removeClass(this.element, 'synthetic-focus'));
|
||||
|
||||
if (this.options.flexibleHeight) {
|
||||
this.maxHeight = typeof this.options.flexibleMaxHeight === 'number' ? this.options.flexibleMaxHeight : Number.POSITIVE_INFINITY;
|
||||
|
||||
this.mirror = dom.append(wrapper, $('div.mirror'));
|
||||
this.mirror.innerHTML = ' ';
|
||||
|
||||
this.scrollableElement = new ScrollableElement(this.element, { vertical: ScrollbarVisibility.Auto });
|
||||
dom.append(container, this.scrollableElement.getDomNode());
|
||||
this._register(this.scrollableElement);
|
||||
|
||||
// from ScrollableElement to DOM
|
||||
this._register(this.scrollableElement.onScroll(e => this.input.scrollTop = e.scrollTop));
|
||||
|
||||
const onSelectionChange = Event.filter(domEvent(document, 'selectionchange'), () => {
|
||||
const selection = document.getSelection();
|
||||
return !!selection && selection.anchorNode === wrapper;
|
||||
});
|
||||
|
||||
// from DOM to ScrollableElement
|
||||
this._register(onSelectionChange(this.updateScrollDimensions, this));
|
||||
this._register(this.onDidHeightChange(this.updateScrollDimensions, this));
|
||||
} else {
|
||||
this.input.type = this.options.type || 'text';
|
||||
this.input.setAttribute('wrap', 'off');
|
||||
@@ -254,7 +279,7 @@ export class InputBox extends Widget {
|
||||
}
|
||||
}
|
||||
|
||||
public get mirrorElement(): HTMLElement {
|
||||
public get mirrorElement(): HTMLElement | undefined {
|
||||
return this.mirror;
|
||||
}
|
||||
|
||||
@@ -274,7 +299,7 @@ export class InputBox extends Widget {
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
return this.cachedHeight === null ? dom.getTotalHeight(this.element) : this.cachedHeight;
|
||||
return typeof this.cachedHeight === 'number' ? this.cachedHeight : dom.getTotalHeight(this.element);
|
||||
}
|
||||
|
||||
public focus(): void {
|
||||
@@ -325,6 +350,19 @@ export class InputBox extends Widget {
|
||||
}
|
||||
}
|
||||
|
||||
private updateScrollDimensions(): void {
|
||||
if (typeof this.cachedContentHeight !== 'number' || typeof this.cachedHeight !== 'number') {
|
||||
return;
|
||||
}
|
||||
|
||||
const scrollHeight = this.cachedContentHeight;
|
||||
const height = this.cachedHeight;
|
||||
const scrollTop = this.input.scrollTop;
|
||||
|
||||
this.scrollableElement!.setScrollDimensions({ scrollHeight, height });
|
||||
this.scrollableElement!.setScrollPosition({ scrollTop });
|
||||
}
|
||||
|
||||
public showMessage(message: IMessage, force?: boolean): void {
|
||||
this.message = message;
|
||||
|
||||
@@ -544,12 +582,13 @@ export class InputBox extends Widget {
|
||||
return;
|
||||
}
|
||||
|
||||
const previousHeight = this.cachedHeight;
|
||||
this.cachedHeight = dom.getTotalHeight(this.mirror);
|
||||
const previousHeight = this.cachedContentHeight;
|
||||
this.cachedContentHeight = dom.getTotalHeight(this.mirror);
|
||||
|
||||
if (previousHeight !== this.cachedHeight) {
|
||||
if (previousHeight !== this.cachedContentHeight) {
|
||||
this.cachedHeight = Math.min(this.cachedContentHeight, this.maxHeight);
|
||||
this.input.style.height = this.cachedHeight + 'px';
|
||||
this._onDidHeightChange.fire(this.cachedHeight);
|
||||
this._onDidHeightChange.fire(this.cachedContentHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user