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


TypeScript cursorMoveHelper.CursorMoveHelper類代碼示例

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


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

示例1: shiftIndentCount

	public static shiftIndentCount(line:string, column:number, tabSize:number): number {
		// Determine the visible column where the content starts
		var contentStartVisibleColumn = CursorMoveHelper.visibleColumnFromColumn2(line, column, tabSize);

		var desiredTabStop = CursorMoveHelper.nextTabColumn(contentStartVisibleColumn, tabSize);

		// The `desiredTabStop` is a multiple of `tabSize` => determine the number of indents
		return desiredTabStop / tabSize;
	}
開發者ID:CPoirot3,項目名稱:vscode,代碼行數:9,代碼來源:shiftCommand.ts

示例2: getEditOperations

	public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
		let startLine = this._selection.startLineNumber,
			endLine = this._selection.endLineNumber,
			_SPACE = ' '.charCodeAt(0);

		if (this._selection.endColumn === 1 && startLine !== endLine) {
			endLine = endLine - 1;
		}

		let lineNumber:number,
			tabSize = this._opts.tabSize,
			oneIndent = this._opts.oneIndent,
			shouldIndentEmptyLines = (startLine === endLine);

		// indents[i] represents i * oneIndent
		let indents: string[] = ['', oneIndent];

		// if indenting or outdenting on a whitespace only line
		if (this._selection.isEmpty()) {
			if (/^\s*$/.test(model.getLineContent(startLine))) {
				this._useLastEditRangeForCursorEndPosition = true;
			}
		}

		// keep track of previous line's "miss-alignment"
		let previousLineExtraSpaces = 0, extraSpaces = 0;
		for (lineNumber = startLine; lineNumber <= endLine; lineNumber++, previousLineExtraSpaces = extraSpaces) {
			extraSpaces = 0;
			let lineText = model.getLineContent(lineNumber);
			let indentationEndIndex = strings.firstNonWhitespaceIndex(lineText);

			if (this._opts.isUnshift && (lineText.length === 0 || indentationEndIndex === 0)) {
				// empty line or line with no leading whitespace => nothing to do
				continue;
			}

			if (!shouldIndentEmptyLines && !this._opts.isUnshift && lineText.length === 0) {
				// do not indent empty lines => nothing to do
				continue;
			}

			if (indentationEndIndex === -1) {
				// the entire line is whitespace
				indentationEndIndex = lineText.length;
			}

			if (lineNumber > 1) {
				let contentStartVisibleColumn = CursorMoveHelper.visibleColumnFromColumn2(lineText, indentationEndIndex + 1, tabSize);
				if (contentStartVisibleColumn % tabSize !== 0) {
					// The current line is "miss-aligned", so let's see if this is expected...
					// This can only happen when it has trailing commas in the indent
					let enterAction = getRawEnterActionAtPosition(model, lineNumber - 1, model.getLineMaxColumn(lineNumber - 1));
					if (enterAction) {
						extraSpaces = previousLineExtraSpaces;
						if (enterAction.appendText) {
							for (let j = 0, lenJ = enterAction.appendText.length; j < lenJ && extraSpaces < tabSize; j++) {
								if (enterAction.appendText.charCodeAt(j) === _SPACE) {
									extraSpaces++;
								} else {
									break;
								}
							}
						}
						if (enterAction.removeText) {
							extraSpaces = Math.max(0, extraSpaces - enterAction.removeText);
						}

						// Act as if `prefixSpaces` is not part of the indentation
						for (let j = 0; j < extraSpaces; j++) {
							if (indentationEndIndex === 0 || lineText.charCodeAt(indentationEndIndex - 1) !== _SPACE) {
								break;
							}
							indentationEndIndex--;
						}
					}
				}
			}


			if (this._opts.isUnshift && indentationEndIndex === 0) {
				// line with no leading whitespace => nothing to do
				continue;
			}

			let desiredIndentCount: number;
			if (this._opts.isUnshift) {
				desiredIndentCount = ShiftCommand.unshiftIndentCount(lineText, indentationEndIndex + 1, tabSize);
			} else {
				desiredIndentCount = ShiftCommand.shiftIndentCount(lineText, indentationEndIndex + 1, tabSize);
			}

			// Fill `indents`, as needed
			for (let j = indents.length; j <= desiredIndentCount; j++) {
				indents[j] = indents[j-1] + oneIndent;
			}

			builder.addEditOperation(new Range(lineNumber, 1, lineNumber, indentationEndIndex + 1), indents[desiredIndentCount]);
		}

		this._selectionId = builder.trackSelection(this._selection);
