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


TypeScript Range.fromPositions方法代碼示例

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


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

示例1: setup

	setup(function () {

		model = TextModel.createFromString('FOO\nbar\BAR\nfoo', undefined, undefined, URI.parse('foo:bar/path'));
		registration = CompletionProviderRegistry.register({ pattern: 'bar/path', scheme: 'foo' }, {
			provideCompletionItems(_doc, pos) {
				return {
					incomplete: false,
					suggestions: [{
						label: 'aaa',
						kind: CompletionItemKind.Snippet,
						insertText: 'aaa',
						range: Range.fromPositions(pos)
					}, {
						label: 'zzz',
						kind: CompletionItemKind.Snippet,
						insertText: 'zzz',
						range: Range.fromPositions(pos)
					}, {
						label: 'fff',
						kind: CompletionItemKind.Property,
						insertText: 'fff',
						range: Range.fromPositions(pos)
					}]
				};
			}
		});
	});
開發者ID:VishalMadhvani,項目名稱:vscode,代碼行數:27,代碼來源:suggest.test.ts

示例2: run

	public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
		if (!editor.hasModel()) {
			return;
		}

		let model = editor.getModel();
		let commands: ICommand[] = [];
		let selections = editor.getSelections();

		for (let selection of selections) {
			if (!selection.isEmpty()) {
				continue;
			}

			let lineNumber = selection.startLineNumber;
			let column = selection.startColumn;

			let lastColumn = model.getLineMaxColumn(lineNumber);

			if (lineNumber === 1 && (column === 1 || (column === 2 && lastColumn === 2))) {
				// at beginning of file, nothing to do
				continue;
			}

			// handle special case: when at end of line, transpose left two chars
			// otherwise, transpose left and right chars
			let endPosition = (column === lastColumn) ?
				selection.getPosition() :
				this.positionRightOf(selection.getPosition(), model);

			let middlePosition = this.positionLeftOf(endPosition, model);
			let beginPosition = this.positionLeftOf(middlePosition, model);

			let leftChar = model.getValueInRange(Range.fromPositions(beginPosition, middlePosition));
			let rightChar = model.getValueInRange(Range.fromPositions(middlePosition, endPosition));

			let replaceRange = Range.fromPositions(beginPosition, endPosition);
			commands.push(new ReplaceCommand(replaceRange, rightChar + leftChar));
		}

		if (commands.length > 0) {
			editor.pushUndoStop();
			editor.executeCommands(this.id, commands);
			editor.pushUndoStop();
		}
	}
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:46,代碼來源:transpose.ts

示例3: _addTokenRange

	private _addTokenRange(bucket: Range[], model: ITextModel, pos: Position): void {
		const tokens = model.getLineTokens(pos.lineNumber);
		const index = tokens.findTokenIndexAtOffset(pos.column - 1);
		const type = tokens.getStandardTokenType(index);
		if (type === StandardTokenType.Other) {
			return;
		}

		// grow left
		let left: Position | undefined;
		{
			let leftIndex = index;
			let leftTokens = tokens;
			let leftLine = pos.lineNumber;
			while (!left) {
				let newLeftIndex = leftIndex - 1;
				if (newLeftIndex < 0) {
					if (leftLine > 1) {
						leftLine -= 1;
						leftTokens = model.getLineTokens(leftLine);
						leftIndex = leftTokens.getCount();
					} else {
						left = new Position(1, 1);
					}
				} else {
					if (leftTokens.getStandardTokenType(newLeftIndex) === type) {
						leftIndex = newLeftIndex;
					} else {
						if (newLeftIndex === leftTokens.getCount() - 1) {
							// we got here but there was nothing
							left = new Position(leftLine + 1, 1);

						} else {
							left = new Position(leftLine, leftTokens.getStartOffset(leftIndex) + 1);
						}
					}
				}
			}
		}

		// grow right
		let right: Position | undefined;
		{
			let rightIndex = index;
			let rightTokens = tokens;
			let rightLine = pos.lineNumber;
			while (!right) {
				let newRightIndex = rightIndex + 1;
				if (newRightIndex >= rightTokens.getCount()) {
					if (rightLine < model.getLineCount()) {
						rightLine += 1;
						rightTokens = model.getLineTokens(rightLine);
						rightIndex = -1;
					} else {
						right = new Position(model.getLineCount(), model.getLineMaxColumn(model.getLineCount()));
					}
				} else {
					if (rightTokens.getStandardTokenType(newRightIndex) === type) {
						rightIndex = newRightIndex;
					} else {
						if (newRightIndex === 0) {
							// we got here but there was nothing
							right = new Position(rightLine - 1, model.getLineMaxColumn(rightLine - 1));
						} else {
							right = new Position(rightLine, rightTokens.getEndOffset(rightIndex) + 1);
						}
					}
				}
			}
		}

		if (type === StandardTokenType.String) {
			// just assume that quotation marks are length=1
			bucket.push(Range.fromPositions(left.delta(0, 1), right.delta(0, -1)));
			bucket.push(Range.fromPositions(left, right));
		} else {
			bucket.push(Range.fromPositions(left, right));
		}
	}
開發者ID:donaldpipowitch,項目名稱:vscode,代碼行數:79,代碼來源:wordSelections.ts


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