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


TypeScript IModel.getLineCount方法代碼示例

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


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

示例1: applyChangesToModel

export function applyChangesToModel(original: IModel, modified: IModel, changes: IChange[]): string {
	sortChanges(changes);
	var result = '';
	var positionInOriginal = 1;

	for (var i = 0; i < changes.length; ++i) {
		// We have to update orginalStartLineNumber for insertions, their start line is always one line behind.
		var originalStartLineUpdated = isInsertion(changes[i]) ? changes[i].originalStartLineNumber + 1 : changes[i].originalStartLineNumber;
		if (positionInOriginal < originalStartLineUpdated) {
			result = appendValueFromRange(result, original,
				new Range(positionInOriginal, 1, originalStartLineUpdated - 1, original.getLineMaxColumn(originalStartLineUpdated - 1)));
			positionInOriginal = originalStartLineUpdated;
		}

		if (!isDeletion(changes[i])) {
			result = appendValueFromRange(result, modified,
				new Range(changes[i].modifiedStartLineNumber, 1, changes[i].modifiedEndLineNumber, modified.getLineMaxColumn(changes[i].modifiedEndLineNumber)));
		}
		// Update position in the original file where we continue to concatanate.
		// Only update position if it was not an insertion.
		if (!isInsertion(changes[i])) {
			positionInOriginal = changes[i].originalEndLineNumber + 1;
		}
	}

	// Append the last chunk after all the changes.
	if (positionInOriginal <= original.getLineCount()) {
		result = appendValueFromRange(result, original,
			new Range(positionInOriginal, 1, original.getLineCount(), original.getLineMaxColumn(original.getLineCount())));
	}

	return result;
}
開發者ID:diarmaidm,項目名稱:vscode,代碼行數:33,代碼來源:stageRanges.ts

示例2: _cursorMoveMessage

	private static _cursorMoveMessage(source: string, model: IModel, oldPosition: Position, newPosition: Position): string {

		if (source === 'moveWordCommand') {
			return model.getValueInRange(new Range(oldPosition.lineNumber, oldPosition.column, newPosition.lineNumber, newPosition.column));
		}

		const oldLineNumber = oldPosition.lineNumber;
		const oldColumn = oldPosition.column;
		const newLineNumber = newPosition.lineNumber;
		const newColumn = newPosition.column;

		// check going down via right arrow
		if (newLineNumber === oldLineNumber + 1 && newColumn === 1 && oldColumn === model.getLineMaxColumn(oldLineNumber)) {
			return this._cursorCharMessage(model, newPosition);
		}

		// check going up via up arrow
		if (newLineNumber === oldLineNumber - 1 && newColumn === model.getLineMaxColumn(newLineNumber) && oldColumn === 1) {
			return this._cursorCharMessage(model, newPosition);
		}

		const lineCount = model.getLineCount();
		if (oldLineNumber !== newLineNumber) {
			if (newLineNumber === lineCount) {
				// Last line does not have an EOL
				return model.getLineContent(newLineNumber);
			}
			return model.getLineContent(newLineNumber) + model.getEOL();
		}

		return this._cursorCharMessage(model, newPosition);
	}
開發者ID:FabianLauer,項目名稱:vscode,代碼行數:32,代碼來源:accGenerator.ts

示例3: _delete

	protected _delete(wordSeparators: WordCharacterClassifier, model: IModel, selection: Selection, whitespaceHeuristics: boolean, wordNavigationType: WordNavigationType): Range {
		let r = WordOperations.deleteWordRight(wordSeparators, model, selection, whitespaceHeuristics, wordNavigationType);
		if (r) {
			return r;
		}
		const lineCount = model.getLineCount();
		const maxColumn = model.getLineMaxColumn(lineCount);
		return new Range(lineCount, maxColumn, lineCount, maxColumn);
	}
開發者ID:Chan-PH,項目名稱:vscode,代碼行數:9,代碼來源:wordOperations.ts

示例4: getLinesRangeWithOneSurroundingNewline

function getLinesRangeWithOneSurroundingNewline(model: IModel, startLine: number, endLine: number): Range {
	let startColumn = 1;
	let endColumn = model.getLineMaxColumn(endLine);
	if (endLine < model.getLineCount()) {
		endLine++;
		endColumn = 1;
	} else if (startLine > 1) {
		startLine--;
		startColumn = model.getLineMaxColumn(startLine);
	}

	return new Range(startLine, startColumn, endLine, endColumn);
}
開發者ID:diarmaidm,項目名稱:vscode,代碼行數:13,代碼來源:stageRanges.ts

