当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript editorCommon.IEditOperationBuilder类代码示例

本文整理汇总了TypeScript中vs/editor/common/editorCommon.IEditOperationBuilder的典型用法代码示例。如果您正苦于以下问题:TypeScript IEditOperationBuilder类的具体用法?TypeScript IEditOperationBuilder怎么用?TypeScript IEditOperationBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IEditOperationBuilder类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: _addEditOperation

	private _addEditOperation(builder: IEditOperationBuilder, range: Range, text: string) {
		if (this._useLastEditRangeForCursorEndPosition) {
			builder.addTrackedEditOperation(range, text);
		} else {
			builder.addEditOperation(range, text);
		}
	}
开发者ID:SeanKilleen,项目名称:vscode,代码行数:7,代码来源:shiftCommand.ts

示例2: getEditOperations

	public getEditOperations(model: ITextModel, builder: IEditOperationBuilder): void {
		let ops = trimTrailingWhitespace(model, this.cursors);
		for (let i = 0, len = ops.length; i < len; i++) {
			let op = ops[i];

			builder.addEditOperation(op.range, op.text);
		}

		this.selectionId = builder.trackSelection(this.selection);
	}
开发者ID:PKRoma,项目名称:vscode,代码行数:10,代码来源:trimTrailingWhitespaceCommand.ts

示例3: getEditOperations

	public getEditOperations(model: ITextModel, builder: IEditOperationBuilder): void {
		builder.addTrackedEditOperation(new Range(
			this._range.startLineNumber,
			this._range.startColumn,
			this._range.startLineNumber,
			this._range.startColumn
		), this._charBeforeSelection);

		builder.addTrackedEditOperation(new Range(
			this._range.endLineNumber,
			this._range.endColumn,
			this._range.endLineNumber,
			this._range.endColumn
		), this._charAfterSelection);
	}
开发者ID:PKRoma,项目名称:vscode,代码行数:15,代码来源:surroundSelectionCommand.ts

示例4: 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

示例5: getEditOperations

	public getEditOperations(model: ITextModel, builder: IEditOperationBuilder): void {
		var s = this._selection;
		this._selectionId = builder.trackSelection(s);
		if (s.startLineNumber !== s.endLineNumber) {
			return;
		}
		if (this._isMovingLeft && s.startColumn === 0) {
			return;
		} else if (!this._isMovingLeft && s.endColumn === model.getLineMaxColumn(s.startLineNumber)) {
			return;
		}

		var lineNumber = s.selectionStartLineNumber;
		var lineContent = model.getLineContent(lineNumber);

		var left;
		var middle;
		var right;

		if (this._isMovingLeft) {
			left = lineContent.substring(0, s.startColumn - 2);
			middle = lineContent.substring(s.startColumn - 1, s.endColumn - 1);
			right = lineContent.substring(s.startColumn - 2, s.startColumn - 1) + lineContent.substring(s.endColumn - 1);
		} else {
			left = lineContent.substring(0, s.startColumn - 1) + lineContent.substring(s.endColumn - 1, s.endColumn);
			middle = lineContent.substring(s.startColumn - 1, s.endColumn - 1);
			right = lineContent.substring(s.endColumn);
		}

		var newLineContent = left + middle + right;

		builder.addEditOperation(new Range(lineNumber, 1, lineNumber, model.getLineMaxColumn(lineNumber)), null);
		builder.addEditOperation(new Range(lineNumber, 1, lineNumber, 1), newLineContent);

		this._cutStartIndex = s.startColumn + (this._isMovingLeft ? -1 : 1);
		this._cutEndIndex = this._cutStartIndex + s.endColumn - s.startColumn;
		this._moved = true;
	}
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:38,代码来源:moveCaretCommand.ts

示例6: getIndentEditsOfMovingBlock

	private getIndentEditsOfMovingBlock(model: ITokenizedModel, builder: IEditOperationBuilder, s: Selection, tabSize: number, insertSpaces: boolean, offset: number) {
		for (let i = s.startLineNumber; i <= s.endLineNumber; i++) {
			let lineContent = model.getLineContent(i);
			let originalIndent = strings.getLeadingWhitespace(lineContent);
			let originalSpacesCnt = IndentUtil.getSpaceCnt(originalIndent, tabSize);
			let newSpacesCnt = originalSpacesCnt + offset;
			let newIndent = IndentUtil.generateIndent(newSpacesCnt, tabSize, insertSpaces);

			if (newIndent !== originalIndent) {
				builder.addEditOperation(new Range(i, 1, i, originalIndent.length + 1), newIndent);

				if (i === s.endLineNumber && s.endColumn <= originalIndent.length + 1 && newIndent === '') {
					// as users select part of the original indent white spaces
					// when we adjust the indentation of endLine, we should adjust the cursor position as well.
					this._moveEndLineSelectionShrink = true;
				}
			}

		}
	}
开发者ID:SeanKilleen,项目名称:vscode,代码行数:20,代码来源:moveLinesCommand.ts

示例7: getEditOperations

	public getEditOperations(model: ITextModel, 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:JarnoNijboer,项目名称:vscode,代码行数:21,代码来源:deleteLinesCommand.ts

示例8: 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

示例9: 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

示例10: getEditOperations

	public getEditOperations(model: ITextModel, builder: IEditOperationBuilder): void {
		builder.addTrackedEditOperation(this._range, this._text);
	}
开发者ID:KTXSoftware,项目名称:KodeStudio,代码行数:3,代码来源:replaceCommand.ts


注:本文中的vs/editor/common/editorCommon.IEditOperationBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。