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


TypeScript ITokenizedModel.getLineCount方法代碼示例

本文整理匯總了TypeScript中vs/editor/common/editorCommon.ITokenizedModel.getLineCount方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ITokenizedModel.getLineCount方法的具體用法?TypeScript ITokenizedModel.getLineCount怎麽用?TypeScript ITokenizedModel.getLineCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vs/editor/common/editorCommon.ITokenizedModel的用法示例。


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

示例1: getIndentationEditOperations

function getIndentationEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder, tabSize: number, tabsToSpaces: boolean): void {
	if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) {
		// Model is empty
		return;
	}

	let spaces = '';
	for (let i = 0; i < tabSize; i++) {
		spaces += ' ';
	}

	const content = model.getLinesContent();
	for (let i = 0; i < content.length; i++) {
		let lastIndentationColumn = model.getLineFirstNonWhitespaceColumn(i + 1);
		if (lastIndentationColumn === 0) {
			lastIndentationColumn = model.getLineMaxColumn(i + 1);
		}

		const text = (tabsToSpaces ? content[i].substr(0, lastIndentationColumn).replace(/\t/ig, spaces) :
			content[i].substr(0, lastIndentationColumn).replace(new RegExp(spaces, 'gi'), '\t')) +
			content[i].substr(lastIndentationColumn);

		builder.addEditOperation(new Range(i + 1, 1, i + 1, model.getLineMaxColumn(i + 1)), text);
	}
}
開發者ID:1Hgm,項目名稱:vscode,代碼行數:25,代碼來源:indentationCommands.ts

示例2: matchEnterRule

	private matchEnterRule(model: ITokenizedModel, indentConverter: IIndentConverter, tabSize: number, line: number, oneLineAbove: number, oneLineAboveText?: string) {
		let validPrecedingLine = oneLineAbove;
		while (validPrecedingLine >= 1) {
			// ship empty lines as empty lines just inherit indentation
			let lineContent;
			if (validPrecedingLine === oneLineAbove && oneLineAboveText !== undefined) {
				lineContent = oneLineAboveText;
			} else {
				lineContent = model.getLineContent(validPrecedingLine);
			}

			let nonWhitespaceIdx = strings.lastNonWhitespaceIndex(lineContent);
			if (nonWhitespaceIdx >= 0) {
				break;
			}
			validPrecedingLine--;
		}

		if (validPrecedingLine < 1 || line > model.getLineCount()) {
			return null;
		}

		let maxColumn = model.getLineMaxColumn(validPrecedingLine);
		let enter = LanguageConfigurationRegistry.getEnterAction(model, new Range(validPrecedingLine, maxColumn, validPrecedingLine, maxColumn));

		if (enter) {
			let enterPrefix = enter.indentation;
			let enterAction = enter.enterAction;

			if (enterAction.indentAction === IndentAction.None) {
				enterPrefix = enter.indentation + enterAction.appendText;
			} else if (enterAction.indentAction === IndentAction.Indent) {
				enterPrefix = enter.indentation + enterAction.appendText;
			} else if (enterAction.indentAction === IndentAction.IndentOutdent) {
				enterPrefix = enter.indentation;
			} else if (enterAction.indentAction === IndentAction.Outdent) {
				enterPrefix = indentConverter.unshiftIndent(enter.indentation) + enterAction.appendText;
			}
			let movingLineText = model.getLineContent(line);
			if (this.trimLeft(movingLineText).indexOf(this.trimLeft(enterPrefix)) >= 0) {
				let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(line));
				let newIndentation = strings.getLeadingWhitespace(enterPrefix);
				let indentMetadataOfMovelingLine = LanguageConfigurationRegistry.getIndentMetadata(model, line);
				if (indentMetadataOfMovelingLine & IndentConsts.DECREASE_MASK) {
					newIndentation = indentConverter.unshiftIndent(newIndentation);
				}
				let newSpaceCnt = IndentUtil.getSpaceCnt(newIndentation, tabSize);
				let oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndentation, tabSize);
				return newSpaceCnt - oldSpaceCnt;
			}
		}

		return null;
	}
