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


TypeScript Position.delta方法代码示例

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


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

示例1: _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/position.Position.delta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。