UNPKG

sussudio

Version:

An unofficial VS Code Internal API

110 lines (109 loc) 4.53 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as dom from "../../../browser/dom.mjs"; import { StandardKeyboardEvent } from "../../../browser/keyboardEvent.mjs"; import { StandardMouseEvent } from "../../../browser/mouseEvent.mjs"; import { FindInput } from "../../../browser/ui/findinput/findInput.mjs"; import { Disposable } from "../../../common/lifecycle.mjs"; import Severity from "../../../common/severity.mjs"; import "../../../../css!./media/quickInput.mjs"; const $ = dom.$; export class QuickInputBox extends Disposable { parent; container; findInput; constructor(parent, inputBoxStyles, toggleStyles) { super(); this.parent = parent; this.container = dom.append(this.parent, $('.quick-input-box')); this.findInput = this._register(new FindInput(this.container, undefined, { label: '', inputBoxStyles, toggleStyles })); } onKeyDown = (handler) => { return dom.addDisposableListener(this.findInput.inputBox.inputElement, dom.EventType.KEY_DOWN, (e) => { handler(new StandardKeyboardEvent(e)); }); }; onMouseDown = (handler) => { return dom.addDisposableListener(this.findInput.inputBox.inputElement, dom.EventType.MOUSE_DOWN, (e) => { handler(new StandardMouseEvent(e)); }); }; onDidChange = (handler) => { return this.findInput.onDidChange(handler); }; get value() { return this.findInput.getValue(); } set value(value) { this.findInput.setValue(value); } select(range = null) { this.findInput.inputBox.select(range); } isSelectionAtEnd() { return this.findInput.inputBox.isSelectionAtEnd(); } setPlaceholder(placeholder) { this.findInput.inputBox.setPlaceHolder(placeholder); } get placeholder() { return this.findInput.inputBox.inputElement.getAttribute('placeholder') || ''; } set placeholder(placeholder) { this.findInput.inputBox.setPlaceHolder(placeholder); } get ariaLabel() { return this.findInput.inputBox.getAriaLabel(); } set ariaLabel(ariaLabel) { this.findInput.inputBox.setAriaLabel(ariaLabel); } get password() { return this.findInput.inputBox.inputElement.type === 'password'; } set password(password) { this.findInput.inputBox.inputElement.type = password ? 'password' : 'text'; } set enabled(enabled) { // We can't disable the input box because it is still used for // navigating the list. Instead, we disable the list and the OK // so that nothing can be selected. // TODO: should this be what we do for all find inputs? Or maybe some _other_ API // on findInput to change it to readonly? this.findInput.inputBox.inputElement.toggleAttribute('readonly', !enabled); // TODO: styles of the quick pick need to be moved to the CSS instead of being in line // so things like this can be done in CSS // this.findInput.inputBox.inputElement.classList.toggle('disabled', !enabled); } set toggles(toggles) { this.findInput.setAdditionalToggles(toggles); } hasFocus() { return this.findInput.inputBox.hasFocus(); } setAttribute(name, value) { this.findInput.inputBox.inputElement.setAttribute(name, value); } removeAttribute(name) { this.findInput.inputBox.inputElement.removeAttribute(name); } showDecoration(decoration) { if (decoration === Severity.Ignore) { this.findInput.clearMessage(); } else { this.findInput.showMessage({ type: decoration === Severity.Info ? 1 /* MessageType.INFO */ : decoration === Severity.Warning ? 2 /* MessageType.WARNING */ : 3 /* MessageType.ERROR */, content: '' }); } } stylesForType(decoration) { return this.findInput.inputBox.stylesForType(decoration === Severity.Info ? 1 /* MessageType.INFO */ : decoration === Severity.Warning ? 2 /* MessageType.WARNING */ : 3 /* MessageType.ERROR */); } setFocus() { this.findInput.focus(); } layout() { this.findInput.inputBox.layout(); } }