開發者ID:SeanKilleen,項目名稱:vscode,代碼行數:54,代碼來源:moveLinesCommand.ts

示例3: getEditOperations

	public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
		if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) {
			// Model is empty
			return;
		}

		var startLineNumber = this.startLineNumber;
		var endLineNumber = this.endLineNumber;

		var startColumn = 1;
		var endColumn = model.getLineMaxColumn(endLineNumber);
		if (endLineNumber < model.getLineCount()) {
			endLineNumber += 1;
			endColumn = 1;
		} else if (startLineNumber > 1) {
			startLineNumber -= 1;
			startColumn = model.getLineMaxColumn(startLineNumber);
		}

		builder.addTrackedEditOperation(new Range(startLineNumber, startColumn, endLineNumber, endColumn), null);
	}
開發者ID:AlexxNica,項目名稱:sqlopsstudio,代碼行數:21,代碼來源:deleteLinesCommand.ts

示例4: getEditOperations

	public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {

		var modelLineCount = model.getLineCount();

		if (this._isMovingDown && this._selection.endLineNumber === modelLineCount) {
			return;
		}
		if (!this._isMovingDown && this._selection.startLineNumber === 1) {
			return;
		}

		this._moveEndPositionDown = false;
		var s = this._selection;

		if (s.startLineNumber < s.endLineNumber && s.endColumn === 1) {
			this._moveEndPositionDown = true;
			s = s.setEndPosition(s.endLineNumber - 1, model.getLineMaxColumn(s.endLineNumber - 1));
		}

		let tabSize = model.getOptions().tabSize;
		let insertSpaces = model.getOptions().insertSpaces;
		let indentConverter = this.buildIndentConverter(tabSize);
		let virtualModel = {
			getLineTokens: (lineNumber: number) => {
				return model.getLineTokens(lineNumber);
			},
			getLanguageIdentifier: () => {
				return model.getLanguageIdentifier();
			},
			getLanguageIdAtPosition: (lineNumber: number, column: number) => {
				return model.getLanguageIdAtPosition(lineNumber, column);
			},
			getLineContent: null
		};

		if (s.startLineNumber === s.endLineNumber && model.getLineMaxColumn(s.startLineNumber) === 1) {
			// Current line is empty
			var lineNumber = s.startLineNumber;
			var otherLineNumber = (this._isMovingDown ? lineNumber + 1 : lineNumber - 1);

			if (model.getLineMaxColumn(otherLineNumber) === 1) {
				// Other line number is empty too, so no editing is needed
				// Add a no-op to force running by the model
				builder.addEditOperation(new Range(1, 1, 1, 1), null);
			} else {
				// Type content from other line number on line number
				builder.addEditOperation(new Range(lineNumber, 1, lineNumber, 1), model.getLineContent(otherLineNumber));

				// Remove content from other line number
				builder.addEditOperation(new Range(otherLineNumber, 1, otherLineNumber, model.getLineMaxColumn(otherLineNumber)), null);
			}
			// Track selection at the other line number
			s = new Selection(otherLineNumber, 1, otherLineNumber, 1);

		} else {

			var movingLineNumber: number,
				movingLineText: string;

			if (this._isMovingDown) {
				movingLineNumber = s.endLineNumber + 1;
				movingLineText = model.getLineContent(movingLineNumber);
				// Delete line that needs to be moved
				builder.addEditOperation(new Range(movingLineNumber - 1, model.getLineMaxColumn(movingLineNumber - 1), movingLineNumber, model.getLineMaxColumn(movingLineNumber)), null);

				let insertingText = movingLineText;

				if (this.shouldAutoIndent(model, s)) {
					let movingLineMatchResult = this.matchEnterRule(model, indentConverter, tabSize, movingLineNumber, s.startLineNumber - 1);
					// if s.startLineNumber - 1 matches onEnter rule, we still honor that.
					if (movingLineMatchResult !== null) {
						let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(movingLineNumber));
						let newSpaceCnt = movingLineMatchResult + IndentUtil.getSpaceCnt(oldIndentation, tabSize);
						let newIndentation = IndentUtil.generateIndent(newSpaceCnt, tabSize, insertSpaces);
						insertingText = newIndentation + this.trimLeft(movingLineText);
					} else {
						// no enter rule matches, let's check indentatin rules then.
						virtualModel.getLineContent = (lineNumber: number) => {
							if (lineNumber === s.startLineNumber) {
								return model.getLineContent(movingLineNumber);
							} else {
								return model.getLineContent(lineNumber);
							}
						};
						let indentOfMovingLine = LanguageConfigurationRegistry.getGoodIndentForLine(virtualModel, model.getLanguageIdAtPosition(
							movingLineNumber, 1), s.startLineNumber, indentConverter);
						if (indentOfMovingLine !== null) {
							let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(movingLineNumber));
							let newSpaceCnt = IndentUtil.getSpaceCnt(indentOfMovingLine, tabSize);
							let oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndentation, tabSize);
							if (newSpaceCnt !== oldSpaceCnt) {
								let newIndentation = IndentUtil.generateIndent(newSpaceCnt, tabSize, insertSpaces);
								insertingText = newIndentation + this.trimLeft(movingLineText);
							}
						}
					}

					// add edit operations for moving line first to make sure it's executed after we make indentation change
					// to s.startLineNumber
					builder.addEditOperation(new Range(s.startLineNumber, 1, s.startLineNumber, 1), insertingText + '\n');
//.........這裏部分代碼省略.........
開發者ID:SeanKilleen,項目名稱:vscode,代碼行數:101,代碼來源:moveLinesCommand.ts

示例5: getEditOperations

	public getEditOperations(model:ITokenizedModel, builder:IEditOperationBuilder):void {

		var modelLineCount = model.getLineCount();

		if (this._isMovingDown && this._selection.endLineNumber === modelLineCount) {
			return;
		}
		if (!this._isMovingDown && this._selection.startLineNumber === 1) {
			return;
		}

		this._moveEndPositionDown = false;
		var s = this._selection;

		if (s.startLineNumber < s.endLineNumber && s.endColumn === 1) {
			this._moveEndPositionDown = true;
			s = s.setEndPosition(s.endLineNumber - 1, model.getLineMaxColumn(s.endLineNumber - 1));
		}

		if (s.startLineNumber === s.endLineNumber && model.getLineMaxColumn(s.startLineNumber) === 1) {
			// Current line is empty
			var lineNumber = s.startLineNumber;
			var otherLineNumber = (this._isMovingDown ? lineNumber + 1 : lineNumber - 1);

			if (model.getLineMaxColumn(otherLineNumber) === 1) {
				// Other line number is empty too, so no editing is needed
				// Add a no-op to force running by the model
				builder.addEditOperation(new Range(1, 1, 1, 1), null);
			} else {
				// Type content from other line number on line number
				builder.addEditOperation(new Range(lineNumber, 1, lineNumber, 1), model.getLineContent(otherLineNumber));

				// Remove content from other line number
				builder.addEditOperation(new Range(otherLineNumber, 1, otherLineNumber, model.getLineMaxColumn(otherLineNumber)), null);
			}
			// Track selection at the other line number
			s = Selection.createSelection(otherLineNumber, 1, otherLineNumber, 1);

		} else {

			var movingLineNumber: number,
				movingLineText: string;

			if (this._isMovingDown) {
				movingLineNumber = s.endLineNumber + 1;
				movingLineText = model.getLineContent(movingLineNumber);

				// Delete line that needs to be moved
				builder.addEditOperation(new Range(movingLineNumber - 1, model.getLineMaxColumn(movingLineNumber - 1), movingLineNumber, model.getLineMaxColumn(movingLineNumber)), null);

				// Insert line that needs to be moved before
				builder.addEditOperation(new Range(s.startLineNumber, 1, s.startLineNumber, 1), movingLineText + '\n');
			} else {
				movingLineNumber = s.startLineNumber - 1;
				movingLineText = model.getLineContent(movingLineNumber);

				// Delete line that needs to be moved
				builder.addEditOperation(new Range(movingLineNumber, 1, movingLineNumber + 1, 1), null);

				// Insert line that needs to be moved after
				builder.addEditOperation(new Range(s.endLineNumber, model.getLineMaxColumn(s.endLineNumber), s.endLineNumber, model.getLineMaxColumn(s.endLineNumber)), '\n' + movingLineText);
			}
		}

		this._selectionId = builder.trackSelection(s);
	}
開發者ID:CPoirot3,項目名稱:vscode,代碼行數:66,代碼來源:moveLinesCommand.ts

示例6: joinLines

	public static joinLines(config: CursorConfiguration, model: ITokenizedModel, cursor: SingleCursorState): EditOperationResult {
		let selection = cursor.selection;
		let position = cursor.position;
		let startLineNumber: number,
			startColumn: number,
			endLineNumber: number,
			endColumn: number,
			columnDeltaOffset;

		if (selection.isEmpty() || selection.startLineNumber === selection.endLineNumber) {
			if (position.lineNumber < model.getLineCount()) {
				startLineNumber = position.lineNumber;
				startColumn = 1;
				endLineNumber = startLineNumber + 1;
				endColumn = model.getLineMaxColumn(endLineNumber);
			} else {
				startLineNumber = position.lineNumber;
				startColumn = 1;
				endLineNumber = position.lineNumber;
				endColumn = model.getLineMaxColumn(position.lineNumber);
			}
		} else {
			startLineNumber = selection.startLineNumber;
			startColumn = 1;
			endLineNumber = selection.endLineNumber;
			endColumn = model.getLineMaxColumn(endLineNumber);
		}

		let trimmedLinesContent = model.getLineContent(startLineNumber);

		for (let i = startLineNumber + 1; i <= endLineNumber; i++) {
			let lineText = model.getLineContent(i);
			let firstNonWhitespaceIdx = strings.firstNonWhitespaceIndex(lineText);

			if (firstNonWhitespaceIdx >= 0) {
				let insertSpace = true;

				if (trimmedLinesContent === '' || trimmedLinesContent.charAt(trimmedLinesContent.length - 1) === ' ') {
					insertSpace = false;
				}

				let lineTextWithoutIndent = lineText.substr(firstNonWhitespaceIdx);

				if (lineTextWithoutIndent.charAt(0) === ')') {
					insertSpace = false;
				}

				trimmedLinesContent += (insertSpace ? ' ' : '') + lineTextWithoutIndent;

				if (insertSpace) {
					columnDeltaOffset = lineTextWithoutIndent.length + 1;
				} else {
					columnDeltaOffset = lineTextWithoutIndent.length;
				}
			} else {
				columnDeltaOffset = 0;
			}
		}

		let deleteSelection = new Range(
			startLineNumber,
			startColumn,
			endLineNumber,
			endColumn
		);

		if (!deleteSelection.isEmpty()) {
			if (!selection.isEmpty() && selection.startLineNumber === selection.endLineNumber) {
				return new EditOperationResult(new ReplaceCommandThatPreservesSelection(deleteSelection, trimmedLinesContent, selection), {
					shouldPushStackElementBefore: false,
					shouldPushStackElementAfter: false
				});
			} else {
				return new EditOperationResult(new ReplaceCommandWithOffsetCursorState(deleteSelection, trimmedLinesContent, 0, -columnDeltaOffset), {
					shouldPushStackElementBefore: false,
					shouldPushStackElementAfter: false
				});
			}
		}

		return null;
	}
開發者ID:rebornix,項目名稱:vscode,代碼行數:82,代碼來源:cursorTypeOperations.ts


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