//.........這裏部分代碼省略.........
開發者ID:CPoirot3,項目名稱:vscode,代碼行數:101,代碼來源:shiftCommand.ts

示例3: testVisibleColumnFromColumn

		function testVisibleColumnFromColumn(text:string, tabSize:number, column:number, expected:number): void {
			let helper = new CursorMoveHelper(new CursorMoveConfiguration(tabSize, 13));
			let model = new OneLineModel(text);
			assert.equal(helper.visibleColumnFromColumn(model, 1, column), expected);
		}
開發者ID:wei772,項目名稱:vscode,代碼行數:5,代碼來源:cursorMoveHelper.test.ts

示例4: getColumnAtEndOfViewLine

	public getColumnAtEndOfViewLine(lineNumber: number, column: number): number {
		return CursorMoveHelper.getColumnAtEndOfLine(this.viewModel, lineNumber, column);
	}
開發者ID:rebornix,項目名稱:vscode,代碼行數:3,代碼來源:oneCursor.ts

示例5: test

	test('nextTabStop', () => {
		assert.equal(CursorMoveHelper.nextTabColumn(0, 4), 4);
		assert.equal(CursorMoveHelper.nextTabColumn(1, 4), 4);
		assert.equal(CursorMoveHelper.nextTabColumn(2, 4), 4);
		assert.equal(CursorMoveHelper.nextTabColumn(3, 4), 4);
		assert.equal(CursorMoveHelper.nextTabColumn(4, 4), 8);
		assert.equal(CursorMoveHelper.nextTabColumn(5, 4), 8);
		assert.equal(CursorMoveHelper.nextTabColumn(6, 4), 8);
		assert.equal(CursorMoveHelper.nextTabColumn(7, 4), 8);
		assert.equal(CursorMoveHelper.nextTabColumn(8, 4), 12);

		assert.equal(CursorMoveHelper.nextTabColumn(0, 2), 2);
		assert.equal(CursorMoveHelper.nextTabColumn(1, 2), 2);
		assert.equal(CursorMoveHelper.nextTabColumn(2, 2), 4);
		assert.equal(CursorMoveHelper.nextTabColumn(3, 2), 4);
		assert.equal(CursorMoveHelper.nextTabColumn(4, 2), 6);
		assert.equal(CursorMoveHelper.nextTabColumn(5, 2), 6);
		assert.equal(CursorMoveHelper.nextTabColumn(6, 2), 8);
		assert.equal(CursorMoveHelper.nextTabColumn(7, 2), 8);
		assert.equal(CursorMoveHelper.nextTabColumn(8, 2), 10);

		assert.equal(CursorMoveHelper.nextTabColumn(0, 1), 1);
		assert.equal(CursorMoveHelper.nextTabColumn(1, 1), 2);
		assert.equal(CursorMoveHelper.nextTabColumn(2, 1), 3);
		assert.equal(CursorMoveHelper.nextTabColumn(3, 1), 4);
		assert.equal(CursorMoveHelper.nextTabColumn(4, 1), 5);
		assert.equal(CursorMoveHelper.nextTabColumn(5, 1), 6);
		assert.equal(CursorMoveHelper.nextTabColumn(6, 1), 7);
		assert.equal(CursorMoveHelper.nextTabColumn(7, 1), 8);
		assert.equal(CursorMoveHelper.nextTabColumn(8, 1), 9);
	});
開發者ID:wei772,項目名稱:vscode,代碼行數:31,代碼來源:cursorMoveHelper.test.ts


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