Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)

* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973

* disable strict null check
This commit is contained in:
Anthony Dresser
2019-07-15 22:35:46 -07:00
committed by GitHub
parent f720ec642f
commit 0b7e7ddbf9
2406 changed files with 59140 additions and 35464 deletions

View File

@@ -5,7 +5,7 @@
import 'vs/css!./selectBoxCustom';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import { KeyCode, KeyCodeUtils } from 'vs/base/common/keyCodes';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
@@ -85,7 +85,7 @@ class SelectListRenderer implements IListRenderer<ISelectOptionItem, ISelectList
}
}
export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<ISelectOptionItem> {
export class SelectBoxList extends Disposable implements ISelectBoxDelegate, IListVirtualDelegate<ISelectOptionItem> {
private static readonly DEFAULT_DROPDOWN_MINIMUM_BOTTOM_MARGIN = 32;
private static readonly DEFAULT_DROPDOWN_MINIMUM_TOP_MARGIN = 2;
@@ -98,7 +98,6 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
private options: ISelectOptionItem[];
private selected: number;
private readonly _onDidSelect: Emitter<ISelectData>;
private toDispose: IDisposable[];
private styles: ISelectBoxStyles;
private listRenderer: SelectListRenderer;
private contextViewProvider: IContextViewProvider;
@@ -117,7 +116,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
constructor(options: ISelectOptionItem[], selected: number, contextViewProvider: IContextViewProvider, styles: ISelectBoxStyles, selectBoxOptions?: ISelectBoxOptions) {
this.toDispose = [];
super();
this._isVisible = false;
this.selectBoxOptions = selectBoxOptions || Object.create(null);
@@ -137,7 +136,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
}
this._onDidSelect = new Emitter<ISelectData>();
this.toDispose.push(this._onDidSelect);
this._register(this._onDidSelect);
this.styles = styles;
@@ -191,18 +190,21 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
// Parent native select keyboard listeners
this.toDispose.push(dom.addStandardDisposableListener(this.selectElement, 'change', (e) => {
this._register(dom.addStandardDisposableListener(this.selectElement, 'change', (e) => {
this.selected = e.target.selectedIndex;
this._onDidSelect.fire({
index: e.target.selectedIndex,
selected: e.target.value
});
if (!!this.options[this.selected] && !!this.options[this.selected].text) {
this.selectElement.title = this.options[this.selected].text;
}
}));
// Have to implement both keyboard and mouse controllers to handle disabled options
// Intercept mouse events to override normal select actions on parents
this.toDispose.push(dom.addDisposableListener(this.selectElement, dom.EventType.CLICK, (e) => {
this._register(dom.addDisposableListener(this.selectElement, dom.EventType.CLICK, (e) => {
dom.EventHelper.stop(e);
if (this._isVisible) {
@@ -212,13 +214,13 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
}
}));
this.toDispose.push(dom.addDisposableListener(this.selectElement, dom.EventType.MOUSE_DOWN, (e) => {
this._register(dom.addDisposableListener(this.selectElement, dom.EventType.MOUSE_DOWN, (e) => {
dom.EventHelper.stop(e);
}));
// Intercept keyboard handling
this.toDispose.push(dom.addDisposableListener(this.selectElement, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
this._register(dom.addDisposableListener(this.selectElement, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
const event = new StandardKeyboardEvent(e);
let showDropDown = false;
@@ -288,6 +290,9 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
}
this.selectElement.selectedIndex = this.selected;
if (!!this.options[this.selected] && !!this.options[this.selected].text) {
this.selectElement.title = this.options[this.selected].text;
}
}
public setAriaLabel(label: string): void {
@@ -410,7 +415,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
let listBackground = this.styles.selectListBackground ? this.styles.selectListBackground.toString() : background;
this.selectDropDownListContainer.style.backgroundColor = listBackground;
this.selectionDetailsPane.style.backgroundColor = listBackground;
const optionsBorder = this.styles.focusBorder ? this.styles.focusBorder.toString() : null;
const optionsBorder = this.styles.focusBorder ? this.styles.focusBorder.toString() : '';
this.selectDropDownContainer.style.outlineColor = optionsBorder;
this.selectDropDownContainer.style.outlineOffset = '-1px';
}
@@ -744,27 +749,26 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
.filter(() => this.selectList.length > 0)
.map(e => new StandardKeyboardEvent(e));
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Enter).on(e => this.onEnter(e), this, this.toDispose);
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Escape).on(e => this.onEscape(e), this, this.toDispose);
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.UpArrow).on(this.onUpArrow, this, this.toDispose);
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.DownArrow).on(this.onDownArrow, this, this.toDispose);
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.PageDown).on(this.onPageDown, this, this.toDispose);
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.PageUp).on(this.onPageUp, this, this.toDispose);
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Home).on(this.onHome, this, this.toDispose);
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.End).on(this.onEnd, this, this.toDispose);
onSelectDropDownKeyDown.filter(e => (e.keyCode >= KeyCode.KEY_0 && e.keyCode <= KeyCode.KEY_Z) || (e.keyCode >= KeyCode.US_SEMICOLON && e.keyCode <= KeyCode.NUMPAD_DIVIDE)).on(this.onCharacter, this, this.toDispose);
this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Enter).on(e => this.onEnter(e), this));
this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Escape).on(e => this.onEscape(e), this));
this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.UpArrow).on(this.onUpArrow, this));
this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.DownArrow).on(this.onDownArrow, this));
this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.PageDown).on(this.onPageDown, this));
this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.PageUp).on(this.onPageUp, this));
this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Home).on(this.onHome, this));
this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.End).on(this.onEnd, this));
this._register(onSelectDropDownKeyDown.filter(e => (e.keyCode >= KeyCode.KEY_0 && e.keyCode <= KeyCode.KEY_Z) || (e.keyCode >= KeyCode.US_SEMICOLON && e.keyCode <= KeyCode.NUMPAD_DIVIDE)).on(this.onCharacter, this));
// SetUp list mouse controller - control navigation, disabled items, focus
Event.chain(domEvent(this.selectList.getHTMLElement(), 'mouseup'))
this._register(Event.chain(domEvent(this.selectList.getHTMLElement(), 'mouseup'))
.filter(() => this.selectList.length > 0)
.on(e => this.onMouseUp(e), this, this.toDispose);
.on(e => this.onMouseUp(e), this));
this.toDispose.push(
this.selectList.onDidBlur(_ => this.onListBlur()),
this.selectList.onMouseOver(e => typeof e.index !== 'undefined' && this.selectList.setFocus([e.index])),
this.selectList.onFocusChange(e => this.onListFocus(e))
);
this._register(this.selectList.onDidBlur(_ => this.onListBlur()));
this._register(this.selectList.onMouseOver(e => typeof e.index !== 'undefined' && this.selectList.setFocus([e.index])));
this._register(this.selectList.onFocusChange(e => this.onListFocus(e)));
this.selectList.getHTMLElement().setAttribute('aria-label', this.selectBoxOptions.ariaLabel || '');
this.selectList.getHTMLElement().setAttribute('aria-expanded', 'true');
@@ -816,7 +820,11 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
this._onDidSelect.fire({
index: this.selectElement.selectedIndex,
selected: this.options[this.selected].text
});
if (!!this.options[this.selected] && !!this.options[this.selected].text) {
this.selectElement.title = this.options[this.selected].text;
}
}
}
}
@@ -907,6 +915,9 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
index: this.selectElement.selectedIndex,
selected: this.options[this.selected].text
});
if (!!this.options[this.selected] && !!this.options[this.selected].text) {
this.selectElement.title = this.options[this.selected].text;
}
}
this.hideSelectDropDown(true);
@@ -1037,6 +1048,6 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
public dispose(): void {
this.hideSelectDropDown(false);
this.toDispose = dispose(this.toDispose);
super.dispose();
}
}