當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript whitespaceComputer.WhitespaceComputer類代碼示例

本文整理匯總了TypeScript中vs/editor/common/viewLayout/whitespaceComputer.WhitespaceComputer的典型用法代碼示例。如果您正苦於以下問題:TypeScript WhitespaceComputer類的具體用法?TypeScript WhitespaceComputer怎麽用?TypeScript WhitespaceComputer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了WhitespaceComputer類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test

	test('WhitespaceComputer changeWhitespaceAfterLineNumber & getFirstWhitespaceIndexAfterLineNumber', () => {
		var whitespaceComputer = new WhitespaceComputer();

		var a = whitespaceComputer.insertWhitespace(0, 0, 1);
		var b = whitespaceComputer.insertWhitespace(7, 0, 1);
		var c = whitespaceComputer.insertWhitespace(3, 0, 1);

		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(0), a); // 0
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(0), 0);
		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(1), c); // 3
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(1), 3);
		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(2), b); // 7
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(2), 7);

		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(1), 1); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(2), 1); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(3), 1); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(4), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(5), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(6), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(7), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(8), -1); // --

		// Do not really move a
		whitespaceComputer.changeWhitespaceAfterLineNumber(a, 1);

		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(0), a); // 1
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(0), 1);
		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(1), c); // 3
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(1), 3);
		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(2), b); // 7
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(2), 7);

		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(1), 0); // a
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(2), 1); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(3), 1); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(4), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(5), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(6), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(7), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(8), -1); // --


		// Do not really move a
		whitespaceComputer.changeWhitespaceAfterLineNumber(a, 2);

		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(0), a); // 2
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(0), 2);
		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(1), c); // 3
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(1), 3);
		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(2), b); // 7
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(2), 7);

		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(1), 0); // a
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(2), 0); // a
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(3), 1); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(4), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(5), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(6), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(7), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(8), -1); // --


		// Change a to conflict with c => a gets placed after c
		whitespaceComputer.changeWhitespaceAfterLineNumber(a, 3);

		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(0), c); // 3
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(0), 3);
		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(1), a); // 3
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(1), 3);
		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(2), b); // 7
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(2), 7);

		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(1), 0); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(2), 0); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(3), 0); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(4), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(5), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(6), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(7), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(8), -1); // --


		// Make a no-op
		whitespaceComputer.changeWhitespaceAfterLineNumber(c, 3);

		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(0), c); // 3
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(0), 3);
		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(1), a); // 3
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(1), 3);
		assert.equal(whitespaceComputer.getIdForWhitespaceIndex(2), b); // 7
		assert.equal(whitespaceComputer.getAfterLineNumberForWhitespaceIndex(2), 7);

		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(1), 0); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(2), 0); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(3), 0); // c
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(4), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(5), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(6), 2); // b
		assert.equal(whitespaceComputer.getFirstWhitespaceIndexAfterLineNumber(7), 2); // b
//.........這裏部分代碼省略.........
開發者ID:StateFarmIns,項目名稱:vscode,代碼行數:101,代碼來源:whitespaceComputer.test.ts

示例2: getVerticalOffsetForLineNumber

	/**
	 * Get the vertical offset (the sum of heights for all objects above) a certain line number.
	 *
	 * @param lineNumber The line number
	 * @param deviceLineHeight The height, in pixels, for one rendered line.
	 * @return The sum of heights for all objects above `lineNumber`.
	 */
	public getVerticalOffsetForLineNumber(lineNumber:number, deviceLineHeight:number): number {

		var previousLinesHeight:number;
		if (lineNumber > 1) {
			previousLinesHeight = deviceLineHeight * (lineNumber - 1);
		} else {
			previousLinesHeight = 0;
		}

		var previousWhitespacesHeight = this.whitespaces.getAccumulatedHeightBeforeLineNumber(lineNumber);

		return previousLinesHeight + previousWhitespacesHeight;
	}
開發者ID:ErickWendel,項目名稱:vscode,代碼行數:20,代碼來源:verticalObjects.ts

