Skip to content

Commit

Permalink
Merge branch 'joao/tree-indent-guides'
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Jun 18, 2019
2 parents 356440d + 4e7353a commit 036278c
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 34 deletions.
51 changes: 36 additions & 15 deletions src/vs/base/browser/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export function isInDOM(node: Node | null): boolean {
}

interface IDomClassList {
hasClass(node: HTMLElement, className: string): boolean;
addClass(node: HTMLElement, className: string): void;
addClasses(node: HTMLElement, ...classNames: string[]): void;
removeClass(node: HTMLElement, className: string): void;
removeClasses(node: HTMLElement, ...classNames: string[]): void;
toggleClass(node: HTMLElement, className: string, shouldHaveIt?: boolean): void;
hasClass(node: HTMLElement | SVGElement, className: string): boolean;
addClass(node: HTMLElement | SVGElement, className: string): void;
addClasses(node: HTMLElement | SVGElement, ...classNames: string[]): void;
removeClass(node: HTMLElement | SVGElement, className: string): void;
removeClasses(node: HTMLElement | SVGElement, ...classNames: string[]): void;
toggleClass(node: HTMLElement | SVGElement, className: string, shouldHaveIt?: boolean): void;
}

const _manualClassList = new class implements IDomClassList {
Expand Down Expand Up @@ -191,12 +191,12 @@ const _nativeClassList = new class implements IDomClassList {
// In IE11 there is only partial support for `classList` which makes us keep our
// custom implementation. Otherwise use the native implementation, see: http://caniuse.com/#search=classlist
const _classList: IDomClassList = browser.isIE ? _manualClassList : _nativeClassList;
export const hasClass: (node: HTMLElement, className: string) => boolean = _classList.hasClass.bind(_classList);
export const addClass: (node: HTMLElement, className: string) => void = _classList.addClass.bind(_classList);
export const addClasses: (node: HTMLElement, ...classNames: string[]) => void = _classList.addClasses.bind(_classList);
export const removeClass: (node: HTMLElement, className: string) => void = _classList.removeClass.bind(_classList);
export const removeClasses: (node: HTMLElement, ...classNames: string[]) => void = _classList.removeClasses.bind(_classList);
export const toggleClass: (node: HTMLElement, className: string, shouldHaveIt?: boolean) => void = _classList.toggleClass.bind(_classList);
export const hasClass: (node: HTMLElement | SVGElement, className: string) => boolean = _classList.hasClass.bind(_classList);
export const addClass: (node: HTMLElement | SVGElement, className: string) => void = _classList.addClass.bind(_classList);
export const addClasses: (node: HTMLElement | SVGElement, ...classNames: string[]) => void = _classList.addClasses.bind(_classList);
export const removeClass: (node: HTMLElement | SVGElement, className: string) => void = _classList.removeClass.bind(_classList);
export const removeClasses: (node: HTMLElement | SVGElement, ...classNames: string[]) => void = _classList.removeClasses.bind(_classList);
export const toggleClass: (node: HTMLElement | SVGElement, className: string, shouldHaveIt?: boolean) => void = _classList.toggleClass.bind(_classList);

class DomListener implements IDisposable {

Expand Down Expand Up @@ -987,14 +987,28 @@ export function prepend<T extends Node>(parent: HTMLElement, child: T): T {

const SELECTOR_REGEX = /([\w\-]+)?(#([\w\-]+))?((.([\w\-]+))*)/;

export function $<T extends HTMLElement>(description: string, attrs?: { [key: string]: any; }, ...children: Array<Node | string>): T {
export enum Namespace {
HTML = 'http://www.w3.org/1999/xhtml',
SVG = 'http://www.w3.org/2000/svg'
}

function _$<T extends Element>(namespace: Namespace, description: string, attrs?: { [key: string]: any; }, ...children: Array<Node | string>): T {
let match = SELECTOR_REGEX.exec(description);

if (!match) {
throw new Error('Bad use of emmet');
}

let result = document.createElement(match[1] || 'div');
attrs = { ...(attrs || {}) };

let tagName = match[1] || 'div';
let result: T;

if (namespace !== Namespace.HTML) {
result = document.createElementNS(namespace as string, tagName) as T;
} else {
result = document.createElement(tagName) as unknown as T;
}

if (match[3]) {
result.id = match[3];
Expand All @@ -1003,7 +1017,6 @@ export function $<T extends HTMLElement>(description: string, attrs?: { [key: st
result.className = match[4].replace(/\./g, ' ').trim();
}

attrs = attrs || {};
Object.keys(attrs).forEach(name => {
const value = attrs![name];
if (/^on\w+$/.test(name)) {
Expand All @@ -1030,6 +1043,14 @@ export function $<T extends HTMLElement>(description: string, attrs?: { [key: st
return result as T;
}

export function $<T extends HTMLElement>(description: string, attrs?: { [key: string]: any; }, ...children: Array<Node | string>): T {
return _$(Namespace.HTML, description, attrs, ...children);
}

$.SVG = function <T extends SVGElement>(description: string, attrs?: { [key: string]: any; }, ...children: Array<Node | string>): T {
return _$(Namespace.SVG, description, attrs, ...children);
};

export function join(nodes: Node[], separator: Node | string): Node[] {
const result: Node[] = [];

Expand Down
5 changes: 4 additions & 1 deletion src/vs/base/browser/ui/list/listWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ export interface IListStyles {
listFilterWidgetOutline?: Color;
listFilterWidgetNoMatchesOutline?: Color;
listMatchesShadow?: Color;
treeIndentGuidesStroke?: Color;
}

const defaultStyles: IListStyles = {
Expand All @@ -867,7 +868,8 @@ const defaultStyles: IListStyles = {
listFocusAndSelectionForeground: Color.fromHex('#FFFFFF'),
listInactiveSelectionBackground: Color.fromHex('#3F3F46'),
listHoverBackground: Color.fromHex('#2A2D2E'),
listDropBackground: Color.fromHex('#383B3D')
listDropBackground: Color.fromHex('#383B3D'),
treeIndentGuidesStroke: Color.fromHex('#a9a9a9')
};

const DefaultOptions = {
Expand Down Expand Up @@ -1112,6 +1114,7 @@ export class List<T> implements ISpliceable<T>, IDisposable {
return Event.map(this._onPin.event, indexes => this.toListEvent({ indexes }));
}

get domId(): string { return this.view.domId; }
get onDidScroll(): Event<ScrollEvent> { return this.view.onDidScroll; }
get onMouseClick(): Event<IListMouseEvent<T>> { return this.view.onMouseClick; }
get onMouseDblClick(): Event<IListMouseEvent<T>> { return this.view.onMouseDblClick; }
Expand Down
Loading

0 comments on commit 036278c

Please sign in to comment.