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


TypeScript TextModel.getEOL方法代碼示例

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


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

示例1: _getMultilineMatchRange

	/**
	 * Multiline search always executes on the lines concatenated with \n.
	 * We must therefore compensate for the count of \n in case the model is CRLF
	 */
	private static _getMultilineMatchRange(model: TextModel, deltaOffset: number, text: string, matchIndex: number, match0: string): Range {
		let startOffset: number;
		if (model.getEOL() === '\r\n') {
			let lineFeedCountBeforeMatch = 0;
			for (let i = 0; i < matchIndex; i++) {
				let chCode = text.charCodeAt(i);
				if (chCode === CharCode.LineFeed) {
					lineFeedCountBeforeMatch++;
				}
			}
			startOffset = deltaOffset + matchIndex + lineFeedCountBeforeMatch /* add as many \r as there were \n */;
		} else {
			startOffset = deltaOffset + matchIndex;
		}

		let endOffset: number;
		if (model.getEOL() === '\r\n') {
			let lineFeedCountInMatch = 0;
			for (let i = 0, len = match0.length; i < len; i++) {
				let chCode = text.charCodeAt(i + matchIndex);
				if (chCode === CharCode.LineFeed) {
					lineFeedCountInMatch++;
				}
			}
			endOffset = startOffset + match0.length + lineFeedCountInMatch /* add as many \r as there were \n */;
		} else {
			endOffset = startOffset + match0.length;
		}

		const startPosition = model.getPositionAt(startOffset);
		const endPosition = model.getPositionAt(endOffset);
		return new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column);
	}
開發者ID:JarnoNijboer,項目名稱:vscode,代碼行數:37,代碼來源:textModelSearch.ts

示例2: setup

	setup(function () {
		contextKeys = new MockContextKeyService();
		model = TextModel.createFromString('if\n    $state\nfi');
		editor = createTestCodeEditor({ model: model });
		editor.setSelections([new Selection(1, 1, 1, 1), new Selection(2, 5, 2, 5)]);
		assert.equal(model.getEOL(), '\n');
	});
開發者ID:VishalMadhvani,項目名稱:vscode,代碼行數:7,代碼來源:snippetController2.test.ts

示例3: _doFindNextMatchMultiline

	private static _doFindNextMatchMultiline(model: TextModel, searchStart: Position, searcher: Searcher, captureMatches: boolean): FindMatch | null {
		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);
		const lfCounter = (model.getEOL() === '\r\n' ? new LineFeedCounter(text) : null);
		searcher.reset(searchStart.column - 1);
		let m = searcher.next(text);
		if (m) {
			return createFindMatch(
				this._getMultilineMatchRange(model, deltaOffset, text, lfCounter, 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:KTXSoftware,項目名稱:KodeStudio,代碼行數:26,代碼來源:textModelSearch.ts

示例4: getModelEOL

function getModelEOL(model: TextModel): EndOfLineSequence {
	const eol = model.getEOL();
	if (eol === '\n') {
		return EndOfLineSequence.LF;
	} else {
		return EndOfLineSequence.CRLF;
	}
}
開發者ID:ramesius,項目名稱:vscode,代碼行數:8,代碼來源:editStack.ts

示例5: test

	test('\\r can never be found', () => {
		let model = new TextModel([], TextModel.toRawText('a\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni', TextModel.DEFAULT_CREATION_OPTIONS));

		assert.equal(model.getEOL(), '\r\n');

		let searchParams = new SearchParams('\\r\\n', true, false, false);
		let actual = TextModelSearch.findNextMatch(model, searchParams, new Position(1, 1), true);
		assert.equal(actual, null);
		assert.deepEqual(TextModelSearch.findMatches(model, searchParams, model.getFullModelRange(), true, 1000), []);

		model.dispose();
	});
開發者ID:diarmaidm,項目名稱:vscode,代碼行數:12,代碼來源:textModelSearch.test.ts

示例6: _getMultilineMatchRange

	/**
	 * Multiline search always executes on the lines concatenated with \n.
	 * We must therefore compensate for the count of \n in case the model is CRLF
	 */
	private static _getMultilineMatchRange(model: TextModel, deltaOffset: number, text: string, lfCounter: LineFeedCounter, matchIndex: number, match0: string): Range {
		let startOffset: number;
		let lineFeedCountBeforeMatch = 0;
		if (model.getEOL() === '\r\n') {
			lineFeedCountBeforeMatch = lfCounter.findLineFeedCountBeforeOffset(matchIndex);
			startOffset = deltaOffset + matchIndex + lineFeedCountBeforeMatch /* add as many \r as there were \n */;
		} else {
			startOffset = deltaOffset + matchIndex;
		}

		let endOffset: number;
		if (model.getEOL() === '\r\n') {
			let lineFeedCountBeforeEndOfMatch = lfCounter.findLineFeedCountBeforeOffset(matchIndex + match0.length);
			let lineFeedCountInMatch = lineFeedCountBeforeEndOfMatch - lineFeedCountBeforeMatch;
			endOffset = startOffset + match0.length + lineFeedCountInMatch /* add as many \r as there were \n */;
		} else {
			endOffset = startOffset + match0.length;
		}

		const startPosition = model.getPositionAt(startOffset);
		const endPosition = model.getPositionAt(endOffset);
		return new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column);
	}
開發者ID:AllureFer,項目名稱:vscode,代碼行數:27,代碼來源:textModelSearch.ts

示例7: _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 lfCounter = (model.getEOL() === '\r\n' ? new LineFeedCounter(text) : null);

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

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

		return result;
	}
開發者ID:KTXSoftware,項目名稱:KodeStudio,代碼行數:22,代碼來源:textModelSearch.ts

示例8: setup

	setup(function () {
		model = TextModel.createFromString('function foo() {\n    console.log(a);\n}');
		editor = createTestCodeEditor({ model: model });
		editor.setSelections([new Selection(1, 1, 1, 1), new Selection(2, 5, 2, 5)]);
		assert.equal(model.getEOL(), '\n');
	});
開發者ID:liunian,項目名稱:vscode,代碼行數:6,代碼來源:snippetSession.test.ts


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