示例3: getWhitespaceIndexAtOrAfterVerticallOffset

	public getWhitespaceIndexAtOrAfterVerticallOffset(verticalOffset: number): number {
		verticalOffset = verticalOffset | 0;

		let midWhitespaceIndex: number,
			minWhitespaceIndex = 0,
			maxWhitespaceIndex = this._whitespaces.getCount() - 1,
			midWhitespaceVerticalOffset: number,
			midWhitespaceHeight: number;

		if (maxWhitespaceIndex < 0) {
			return -1;
		}

		// Special case: nothing to be found
		let maxWhitespaceVerticalOffset = this.getVerticalOffsetForWhitespaceIndex(maxWhitespaceIndex);
		let maxWhitespaceHeight = this._whitespaces.getHeightForWhitespaceIndex(maxWhitespaceIndex);
		if (verticalOffset >= maxWhitespaceVerticalOffset + maxWhitespaceHeight) {
			return -1;
		}

		while (minWhitespaceIndex < maxWhitespaceIndex) {
			midWhitespaceIndex = Math.floor((minWhitespaceIndex + maxWhitespaceIndex) / 2);

			midWhitespaceVerticalOffset = this.getVerticalOffsetForWhitespaceIndex(midWhitespaceIndex);
			midWhitespaceHeight = this._whitespaces.getHeightForWhitespaceIndex(midWhitespaceIndex);

			if (verticalOffset >= midWhitespaceVerticalOffset + midWhitespaceHeight) {
				// vertical offset is after whitespace
				minWhitespaceIndex = midWhitespaceIndex + 1;
			} else if (verticalOffset >= midWhitespaceVerticalOffset) {
				// Hit
				return midWhitespaceIndex;
			} else {
				// vertical offset is before whitespace, but midWhitespaceIndex might still be what we're searching for
				maxWhitespaceIndex = midWhitespaceIndex;
			}
		}
		return minWhitespaceIndex;
	}
開發者ID:AlexxNica,項目名稱:sqlopsstudio,代碼行數:39,代碼來源:linesLayout.ts

示例4: getVerticalOffsetForLineNumber

	/**
	 * Get the vertical offset (the sum of heights for all objects above) a certain line number.
	 *
	 * @param lineNumber The line number
	 * @return The sum of heights for all objects above `lineNumber`.
	 */
	public getVerticalOffsetForLineNumber(lineNumber: number): number {
		lineNumber = lineNumber | 0;

		let previousLinesHeight: number;
		if (lineNumber > 1) {
			previousLinesHeight = this._lineHeight * (lineNumber - 1);
		} else {
			previousLinesHeight = 0;
		}

		let previousWhitespacesHeight = this._whitespaces.getAccumulatedHeightBeforeLineNumber(lineNumber);

		return previousLinesHeight + previousWhitespacesHeight;
	}
開發者ID:diarmaidm,項目名稱:vscode,代碼行數:20,代碼來源:linesLayout.ts

