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


TypeScript TextModel.getOffsetAt方法代码示例

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


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

示例1: assertOneDirectionLineMapping

function assertOneDirectionLineMapping(model: TextModel, direction: AssertDocumentLineMappingDirection, msg: string): void {
	let allText = model.getValue();

	let line = 1, column = 1, previousIsCarriageReturn = false;
	for (let offset = 0; offset <= allText.length; offset++) {
		// The position coordinate system cannot express the position between \r and \n
		let position = new Position(line, column + (previousIsCarriageReturn ? -1 : 0));

		if (direction === AssertDocumentLineMappingDirection.OffsetToPosition) {
			let actualPosition = model.getPositionAt(offset);
			assert.equal(actualPosition.toString(), position.toString(), msg + ' - getPositionAt mismatch for offset ' + offset);
		} else {
			// The position coordinate system cannot express the position between \r and \n
			let expectedOffset = offset + (previousIsCarriageReturn ? -1 : 0);
			let actualOffset = model.getOffsetAt(position);
			assert.equal(actualOffset, expectedOffset, msg + ' - getOffsetAt mismatch for position ' + position.toString());
		}

		if (allText.charAt(offset) === '\n') {
			line++;
			column = 1;
		} else {
			column++;
		}

		previousIsCarriageReturn = (allText.charAt(offset) === '\r');
	}
}
开发者ID:jumpinjackie,项目名称:sqlopsstudio,代码行数:28,代码来源:editableTextModelTestUtils.ts

示例2: _doFindNextMatchMultiline

	private static _doFindNextMatchMultiline(model: TextModel, searchStart: Position, searcher: Searcher, captureMatches: boolean): FindMatch {
		const searchTextStart = new Position(searchStart.lineNumber, 1);
		const deltaOffset = model.getOffsetAt(searchTextStart);
		const lineCount = model.getLineCount();
		// We always execute multiline search over the lines joined with \n
		// This makes it that \n will match the EOL for both CRLF and LF models
		// We compensate for offset errors in `_getMultilineMatchRange`
		const text = model.getValueInRange(new Range(searchTextStart.lineNumber, searchTextStart.column, lineCount, model.getLineMaxColumn(lineCount)), EndOfLinePreference.LF);
		searcher.reset(searchStart.column - 1);
		let m = searcher.next(text);
		if (m) {
			return createFindMatch(
				this._getMultilineMatchRange(model, deltaOffset, text, m.index, m[0]),
				m,
				captureMatches
			);
		}

		if (searchStart.lineNumber !== 1 || searchStart.column !== 1) {
			// Try again from the top
			return this._doFindNextMatchMultiline(model, new Position(1, 1), searcher, captureMatches);
		}

		return null;
	}
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:25,代码来源:textModelSearch.ts

示例3: _doFindNextMatchMultiline

	private static _doFindNextMatchMultiline(model: TextModel, searchStart: Position, searchRegex: RegExp, captureMatches: boolean): FindMatch {
		const searchTextStart = new Position(searchStart.lineNumber, 1);
		const deltaOffset = model.getOffsetAt(searchTextStart);
		const lineCount = model.getLineCount();
		const text = model.getValueInRange(new Range(searchTextStart.lineNumber, searchTextStart.column, lineCount, model.getLineMaxColumn(lineCount)));
		searchRegex.lastIndex = searchStart.column - 1;
		let m = searchRegex.exec(text);
		if (m) {
			const startOffset = deltaOffset + m.index;
			const endOffset = startOffset + m[0].length;
			const startPosition = model.getPositionAt(startOffset);
			const endPosition = model.getPositionAt(endOffset);
			return createFindMatch(
				new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column),
				m,
				captureMatches
			);
		}

		if (searchStart.lineNumber !== 1 || searchStart.column !== -1) {
			// Try again from the top
			return this._doFindNextMatchMultiline(model, new Position(1, 1), searchRegex, captureMatches);
		}

		return null;
	}