示例5: computeRanges

export function computeRanges(model: IModel, tabSize: number, minimumRangeSize: number = 1): IFoldingRange[] {

	let result: IFoldingRange[] = [];

	let previousRegions: { indent: number, line: number }[] = [];
	previousRegions.push({ indent: -1, line: model.getLineCount() + 1 }); // sentinel, to make sure there's at least one entry

	for (let line = model.getLineCount(); line > 0; line--) {
		let indent = computeIndentLevel(model.getLineContent(line), tabSize);
		if (indent === -1) {
			continue; // only whitespace
		}

		let previous = previousRegions[previousRegions.length - 1];

		if (previous.indent > indent) {
			// discard all regions with larger indent
			do {
				previousRegions.pop();
				previous = previousRegions[previousRegions.length - 1];
			} while (previous.indent > indent);

			// new folding range
			let endLineNumber = previous.line - 1;
			if (endLineNumber - line >= minimumRangeSize) {
				result.push({ startLineNumber: line, endLineNumber, indent: indent });
			}
		}
		if (previous.indent === indent) {
			previous.line = line;
		} else { // previous.indent < indent
			// new region with a bigger indent
			previousRegions.push({ indent, line });
		}
	}
	return result.reverse();
}
開發者ID:13572293130,項目名稱:vscode,代碼行數:37,代碼來源:indentFoldStrategy.ts

示例6: _cursorCharMessage

	private static _cursorCharMessage(model: IModel, position: Position): string {
		const lineNumber = position.lineNumber;
		const column = position.column;

		const maxLineColumn = model.getLineMaxColumn(lineNumber);
		if (column === maxLineColumn) {
			const lineCount = model.getLineCount();
			if (lineNumber === lineCount) {
				// At the end of the file
				return '';
			}
			return model.getEOL();
		}
		return model.getLineContent(lineNumber).charAt(column - 1);
	}
開發者ID:FabianLauer,項目名稱:vscode,代碼行數:15,代碼來源:accGenerator.ts

示例7: getDeleteOperation

	return changes.map((change, i) => {
		if (isInsertion(change)) {
			// Delete inserted range
			return getDeleteOperation(change);
		} else if (isDeletion(change)) {
			// Get the original lines and insert at the deleted position
			const value = original.getValueInRange(getLinesRangeWithOneSurroundingNewline(original, change.originalStartLineNumber, change.originalEndLineNumber));
			return EditOperation.insert(new Position(change.modifiedStartLineNumber + 1, 1), value);
		} else if (change.isCompletelySelected) {
			// If the entire change is selected, then revert the whole thing.
			const value = original.getValueInRange(new Range(change.originalStartLineNumber, 1, change.originalEndLineNumber + 1, 1));
			return EditOperation.replace(new Range(change.modifiedStartLineNumber, 1, change.modifiedEndLineNumber + 1, 1), value);
		} else {
			// If only a portion is selected, replace with the matching lines - e.g. if lines 2-4 are selected, replace with lines 2-4 from the original model (if they exist)
			const copyOffset = change.modifiedStartLineNumber - change.fullModifiedStartLineNumber;
			const numLinesToCopy = change.modifiedEndLineNumber - change.modifiedStartLineNumber;
			const copyStartLine = change.originalStartLineNumber + copyOffset;
			const copyEndLine = Math.min(copyStartLine + numLinesToCopy, original.getLineCount());
			if (copyStartLine > copyEndLine) {
				return getDeleteOperation(change);
			}

			// Compute the range to copy, and intersect with the full original range to validate
			const originalRange = new Range(change.originalStartLineNumber, 1, change.originalEndLineNumber, original.getLineMaxColumn(change.originalEndLineNumber));
			const rangeToCopy = originalRange.intersectRanges(
				new Range(copyStartLine, 1, copyEndLine, original.getLineMaxColumn(copyEndLine)));

			// No intersection, so delete the added text
			if (!rangeToCopy) {
				return getDeleteOperation(change);
			}

			const value = original.getValueInRange(rangeToCopy);
			return EditOperation.replace(new Range(change.modifiedStartLineNumber, 1, change.modifiedEndLineNumber, modified.getLineMaxColumn(change.modifiedEndLineNumber)), value);
		}
	});
開發者ID:diarmaidm,項目名稱:vscode,代碼行數:36,代碼來源:stageRanges.ts


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