示例5: getLinesViewportData

	/**
	 * Get all the lines and their relative vertical offsets that are positioned between `verticalOffset1` and `verticalOffset2`.
	 *
	 * @param verticalOffset1 The beginning of the viewport.
	 * @param verticalOffset2 The end of the viewport.
	 * @param deviceLineHeight The height, in pixels, for one rendered line.
	 * @return A structure describing the lines positioned between `verticalOffset1` and `verticalOffset2`.
	 */
	public getLinesViewportData(verticalOffset1:number, verticalOffset2:number, deviceLineHeight:number): IViewLinesViewportData {
		// Find first line number
		// We don't live in a perfect world, so the line number might start before or after verticalOffset1
		var startLineNumber = this.getLineNumberAtOrAfterVerticalOffset(verticalOffset1, deviceLineHeight);

		var endLineNumber = this.linesCount,
			startLineNumberVerticalOffset = this.getVerticalOffsetForLineNumber(startLineNumber, deviceLineHeight);

		// Also keep track of what whitespace we've got
		var whitespaceIndex = this.whitespaces.getFirstWhitespaceIndexAfterLineNumber(startLineNumber),
			whitespaceCount = this.whitespaces.getCount(),
			currentWhitespaceHeight: number,
			currentWhitespaceAfterLineNumber: number;

		if (whitespaceIndex === -1) {
			whitespaceIndex = whitespaceCount;
			currentWhitespaceAfterLineNumber = endLineNumber + 1;
		} else {
			currentWhitespaceAfterLineNumber = this.whitespaces.getAfterLineNumberForWhitespaceIndex(whitespaceIndex);
			currentWhitespaceHeight = this.whitespaces.getHeightForWhitespaceIndex(whitespaceIndex);
		}

		var currentVerticalOffset = startLineNumberVerticalOffset;
		var currentLineRelativeOffset = currentVerticalOffset;

		// IE (all versions) cannot handle units above about 1,533,908 px, so every 500k pixels bring numbers down
		var STEP_SIZE = 500000;
		var bigNumbersDelta = 0;
		if (startLineNumberVerticalOffset >= STEP_SIZE) {
			// Compute a delta that guarantees that lines are positioned at `lineHeight` increments
			bigNumbersDelta = Math.floor(startLineNumberVerticalOffset / STEP_SIZE) * STEP_SIZE;
			bigNumbersDelta = Math.floor(bigNumbersDelta / deviceLineHeight) * deviceLineHeight;

			currentLineRelativeOffset -= bigNumbersDelta;
		}

		var linesOffsets:number[] = [];

		// Figure out how far the lines go
		for (var lineNumber = startLineNumber; lineNumber <= endLineNumber; lineNumber++) {

			// Count current line height in the vertical offsets
			currentVerticalOffset += deviceLineHeight;
			linesOffsets.push(currentLineRelativeOffset);

			// Next line starts immediately after this one
			currentLineRelativeOffset += deviceLineHeight;
			while (currentWhitespaceAfterLineNumber === lineNumber) {
				// Push down next line with the height of the current whitespace
				currentLineRelativeOffset += currentWhitespaceHeight;

				// Count current whitespace in the vertical offsets
				currentVerticalOffset += currentWhitespaceHeight;
				whitespaceIndex++;

				if (whitespaceIndex >= whitespaceCount) {
					currentWhitespaceAfterLineNumber = endLineNumber + 1;
				} else {
					currentWhitespaceAfterLineNumber = this.whitespaces.getAfterLineNumberForWhitespaceIndex(whitespaceIndex);
					currentWhitespaceHeight = this.whitespaces.getHeightForWhitespaceIndex(whitespaceIndex);
				}
			}

			if (currentVerticalOffset > verticalOffset2) {
				// We have covered the entire viewport area, time to stop
				endLineNumber = lineNumber;
				break;
			}
		}

		return {
			viewportTop: verticalOffset1 - bigNumbersDelta,
			viewportHeight: verticalOffset2 - verticalOffset1,
			bigNumbersDelta: bigNumbersDelta,
			startLineNumber: startLineNumber,
			endLineNumber: endLineNumber,
			visibleRangesDeltaTop: -(verticalOffset1 - bigNumbersDelta),
			relativeVerticalOffset: linesOffsets,
			visibleRange: null, // This will be filled in by someone else :) (hint: viewLines)
			getInlineDecorationsForLineInViewport: null, // This will be filled in by linesLayout
			getDecorationsInViewport: null // This will be filled in by linesLayout
		};
	}
開發者ID:1424667164,項目名稱:vscode,代碼行數:91,代碼來源:verticalObjects.ts

示例6: hasWhitespace

	/**
	 * Returns if there is any whitespace in the document.
	 */
	public hasWhitespace(): boolean {
		return this.whitespaces.getCount() > 0;
	}
開發者ID:1424667164,項目名稱:vscode,代碼行數:6,代碼來源:verticalObjects.ts

示例7: removeWhitespace

	/**
	 * Remove an existing whitespace.
	 *
	 * @param id The whitespace to remove
	 * @return Returns true if the whitespace is found and it is removed.
	 */
	public removeWhitespace(id:number): boolean {
		return this.whitespaces.removeWhitespace(id);
	}
開發者ID:1424667164,項目名稱:vscode,代碼行數:9,代碼來源:verticalObjects.ts

示例8: changeWhitespace

	/**
	 * Change the height of an existing whitespace
	 *
	 * @param id The whitespace to change
	 * @param newHeightInPx The new height of the whitespace, in pixels
	 * @return Returns true if the whitespace is found and if the new height is different than the old height
	 */
	public changeWhitespace(id:number, newHeightInPx:number): boolean {
		return this.whitespaces.changeWhitespace(id, newHeightInPx);
	}
開發者ID:1424667164,項目名稱:vscode,代碼行數:10,代碼來源:verticalObjects.ts

示例9: getLinesTotalHeight

	/**
	 * Get the sum of heights for all objects.
	 *
	 * @return The sum of heights for all objects.
	 */
	public getLinesTotalHeight(): number {
		let linesHeight = this._lineHeight * this._lineCount;
		let whitespacesHeight = this._whitespaces.getTotalHeight();
		return linesHeight + whitespacesHeight;
	}
開發者ID:diarmaidm,項目名稱:vscode,代碼行數:10,代碼來源:linesLayout.ts


注:本文中的vs/editor/common/viewLayout/whitespaceComputer.WhitespaceComputer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。