开发者ID:fs814,项目名称:vscode,代码行数:26,代码来源:textModelSearch.ts

示例4: _doFindMatchesMultiline

	private static _doFindMatchesMultiline(model: TextModel, searchRange: Range, searcher: Searcher, captureMatches: boolean, limitResultCount: number): FindMatch[] {
		const deltaOffset = model.getOffsetAt(searchRange.getStartPosition());
		// We always execute multiline search over the lines joined with \n
		// This makes it that \n will match the EOL for both CRLF and LF models
		// We compensate for offset errors in `_getMultilineMatchRange`
		const text = model.getValueInRange(searchRange, EndOfLinePreference.LF);

		const result: FindMatch[] = [];
		let counter = 0;

		let m: RegExpExecArray;
		searcher.reset(0);
		while ((m = searcher.next(text))) {
			result[counter++] = createFindMatch(this._getMultilineMatchRange(model, deltaOffset, text, m.index, m[0]), m, captureMatches);
			if (counter >= limitResultCount) {
				return result;
			}
		}

		return result;
	}
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:21,代码来源:textModelSearch.ts

示例5: _doFindMatchesMultiline

	private static _doFindMatchesMultiline(model: TextModel, searchRange: Range, searchRegex: RegExp, captureMatches: boolean, limitResultCount: number): FindMatch[] {
		const deltaOffset = model.getOffsetAt(searchRange.getStartPosition());
		const text = model.getValueInRange(searchRange);

		const result: FindMatch[] = [];
		let prevStartOffset = 0;
		let prevEndOffset = 0;
		let counter = 0;

		let m: RegExpExecArray;
		while ((m = searchRegex.exec(text))) {
			const startOffset = deltaOffset + m.index;
			const endOffset = startOffset + m[0].length;

			if (prevStartOffset === startOffset && prevEndOffset === endOffset) {
				// Exit early if the regex matches the same range
				return result;
			}

			const startPosition = model.getPositionAt(startOffset);
			const endPosition = model.getPositionAt(endOffset);

			result[counter++] = createFindMatch(
				new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column),
				m,
				captureMatches
			);
			if (counter >= limitResultCount) {
				return result;
			}

			prevStartOffset = startOffset;
			prevEndOffset = endOffset;
		}

		return result;
	}
开发者ID:fs814,项目名称:vscode,代码行数:37,代码来源:textModelSearch.ts

示例6: _doFindMatchesMultiline

	private static _doFindMatchesMultiline(model: TextModel, searchRange: Range, searchRegex: RegExp, captureMatches: boolean, limitResultCount: number): FindMatch[] {
		const deltaOffset = model.getOffsetAt(searchRange.getStartPosition());
		// We always execute multiline search over the lines joined with \n
		// This makes it that \n will match the EOL for both CRLF and LF models
		// We compensate for offset errors in `_getMultilineMatchRange`
		const text = model.getValueInRange(searchRange, EndOfLinePreference.LF);

		const result: FindMatch[] = [];
		let prevStartOffset = 0;
		let prevEndOffset = 0;
		let counter = 0;

		let m: RegExpExecArray;
		while ((m = searchRegex.exec(text))) {
			const startOffset = deltaOffset + m.index;
			const endOffset = startOffset + m[0].length;

			if (prevStartOffset === startOffset && prevEndOffset === endOffset) {
				// Exit early if the regex matches the same range
				return result;
			}

			result[counter++] = createFindMatch(
				this._getMultilineMatchRange(model, deltaOffset, text, m.index, m[0]),
				m,
				captureMatches
			);
			if (counter >= limitResultCount) {
				return result;
			}

			prevStartOffset = startOffset;
			prevEndOffset = endOffset;
		}

		return result;
	}
开发者ID:hungys,项目名称:vscode,代码行数:37,代码来源:textModelSearch.ts


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