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


TypeScript IEditOperationBuilder.trackSelection方法代码示例

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


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

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

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

示例3: getEditOperations


//.........这里部分代码省略.........
						};
						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');

					let ret = this.matchEnterRule(model, indentConverter, tabSize, s.startLineNumber, s.startLineNumber, insertingText);
					// check if the line being moved before matches onEnter rules, if so let's adjust the indentation by onEnter rules.
					if (ret !== null) {
						if (ret !== 0) {
							this.getIndentEditsOfMovingBlock(model, builder, s, tabSize, insertSpaces, ret);
						}
					} else {
						// it doesn't match onEnter rules, let's check indentation rules then.
						virtualModel.getLineContent = (lineNumber: number) => {
							if (lineNumber === s.startLineNumber) {
								return insertingText;
							} else if (lineNumber >= s.startLineNumber + 1 && lineNumber <= s.endLineNumber + 1) {
								return model.getLineContent(lineNumber - 1);
							} else {
								return model.getLineContent(lineNumber);
							}
						};

						let newIndentatOfMovingBlock = LanguageConfigurationRegistry.getGoodIndentForLine(virtualModel, model.getLanguageIdAtPosition(
							movingLineNumber, 1), s.startLineNumber + 1, indentConverter);

						if (newIndentatOfMovingBlock !== null) {
							const oldIndentation = strings.getLeadingWhitespace(model.getLineContent(s.startLineNumber));
							const newSpaceCnt = IndentUtil.getSpaceCnt(newIndentatOfMovingBlock, tabSize);
							const oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndentation, tabSize);
							if (newSpaceCnt !== oldSpaceCnt) {
								const spaceCntOffset = newSpaceCnt - oldSpaceCnt;

								this.getIndentEditsOfMovingBlock(model, builder, s, tabSize, insertSpaces, spaceCntOffset);
							}
						}
					}
				} else {
					// Insert line that needs to be moved before
					builder.addEditOperation(new Range(s.startLineNumber, 1, s.startLineNumber, 1), insertingText + '\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);

				if (this.shouldAutoIndent(model, s)) {
					virtualModel.getLineContent = (lineNumber: number) => {
						if (lineNumber === movingLineNumber) {
							return model.getLineContent(s.startLineNumber);
						} else {
							return model.getLineContent(lineNumber);
						}
					};

					let ret = this.matchEnterRule(model, indentConverter, tabSize, s.startLineNumber, s.startLineNumber - 2);
					// check if s.startLineNumber - 2 matches onEnter rules, if so adjust the moving block by onEnter rules.
					if (ret !== null) {
						if (ret !== 0) {
							this.getIndentEditsOfMovingBlock(model, builder, s, tabSize, insertSpaces, ret);
						}
					} else {
						// it doesn't match any onEnter rule, let's check indentation rules then.
						let indentOfFirstLine = LanguageConfigurationRegistry.getGoodIndentForLine(virtualModel, model.getLanguageIdAtPosition(s.startLineNumber, 1), movingLineNumber, indentConverter);
						if (indentOfFirstLine !== null) {
							// adjust the indentation of the moving block
							let oldIndent = strings.getLeadingWhitespace(model.getLineContent(s.startLineNumber));
							let newSpaceCnt = IndentUtil.getSpaceCnt(indentOfFirstLine, tabSize);
							let oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndent, tabSize);
							if (newSpaceCnt !== oldSpaceCnt) {
								let spaceCntOffset = newSpaceCnt - oldSpaceCnt;

								this.getIndentEditsOfMovingBlock(model, builder, s, tabSize, insertSpaces, spaceCntOffset);
							}
						}
					}
				}
			}
		}

		this._selectionId = builder.trackSelection(s);
	}
开发者ID:SeanKilleen,项目名称:vscode,代码行数:101,代码来源:moveLinesCommand.ts

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

示例5: getEditOperations

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

示例6: getEditOperations

	public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
		this.selectionId = builder.trackSelection(this.selection);
		getIndentationEditOperations(model, builder, this.tabSize, false);
	}
开发者ID:huiyuewidows10,项目名称:vscode,代码行数:4,代码来源:indentationCommands.ts

示例7: getEditOperations


//.........这里部分代码省略.........
						if (model.isCheapToTokenize(lineNumber - 1)) {
							let enterAction = LanguageConfigurationRegistry.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 < indentSize; j++) {
										if (enterAction.appendText.charCodeAt(j) === CharCode.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) !== CharCode.Space) {
										break;
									}
									indentationEndIndex--;
								}
							}
						}
					}
				}


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

				let desiredIndent: string;
				if (this._opts.isUnshift) {
					desiredIndent = ShiftCommand.unshiftIndent(lineText, indentationEndIndex + 1, tabSize, indentSize, insertSpaces);
				} else {
					desiredIndent = ShiftCommand.shiftIndent(lineText, indentationEndIndex + 1, tabSize, indentSize, insertSpaces);
				}

				this._addEditOperation(builder, new Range(lineNumber, 1, lineNumber, indentationEndIndex + 1), desiredIndent);
				if (lineNumber === startLine) {
					// Force the startColumn to stay put because we're inserting after it
					this._selectionStartColumnStaysPut = (this._selection.startColumn <= indentationEndIndex + 1);
				}
			}
		} else {

			const oneIndent = (insertSpaces ? cachedStringRepeat(' ', indentSize) : '\t');

			for (let lineNumber = startLine; lineNumber <= endLine; lineNumber++) {
				const 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 (this._opts.isUnshift && indentationEndIndex === 0) {
					// line with no leading whitespace => nothing to do
					continue;
				}

				if (this._opts.isUnshift) {

					indentationEndIndex = Math.min(indentationEndIndex, indentSize);
					for (let i = 0; i < indentationEndIndex; i++) {
						const chr = lineText.charCodeAt(i);
						if (chr === CharCode.Tab) {
							indentationEndIndex = i + 1;
							break;
						}
					}

					this._addEditOperation(builder, new Range(lineNumber, 1, lineNumber, indentationEndIndex + 1), '');
				} else {
					this._addEditOperation(builder, new Range(lineNumber, 1, lineNumber, 1), oneIndent);
					if (lineNumber === startLine) {
						// Force the startColumn to stay put because we're inserting after it
						this._selectionStartColumnStaysPut = (this._selection.startColumn === 1);
					}
				}
			}
		}

		this._selectionId = builder.trackSelection(this._selection);
	}
开发者ID:PKRoma,项目名称:vscode,代码行数:101,代码来源:shiftCommand.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));
		}

		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


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