diff --git a/src/vs/base/browser/builder.ts b/src/vs/base/browser/builder.ts index 48003c5f48c82..8483dad31b919 100644 --- a/src/vs/base/browser/builder.ts +++ b/src/vs/base/browser/builder.ts @@ -102,10 +102,6 @@ export class Dimension { this.width = width; this.height = height; } - - public substract(box: Box): Dimension { - return new Dimension(this.width - box.left - box.right, this.height - box.top - box.bottom); - } } export interface IRange { @@ -336,18 +332,6 @@ export class Builder implements IDisposable { return this.doElement('ul', attributes, fn); } - /** - * Creates a new element of this kind as child of the current element or parent. - * Accepts an object literal as first parameter that can be used to describe the - * attributes of the element. - * Accepts a function as second parameter that can be used to create child elements - * of the element. The function will be called with a new builder created with the - * provided element. - */ - public ol(attributes?: any, fn?: (builder: Builder) => void): Builder { - return this.doElement('ol', attributes, fn); - } - /** * Creates a new element of this kind as child of the current element or parent. * Accepts an object literal as first parameter that can be used to describe the @@ -396,42 +380,6 @@ export class Builder implements IDisposable { return this.doElement('a', attributes, fn); } - /** - * Creates a new element of this kind as child of the current element or parent. - * Accepts an object literal as first parameter that can be used to describe the - * attributes of the element. - * Accepts a function as second parameter that can be used to create child elements - * of the element. The function will be called with a new builder created with the - * provided element. - */ - public header(attributes?: any, fn?: (builder: Builder) => void): Builder { - return this.doElement('header', attributes, fn); - } - - /** - * Creates a new element of this kind as child of the current element or parent. - * Accepts an object literal as first parameter that can be used to describe the - * attributes of the element. - * Accepts a function as second parameter that can be used to create child elements - * of the element. The function will be called with a new builder created with the - * provided element. - */ - public section(attributes?: any, fn?: (builder: Builder) => void): Builder { - return this.doElement('section', attributes, fn); - } - - /** - * Creates a new element of this kind as child of the current element or parent. - * Accepts an object literal as first parameter that can be used to describe the - * attributes of the element. - * Accepts a function as second parameter that can be used to create child elements - * of the element. The function will be called with a new builder created with the - * provided element. - */ - public footer(attributes?: any, fn?: (builder: Builder) => void): Builder { - return this.doElement('footer', attributes, fn); - } - /** * Creates a new element of given tag name as child of the current element or parent. * Accepts an object literal as first parameter that can be used to describe the @@ -488,15 +436,6 @@ export class Builder implements IDisposable { return this; } - /** - * Returns true if the current element of this builder is the active element. - */ - public hasFocus(): boolean { - let activeElement: Element = document.activeElement; - - return (activeElement === this.currentElement); - } - /** * Calls select() on the current HTML element; */ @@ -521,15 +460,6 @@ export class Builder implements IDisposable { return this; } - /** - * Calls click() on the current HTML element; - */ - public domClick(): Builder { - this.currentElement.click(); - - return this; - } - /** * Registers listener on event types on the current element. */ @@ -645,30 +575,6 @@ export class Builder implements IDisposable { return this; } - /** - * Registers listener on event types on the current element and causes - * the event to prevent default execution (e.preventDefault()). If the - * parameter "cancelBubble" is set to true, it will also prevent bubbling - * of the event. - */ - public preventDefault(type: string, cancelBubble: boolean, listenerToUnbindContainer?: IDisposable[], useCapture?: boolean): Builder; - public preventDefault(typesArray: string[], cancelBubble: boolean, listenerToUnbindContainer?: IDisposable[], useCapture?: boolean): Builder; - public preventDefault(arg1: any, cancelBubble: boolean, listenerToUnbindContainer?: IDisposable[], useCapture?: boolean): Builder { - let fn = function (e: Event) { - e.preventDefault(); - - if (cancelBubble) { - if (e.stopPropagation) { - e.stopPropagation(); - } else { - e.cancelBubble = true; - } - } - }; - - return this.on(arg1, fn, listenerToUnbindContainer, useCapture); - } - /** * This method has different characteristics based on the parameter provided: * a) a single string passed in as argument will return the attribute value using the @@ -745,24 +651,6 @@ export class Builder implements IDisposable { return this; } - /** - * Sets the src attribute to the value provided for the current HTML element of the builder. - */ - public src(src: string): Builder { - this.currentElement.setAttribute('src', src); - - return this; - } - - /** - * Sets the href attribute to the value provided for the current HTML element of the builder. - */ - public href(href: string): Builder { - this.currentElement.setAttribute('href', href); - - return this; - } - /** * Sets the title attribute to the value provided for the current HTML element of the builder. */ @@ -799,24 +687,6 @@ export class Builder implements IDisposable { return this; } - /** - * Sets the alt attribute to the value provided for the current HTML element of the builder. - */ - public alt(alt: string): Builder { - this.currentElement.setAttribute('alt', alt); - - return this; - } - - /** - * Sets the name draggable to the value provided for the current HTML element of the builder. - */ - public draggable(isDraggable: boolean): Builder { - this.currentElement.setAttribute('draggable', isDraggable ? 'true' : 'false'); - - return this; - } - /** * Sets the tabindex attribute to the value provided for the current HTML element of the builder. */ @@ -960,22 +830,6 @@ export class Builder implements IDisposable { return this; } - /** - * Sets the first class to the current HTML element of the builder if the second class is currently set - * and vice versa otherwise. - */ - public swapClass(classA: string, classB: string): Builder { - if (this.hasClass(classA)) { - this.removeClass(classA); - this.addClass(classB); - } else { - this.removeClass(classB); - this.addClass(classA); - } - - return this; - } - /** * Adds or removes the provided className for the current HTML element of the builder. */ @@ -998,15 +852,6 @@ export class Builder implements IDisposable { return this; } - /** - * Sets the CSS property background. - */ - public background(color: string): Builder { - this.currentElement.style.backgroundColor = color; - - return this; - } - /** * Sets the CSS property padding. */ @@ -1169,71 +1014,6 @@ export class Builder implements IDisposable { return this; } - /** - * Sets the CSS property float. - */ - public float(float: string): Builder { - this.currentElement.style.cssFloat = float; - - return this; - } - - /** - * Sets the CSS property clear. - */ - public clear(clear: string): Builder { - this.currentElement.style.clear = clear; - - return this; - } - - /** - * Sets the CSS property for fonts back to default. - */ - public normal(): Builder { - this.currentElement.style.fontStyle = 'normal'; - this.currentElement.style.fontWeight = 'normal'; - this.currentElement.style.textDecoration = 'none'; - - return this; - } - - /** - * Sets the CSS property font-style to italic. - */ - public italic(): Builder { - this.currentElement.style.fontStyle = 'italic'; - - return this; - } - - /** - * Sets the CSS property font-weight to bold. - */ - public bold(): Builder { - this.currentElement.style.fontWeight = 'bold'; - - return this; - } - - /** - * Sets the CSS property text-decoration to underline. - */ - public underline(): Builder { - this.currentElement.style.textDecoration = 'underline'; - - return this; - } - - /** - * Sets the CSS property overflow. - */ - public overflow(overflow: string): Builder { - this.currentElement.style.overflow = overflow; - - return this; - } - /** * Sets the CSS property display. */ @@ -1243,18 +1023,6 @@ export class Builder implements IDisposable { return this; } - public disable(): Builder { - this.currentElement.setAttribute('disabled', 'disabled'); - - return this; - } - - public enable(): Builder { - this.currentElement.removeAttribute('disabled'); - - return this; - } - /** * Shows the current element of the builder. */ @@ -1439,24 +1207,6 @@ export class Builder implements IDisposable { return this; } - /** - * Sets the CSS property text-align. - */ - public textAlign(textAlign: string): Builder { - this.currentElement.style.textAlign = textAlign; - - return this; - } - - /** - * Sets the CSS property vertical-align. - */ - public verticalAlign(valign: string): Builder { - this.currentElement.style.verticalAlign = valign; - - return this; - } - private toPixel(obj: any): string { if (obj.toString().indexOf('px') === -1) { return obj.toString() + 'px'; @@ -1507,32 +1257,6 @@ export class Builder implements IDisposable { return this.innerHtml(strings.escape(html), append); } - /** - * Adds the provided object as property to the current element. Call getBinding() - * to retrieve it again. - */ - public bind(object: any): Builder { - bindElement(this.currentElement, object); - - return this; - } - - /** - * Removes the binding of the current element. - */ - public unbind(): Builder { - unbindElement(this.currentElement); - - return this; - } - - /** - * Returns the object that was passed into the bind() call. - */ - public getBinding(): any { - return getBindingFromElement(this.currentElement); - } - /** * Allows to store arbritary data into the current element. */ @@ -1569,20 +1293,6 @@ export class Builder implements IDisposable { return withElement(this.currentElement.parentNode, offdom); } - /** - * Returns a new builder with all child elements of the current element of the builder. - */ - public children(offdom?: boolean): MultiBuilder { - let children = this.currentElement.children; - - let builders: Builder[] = []; - for (let i = 0; i < children.length; i++) { - builders.push(withElement(children.item(i), offdom)); - } - - return new MultiBuilder(builders); - } - /** * Returns a new builder with the child at the given index. */ @@ -1592,48 +1302,6 @@ export class Builder implements IDisposable { return withElement(children.item(index)); } - /** - * Removes the current HTMLElement from the given builder from this builder if this builders - * current HTMLElement is the direct parent. - */ - public removeChild(builder: Builder): Builder { - if (this.currentElement === builder.parent().getHTMLElement()) { - this.currentElement.removeChild(builder.getHTMLElement()); - } - - return this; - } - - /** - * Returns a new builder with all elements matching the provided selector scoped to the - * current element of the builder. Use Build.withElementsBySelector() to run the selector - * over the entire DOM. - * The returned builder is an instance of array that can have 0 elements if the selector does not match any - * elements. - */ - public select(selector: string, offdom?: boolean): MultiBuilder { - assert.ok(types.isString(selector), 'Expected String as parameter'); - - let elements = this.currentElement.querySelectorAll(selector); - - let builders: Builder[] = []; - for (let i = 0; i < elements.length; i++) { - builders.push(withElement(elements.item(i), offdom)); - } - - return new MultiBuilder(builders); - } - - /** - * Returns true if the current element of the builder matches the given selector and false otherwise. - */ - public matches(selector: string): boolean { - let element = this.currentElement; - let matches = (element).webkitMatchesSelector || (element).mozMatchesSelector || (element).msMatchesSelector || (element).oMatchesSelector; - - return matches && matches.call(element, selector); - } - /** * Returns true if the current element of the builder has no children. */ @@ -1772,16 +1440,6 @@ export class Builder implements IDisposable { return new Dimension(totalWidth, totalHeight); } - /** - * Gets the size (in pixels) of the inside of the element, excluding the border and padding. - */ - public getContentSize(): Dimension { - let contentWidth = DOM.getContentWidth(this.currentElement); - let contentHeight = DOM.getContentHeight(this.currentElement); - - return new Dimension(contentWidth, contentHeight); - } - /** * Another variant of getting the inner dimensions of an element. */ @@ -1910,74 +1568,9 @@ export class MultiBuilder extends Builder { this.length = this.builders.length; } - public pop(): Builder { - let element = this.builders.pop(); - this.length = this.builders.length; - - return element; - } - - public concat(items: Builder[]): Builder[] { - let elements = this.builders.concat(items); - this.length = this.builders.length; - - return elements; - } - - public shift(): Builder { - let element = this.builders.shift(); - this.length = this.builders.length; - - return element; - } - - public unshift(item: Builder): number { - let res = this.builders.unshift(item); - this.length = this.builders.length; - - return res; - } - - public slice(start: number, end?: number): Builder[] { - let elements = this.builders.slice(start, end); - this.length = this.builders.length; - - return elements; - } - - public splice(start: number, deleteCount?: number): Builder[] { - let elements = this.builders.splice(start, deleteCount); - this.length = this.builders.length; - - return elements; - } - public clone(): MultiBuilder { return new MultiBuilder(this); } - - public and(element: HTMLElement): MultiBuilder; - public and(builder: Builder): MultiBuilder; - public and(obj: any): MultiBuilder { - - // Convert HTMLElement to Builder as necessary - if (!(obj instanceof Builder) && !(obj instanceof MultiBuilder)) { - obj = new Builder((obj)); - } - - let builders: Builder[] = []; - if (obj instanceof MultiBuilder) { - for (let i = 0; i < (obj).length; i++) { - builders.push((obj).item(i)); - } - } else { - builders.push(obj); - } - - this.push.apply(this, builders); - - return this; - } } function withBuilder(builder: Builder, offdom?: boolean): Builder { @@ -1988,7 +1581,7 @@ function withBuilder(builder: Builder, offdom?: boolean): Builder { return new Builder(builder.getHTMLElement(), offdom); } -function withElement(element: HTMLElement, offdom?: boolean): Builder { +export function withElement(element: HTMLElement, offdom?: boolean): Builder { return new Builder(element, offdom); } diff --git a/src/vs/base/browser/ui/inputbox/inputBox.ts b/src/vs/base/browser/ui/inputbox/inputBox.ts index 8dfb882931c8a..df7c0b99ba6bc 100644 --- a/src/vs/base/browser/ui/inputbox/inputBox.ts +++ b/src/vs/base/browser/ui/inputbox/inputBox.ts @@ -219,10 +219,6 @@ export class InputBox extends Widget { } } - public setContextViewProvider(contextViewProvider: IContextViewProvider): void { - this.contextViewProvider = contextViewProvider; - } - public get inputElement(): HTMLInputElement { return this.input; } diff --git a/src/vs/base/common/filters.ts b/src/vs/base/common/filters.ts index b43808d4e3115..ebb04449af7c6 100644 --- a/src/vs/base/common/filters.ts +++ b/src/vs/base/common/filters.ts @@ -691,16 +691,4 @@ class LazyArray { } return Array.prototype.concat.apply(this._data, bucket); } -} - -export function nextTypoPermutation(pattern: string, patternPos: number) { - - if (patternPos + 1 >= pattern.length) { - return undefined; - } - - return pattern.slice(0, patternPos) - + pattern[patternPos + 1] - + pattern[patternPos] - + pattern.slice(patternPos + 2); } \ No newline at end of file diff --git a/src/vs/base/common/map.ts b/src/vs/base/common/map.ts index 04186a763cdb6..58e3fea9be18e 100644 --- a/src/vs/base/common/map.ts +++ b/src/vs/base/common/map.ts @@ -555,18 +555,6 @@ export class LinkedMap { } } - public forEachReverse(callbackfn: (value: V, key: K, map: LinkedMap) => void, thisArg?: any): void { - let current = this._tail; - while (current) { - if (thisArg) { - callbackfn.bind(thisArg)(current.value, current.key, this); - } else { - callbackfn(current.value, current.key, this); - } - current = current.previous; - } - } - public values(): V[] { let result: V[] = []; let current = this._head; diff --git a/src/vs/base/test/browser/builder.test.ts b/src/vs/base/test/browser/builder.test.ts index 76d1221c7807c..3235c8241a980 100644 --- a/src/vs/base/test/browser/builder.test.ts +++ b/src/vs/base/test/browser/builder.test.ts @@ -5,7 +5,7 @@ 'use strict'; import * as assert from 'assert'; -import { Build, Builder, MultiBuilder, Binding, Dimension, Position, Box, $ } from 'vs/base/browser/builder'; +import { Build, Builder, MultiBuilder, Binding, Position, $, bindElement, withElement } from 'vs/base/browser/builder'; import * as Types from 'vs/base/common/types'; import * as DomUtils from 'vs/base/browser/dom'; import { TPromise } from 'vs/base/common/winjs.base'; @@ -30,6 +30,17 @@ let withBuilder = function (builder: Builder, offdom: boolean) { return new Builder(builder.getHTMLElement(), offdom); }; +function select(builder: Builder, selector: string, offdom?: boolean): MultiBuilder { + let elements = builder.getHTMLElement().querySelectorAll(selector); + + let builders: Builder[] = []; + for (let i = 0; i < elements.length; i++) { + builders.push(withElement(elements.item(i), offdom)); + } + + return new MultiBuilder(builders); +} + suite('Builder', () => { let fixture: HTMLElement; let fixtureId = 'builder-fixture'; @@ -44,13 +55,6 @@ suite('Builder', () => { document.body.removeChild(fixture); }); - test('Dimension.substract()', function () { - let d1 = new Dimension(200, 100); - let d2 = new Box(10, 20, 30, 40); - - assert.deepEqual(d1.substract(d2), new Dimension(140, 60)); - }); - test('Position', function () { let p = new Position(200, 100); assert.strictEqual(p.x, 200); @@ -103,7 +107,6 @@ suite('Builder', () => { assert(allDivs); assert(allDivs.length >= 1); assert(Types.isFunction(allDivs.push)); - assert(Types.isFunction(allDivs.pop)); assert(allDivs instanceof MultiBuilder); for (let key in b) { @@ -117,7 +120,6 @@ suite('Builder', () => { assert(noElement); assert(noElement.length === 0); assert(Types.isFunction(noElement.push)); - assert(Types.isFunction(noElement.pop)); assert(noElement instanceof MultiBuilder); for (let key in b) { @@ -267,7 +269,7 @@ suite('Builder', () => { b.build(Build.withElementById(fixtureId), 0); b = Build.withElementById(fixtureId); - let divs = b.select('div'); + let divs = select(b, 'div'); assert.strictEqual(divs.length, 4); let ids = divs.attr('id'); @@ -282,7 +284,7 @@ suite('Builder', () => { b.build(Build.withElementById(fixtureId), 2); b = Build.withElementById(fixtureId); - divs = b.select('div'); + divs = select(b, 'div'); assert.strictEqual(divs.length, 5); ids = divs.attr('id'); @@ -337,10 +339,8 @@ suite('Builder', () => { div.span(); }); - let multiBuilder = Build.withElementById(fixtureId).select('div'); + let multiBuilder = select(Build.withElementById(fixtureId), 'div'); assert(multiBuilder.length === 3); - - assert(multiBuilder.select('span').length === 3); }); test('Builder.p() and other elements', function () { @@ -381,8 +381,8 @@ suite('Builder', () => { assert.strictEqual('p', div.getHTMLElement().nodeName.toLowerCase()); }); - assert.strictEqual(Build.withElementById(fixtureId).select('div').length, 1); - assert.strictEqual(Build.withElementById(fixtureId).select('*').length, 7); + assert.strictEqual(select(Build.withElementById(fixtureId), 'div').length, 1); + assert.strictEqual(select(Build.withElementById(fixtureId), '*').length, 7); assert.strictEqual(Build.withElementById('builderspan').getHTMLElement().innerHTML, 'Foo Bar'); assert.strictEqual(Build.withElementById('builderimg').attr('src'), '#'); @@ -453,8 +453,8 @@ suite('Builder', () => { }); }); - assert.strictEqual(Build.withElementById(fixtureId).select('div').length, 1); - assert.strictEqual(Build.withElementById(fixtureId).select('*').length, 7); + assert.strictEqual(select(Build.withElementById(fixtureId), 'div').length, 1); + assert.strictEqual(select(Build.withElementById(fixtureId), '*').length, 7); assert.strictEqual(Build.withElementById('builderspan').getHTMLElement().innerHTML, 'Foo Bar'); assert.strictEqual(Build.withElementById('builderimg').attr('src'), '#'); @@ -550,36 +550,24 @@ suite('Builder', () => { b.div(); b.id('foobar'); - b.src('foobar'); - b.href('foobar'); b.title('foobar'); b.name('foobar'); b.type('foobar'); b.value('foobar'); - b.alt('foobar'); - b.draggable(true); b.tabindex(0); assert.strictEqual(b.attr('id'), 'foobar'); - assert.strictEqual(b.attr('src'), 'foobar'); - assert.strictEqual(b.attr('href'), 'foobar'); assert.strictEqual(b.attr('title'), 'foobar'); assert.strictEqual(b.attr('name'), 'foobar'); assert.strictEqual(b.attr('type'), 'foobar'); assert.strictEqual(b.attr('value'), 'foobar'); - assert.strictEqual(b.attr('alt'), 'foobar'); - assert.strictEqual(b.attr('draggable'), 'true'); assert.strictEqual(b.attr('tabindex'), '0'); assert.strictEqual(b.getHTMLElement().getAttribute('id'), 'foobar'); - assert.strictEqual(b.getHTMLElement().getAttribute('src'), 'foobar'); - assert.strictEqual(b.getHTMLElement().getAttribute('href'), 'foobar'); assert.strictEqual(b.getHTMLElement().getAttribute('title'), 'foobar'); assert.strictEqual(b.getHTMLElement().getAttribute('name'), 'foobar'); assert.strictEqual(b.getHTMLElement().getAttribute('type'), 'foobar'); assert.strictEqual(b.getHTMLElement().getAttribute('value'), 'foobar'); - assert.strictEqual(b.getHTMLElement().getAttribute('alt'), 'foobar'); - assert.strictEqual(b.getHTMLElement().getAttribute('draggable'), 'true'); assert.strictEqual(b.getHTMLElement().getAttribute('tabindex'), '0'); }); @@ -612,35 +600,6 @@ suite('Builder', () => { assert(!b.hasClass('barfoo')); assert(!b.hasClass('foobar')); assert(!b.getHTMLElement().className); - - b.addClass('foobar'); - b.swapClass('foobar', 'barfoo'); - assert(b.hasClass('barfoo')); - b.swapClass('foobar', 'barfoo'); - assert(b.hasClass('foobar')); - - b.toggleClass('foobar'); - assert(!b.hasClass('foobar')); - - b.toggleClass('barfoo'); - assert(b.hasClass('barfoo')); - - b.setClass('helloworld'); - assert(!b.hasClass('barfoo')); - assert(b.hasClass('helloworld')); - b.setClass(''); - assert(!b.hasClass('helloworld')); - }); - - test('Builder.color() and .background()', function () { - let b = Build.withElementById(fixtureId); - b.div(); - - b.color('red').background('blue'); - - assert.strictEqual(b.style('color'), 'red'); - assert.strictEqual(b.style('background-color'), 'blue'); - assert(b.getComputedStyle()); }); test('Builder.padding() and .margin()', function () { @@ -692,45 +651,6 @@ suite('Builder', () => { assert.strictEqual(b.style('maxHeight'), '600px'); }); - test('Builder.float() and .clear()', function () { - let b = Build.withElementById(fixtureId); - b.div(); - - b.float('left'); - b.clear('right'); - - assert.strictEqual(b.style('float'), 'left'); - assert.strictEqual(b.style('clear'), 'right'); - }); - - test('Builder.normal(), .italic(), .bold() and underline()', function () { - let b = Build.withElementById(fixtureId); - b.div(); - - b.italic().underline().bold(); - - assert(b.style('font-weight') === 'bold' || b.style('font-weight') === '700'); // For Opera - assert.strictEqual(b.style('text-decoration'), 'underline'); - assert.strictEqual(b.style('font-style'), 'italic'); - - b.normal(); - - assert(b.style('font-weight') === 'normal' || b.style('font-weight') === '400'); // For Opera - assert(b.style('text-decoration') === 'none' || b.style('text-decoration') === 'initial'); - assert.strictEqual(b.style('font-style'), 'normal'); - }); - - test('Builder.display() and .overflow()', function () { - let b = Build.withElementById(fixtureId); - b.div(); - - b.display('inline'); - b.overflow('hidden'); - - assert.strictEqual(b.style('display'), 'inline'); - assert.strictEqual(b.style('overflow'), 'hidden'); - }); - test('Builder.show() and .hide()', function () { let b = Build.withElementById(fixtureId); b.div(); @@ -810,17 +730,6 @@ suite('Builder', () => { assert.strictEqual(b.style('border-left-style'), 'dashed'); }); - test('Builder.textAlign() and .verticalAlign()', function () { - let b = Build.withElementById(fixtureId); - b.div(); - - b.textAlign('center'); - b.verticalAlign('top'); - - assert.strictEqual(b.style('textAlign'), 'center'); - assert.strictEqual(b.style('verticalAlign'), 'top'); - }); - test('Builder.innerHtml()', function () { let b = Build.withElementById(fixtureId); b.div(); @@ -843,30 +752,6 @@ suite('Builder', () => { assert.strictEqual(b.getHTMLElement().innerHTML, 'Foo Bar'); }); - test('Builder.parent(), .children(), .removeChild() and isEmpty()', function () { - let b = Build.withElementById(fixtureId); - b.empty(); - - assert(b.isEmpty()); - assert.strictEqual(b.parent().getHTMLElement(), b.getHTMLElement().parentNode); - assert(b.children().length === 0); - - let divB; - b.div(function (div: Builder) { - divB = div.clone(); - div.span(); - }); - b.span(); - - b = Build.withElementById(fixtureId); - assert(!b.isEmpty()); - assert.strictEqual(b.parent().getHTMLElement(), b.getHTMLElement().parentNode); - assert.equal(b.children().length, 2); - - b.removeChild(divB); - assert.equal(b.children().length, 1); - }); - test('Build Client Area', function () { // Global @@ -881,49 +766,6 @@ suite('Builder', () => { // assert(dimensions.height >= 0); }); - // test('Builder.select() and .matches()', function () { - // let b = Build.withElementById(fixtureId); - - // assert(b.matches('#' + fixtureId)); - - // let divs = withElementsBySelector('div'); - // for (let i = 0; i < divs.length; i++) { - // assert (divs.item(i).matches('div')); - // } - - // assert(b.select('div').length === 0); - - // b.clone().div(); - - // assert(b.select('div').length === 1); - // }); - - test('Builder.select() and .matches()', function () { - let b = Build.withElementById(fixtureId); - - assert(b.getTotalSize()); - assert(b.getContentSize()); - }); - - test('Builder.preventDefault()', function () { - let b = Build.withElementById(fixtureId); - b.element('input', { - type: 'button' - }); - - b.preventDefault(DomUtils.EventType.CLICK, true); - - b.once(DomUtils.EventType.CLICK, function (e) { - if (e.defaultPrevented) { - assert.strictEqual(e.defaultPrevented, true); - } else if (e.cancelBubble) { - assert.strictEqual(e.cancelBubble, true); - } - }); - - b.domClick(); - }); - test('Builder.once()', function () { let b = Build.withElementById(fixtureId); b.element('input', { @@ -936,8 +778,8 @@ suite('Builder', () => { assert(counter <= 1); }); - b.domClick(); - b.domClick(); + b.getHTMLElement().click(); + b.getHTMLElement().click(); }); test('Builder.once() with capture', function () { @@ -952,8 +794,8 @@ suite('Builder', () => { assert(counter <= 1); }, null, true); - b.domClick(); - b.domClick(); + b.getHTMLElement().click(); + b.getHTMLElement().click(); }); test('Builder.on() and .off()', function () { @@ -970,12 +812,12 @@ suite('Builder', () => { assert(listeners.length === 1); - b.domClick(); + b.getHTMLElement().click(); b.off(DomUtils.EventType.BLUR); - b.domClick(); + b.getHTMLElement().click(); b.off(DomUtils.EventType.CLICK); - b.domClick(); - b.domClick(); + b.getHTMLElement().click(); + b.getHTMLElement().click(); assert.equal(counter, 2); }); @@ -994,16 +836,16 @@ suite('Builder', () => { assert(listeners.length === 1); - b.domClick(); + b.getHTMLElement().click(); b.off(DomUtils.EventType.BLUR); - b.domClick(); + b.getHTMLElement().click(); b.off(DomUtils.EventType.BLUR, true); - b.domClick(); + b.getHTMLElement().click(); b.off(DomUtils.EventType.CLICK); - b.domClick(); + b.getHTMLElement().click(); b.off(DomUtils.EventType.CLICK, true); - b.domClick(); - b.domClick(); + b.getHTMLElement().click(); + b.getHTMLElement().click(); assert(counter === 4); }); @@ -1021,7 +863,7 @@ suite('Builder', () => { let counter7 = 0; b.div(function (div: Builder) { - div.bind('Foo Bar'); + bindElement(div.getHTMLElement(), 'Foo Bar'); div.setProperty('Foo', 'Bar'); bindings.push(div.clone()); @@ -1034,7 +876,7 @@ suite('Builder', () => { inputs.push(div.clone()); div.p(function (p: Builder) { - p.bind('Foo Bar'); + bindElement(p.getHTMLElement(), 'Foo Bar'); p.setProperty('Foo', 'Bar'); bindings.push(p.clone()); @@ -1047,7 +889,7 @@ suite('Builder', () => { inputs.push(p.clone()); p.ul(function (ul: Builder) { - ul.bind('Foo Bar'); + bindElement(ul.getHTMLElement(), 'Foo Bar'); ul.setProperty('Foo', 'Bar'); bindings.push(ul.clone()); @@ -1060,7 +902,7 @@ suite('Builder', () => { inputs.push(ul.clone()); ul.li(function (li: Builder) { - li.bind('Foo Bar'); + bindElement(li.getHTMLElement(), 'Foo Bar'); li.setProperty('Foo', 'Bar'); bindings.push(li.clone()); @@ -1076,7 +918,7 @@ suite('Builder', () => { id: 'builderspan', innerHtml: 'Foo Bar' }, function (span) { - span.bind('Foo Bar'); + bindElement(span.getHTMLElement(), 'Foo Bar'); span.setProperty('Foo', 'Bar'); bindings.push(span.clone()); @@ -1093,7 +935,7 @@ suite('Builder', () => { id: 'builderimg', src: '#' }, function (img) { - img.bind('Foo Bar'); + bindElement(img.getHTMLElement(), 'Foo Bar'); img.setProperty('Foo', 'Bar'); bindings.push(img.clone()); @@ -1111,7 +953,7 @@ suite('Builder', () => { href: '#', innerHtml: 'Link' }, function (a) { - a.bind('Foo Bar'); + bindElement(a.getHTMLElement(), 'Foo Bar'); a.setProperty('Foo', 'Bar'); bindings.push(a.clone()); @@ -1129,23 +971,21 @@ suite('Builder', () => { }); inputs.forEach(function (input) { - input.domClick(); + input.getHTMLElement().click(); }); for (let i = 0; i < bindings.length; i++) { - assert(bindings[i].getBinding()); assert(bindings[i].getProperty('Foo')); } Build.withElementById(fixtureId).empty(); - assert(Build.withElementById(fixtureId).select('*').length === 0); + assert(select(Build.withElementById(fixtureId), '*').length === 0); inputs.forEach(function (input) { - input.domClick(); + input.getHTMLElement().click(); }); for (let i = 0; i < bindings.length; i++) { - assert(!bindings[i].getBinding()); assert(!bindings[i].getProperty('Foo')); } @@ -1208,7 +1048,7 @@ suite('Builder', () => { let counter7 = 0; b.div(function (div: Builder) { - div.bind('Foo Bar'); + bindElement(div.getHTMLElement(), 'Foo Bar'); div.setProperty('Foo', 'Bar'); bindings.push(div.clone()); @@ -1221,7 +1061,7 @@ suite('Builder', () => { inputs.push(div.clone()); div.p(function (p: Builder) { - p.bind('Foo Bar'); + bindElement(p.getHTMLElement(), 'Foo Bar'); p.setProperty('Foo', 'Bar'); bindings.push(p.clone()); @@ -1234,7 +1074,7 @@ suite('Builder', () => { inputs.push(p.clone()); p.ul(function (ul: Builder) { - ul.bind('Foo Bar'); + bindElement(ul.getHTMLElement(), 'Foo Bar'); ul.setProperty('Foo', 'Bar'); bindings.push(ul.clone()); @@ -1247,7 +1087,7 @@ suite('Builder', () => { inputs.push(ul.clone()); ul.li(function (li: Builder) { - li.bind('Foo Bar'); + bindElement(li.getHTMLElement(), 'Foo Bar'); li.setProperty('Foo', 'Bar'); bindings.push(li.clone()); @@ -1263,7 +1103,7 @@ suite('Builder', () => { id: 'builderspan', innerHtml: 'Foo Bar' }, function (span) { - span.bind('Foo Bar'); + bindElement(span.getHTMLElement(), 'Foo Bar'); span.setProperty('Foo', 'Bar'); bindings.push(span.clone()); @@ -1280,7 +1120,7 @@ suite('Builder', () => { id: 'builderimg', src: '#' }, function (img) { - img.bind('Foo Bar'); + bindElement(img.getHTMLElement(), 'Foo Bar'); img.setProperty('Foo', 'Bar'); bindings.push(img.clone()); @@ -1298,7 +1138,7 @@ suite('Builder', () => { href: '#', innerHtml: 'Link' }, function (a) { - a.bind('Foo Bar'); + bindElement(a.getHTMLElement(), 'Foo Bar'); a.setProperty('Foo', 'Bar'); bindings.push(a.clone()); @@ -1316,23 +1156,21 @@ suite('Builder', () => { }); inputs.forEach(function (input) { - input.domClick(); + input.getHTMLElement().click(); }); for (let i = 0; i < bindings.length; i++) { - assert(bindings[i].getBinding()); assert(bindings[i].getProperty('Foo')); } - Build.withElementById(fixtureId).select('div').destroy(); - assert(Build.withElementById(fixtureId).select('*').length === 0); + select(Build.withElementById(fixtureId), 'div').destroy(); + assert(select(Build.withElementById(fixtureId), '*').length === 0); inputs.forEach(function (input) { - input.domClick(); + input.getHTMLElement().click(); }); for (let i = 0; i < bindings.length; i++) { - assert(!bindings[i].getBinding()); assert(!bindings[i].getProperty('Foo')); } @@ -1383,92 +1221,6 @@ suite('Builder', () => { } }); - test('Builder.empty() MultiBuilder', function () { - let b = Build.withElementById(fixtureId); - let inputs: Builder[] = []; - - let firstCounter = 0; - b.div(function (div: Builder) { - div.element('input', { - type: 'button' - }).on(DomUtils.EventType.CLICK, function () { - firstCounter++; - }); - - inputs.push(div.clone()); - }); - - let secondCounter = 0; - b.div(function (div: Builder) { - div.element('input', { - type: 'button' - }).on(DomUtils.EventType.CLICK, function () { - secondCounter++; - }); - - inputs.push(div.clone()); - }); - - let thirdCounter = 0; - b.div(function (div: Builder) { - div.element('input', { - type: 'button' - }).on(DomUtils.EventType.CLICK, function () { - thirdCounter++; - }); - - inputs.push(div.clone()); - }); - - Build.withElementById(fixtureId).select('div > input').domClick(); - - Build.withElementById(fixtureId).select('div').empty(); - - inputs.forEach(function (input) { - input.domClick(); - }); - - assert.equal(firstCounter, 1); - assert.equal(secondCounter, 1); - assert.equal(thirdCounter, 1); - }); - - test('Builder .domFocus(), .domBlur(), .hasFocus()', function () { - let b = Build.withElementById(fixtureId); - - b.element('input', { type: 'text' }); - assert(!b.hasFocus()); - b.domFocus().domSelect(); - assert(b.hasFocus()); - b.domBlur(); - assert(!b.hasFocus()); - }); - - test('Builder misc', function () { - let b = Build.withElementById(fixtureId); - b.div(); - - b.on([DomUtils.EventType.CLICK, DomUtils.EventType.MOUSE_DOWN, DomUtils.EventType.MOUSE_UP], function (e, b) { - }); - b.off([DomUtils.EventType.CLICK, DomUtils.EventType.MOUSE_DOWN, DomUtils.EventType.MOUSE_UP]); - - b.once([DomUtils.EventType.CLICK, DomUtils.EventType.MOUSE_DOWN, DomUtils.EventType.MOUSE_UP], function (e, b) { - }); - b.off([DomUtils.EventType.CLICK, DomUtils.EventType.MOUSE_DOWN, DomUtils.EventType.MOUSE_UP]); - - b.preventDefault(DomUtils.EventType.CLICK, true); - - b.bind('foo'); - assert.strictEqual(b.getBinding(), 'foo'); - b.unbind(); - assert(!b.getBinding()); - - b.setProperty('foo', 'bar'); - assert.strictEqual(b.getProperty('foo'), 'bar'); - b.removeProperty('foo'); - assert(!b.getProperty('foo')); - }); - test('Builder.offDOM()', function () { let b = Build.withElementById(fixtureId); b.div({ id: '1' }); diff --git a/src/vs/base/test/common/filters.test.ts b/src/vs/base/test/common/filters.test.ts index 6aea42f4915e9..527972a578d8e 100644 --- a/src/vs/base/test/common/filters.test.ts +++ b/src/vs/base/test/common/filters.test.ts @@ -5,7 +5,7 @@ 'use strict'; import * as assert from 'assert'; -import { IFilter, or, matchesPrefix, matchesStrictPrefix, matchesCamelCase, matchesSubString, matchesContiguousSubString, matchesWords, fuzzyScore, nextTypoPermutation, IMatch } from 'vs/base/common/filters'; +import { IFilter, or, matchesPrefix, matchesStrictPrefix, matchesCamelCase, matchesSubString, matchesContiguousSubString, matchesWords, fuzzyScore, IMatch } from 'vs/base/common/filters'; function filterOk(filter: IFilter, word: string, wordToMatchAgainst: string, highlights?: { start: number; end: number; }[]) { let r = filter(word, wordToMatchAgainst); @@ -422,20 +422,4 @@ suite('Filters', () => { assertTopScore(fuzzyScore, '_lines', 1, '_lineS', '_lines'); assertTopScore(fuzzyScore, '_lineS', 0, '_lineS', '_lines'); }); - - test('nextTypoPermutation', function () { - - function assertTypos(pattern: string, ...variants: string[]) { - let pos = 1; - for (const expected of variants) { - const actual = nextTypoPermutation(pattern, pos); - assert.equal(actual, expected); - pos += 1; - } - assert.equal(nextTypoPermutation(pattern, pos), undefined); - } - - assertTypos('abc', 'acb'); - assertTypos('foboar', 'fbooar', 'foobar', 'fobaor', 'fobora'); - }); });