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


TypeScript ITextModel.getLineContent方法代碼示例

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


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

示例1: computeRanges

export function computeRanges(model: ITextModel, foldEndPattern: RegExp = null, minimumRangeSize: number = 1): IndentRange[] {


	let result: IndentRange[] = [];

	let previousRegions: { indent: number, line: number }[] = [];
	previousRegions.push({ indent: -1, line: model.getLineCount() + 1 }); // sentinel, to make sure there's at least one entry

	for (let line = model.getLineCount(); line > 0; line--) {
		let indent = model.getIndentLevel(line);
		if (indent === -1) {
			continue; // only whitespace
		}

		let previous = previousRegions[previousRegions.length - 1];

		if (previous.indent > indent) {
			// discard all regions with larger indent
			do {
				previousRegions.pop();
				previous = previousRegions[previousRegions.length - 1];
			} while (previous.indent > indent);

			// new folding range
			let endLineNumber = previous.line - 1;

			if (previous.line <= model.getLineCount() && foldEndPattern) {
				let foldEndLineContent = model.getLineContent(previous.line);
				if (previous.indent === indent && foldEndPattern.test(foldEndLineContent)) {
					endLineNumber = previous.line;
				}
			}

			if (endLineNumber - line >= minimumRangeSize) {
				result.push(new IndentRange(line, endLineNumber, indent));
			}
		}
		if (previous.indent === indent) {
			previous.line = line;
		} else { // previous.indent < indent
			// new region with a bigger indent
			previousRegions.push({ indent, line });
		}
	}

	return result.reverse();
}
開發者ID:aminroosta,項目名稱:vscode,代碼行數:47,代碼來源:indentRanges.ts

示例2: toIndentRanges

	public toIndentRanges(model: ITextModel) {
		if (this._length <= this._FoldingRangesLimit) {
			// reverse and create arrays of the exact length
			let startIndexes = new Uint32Array(this._length);
			let endIndexes = new Uint32Array(this._length);
			for (let i = this._length - 1, k = 0; i >= 0; i-- , k++) {
				startIndexes[k] = this._startIndexes[i];
				endIndexes[k] = this._endIndexes[i];
			}
			return new FoldingRanges(startIndexes, endIndexes);
		} else {
			let entries = 0;
			let maxIndent = this._indentOccurrences.length;
			for (let i = 0; i < this._indentOccurrences.length; i++) {
				let n = this._indentOccurrences[i];
				if (n) {
					if (n + entries > this._FoldingRangesLimit) {
						maxIndent = i;
						break;
					}
					entries += n;
				}
			}
			const tabSize = model.getOptions().tabSize;
			// reverse and create arrays of the exact length
			let startIndexes = new Uint32Array(entries);
			let endIndexes = new Uint32Array(entries);
			for (let i = this._length - 1, k = 0; i >= 0; i--) {
				let startIndex = this._startIndexes[i];
				let lineContent = model.getLineContent(startIndex);
				let indent = computeIndentLevel(lineContent, tabSize);
				if (indent < maxIndent) {
					startIndexes[k] = startIndex;
					endIndexes[k] = this._endIndexes[i];
					k++;
				}
			}
			return new FoldingRanges(startIndexes, endIndexes);
		}

	}
開發者ID:SeanKilleen,項目名稱:vscode,代碼行數:41,代碼來源:indentRangeProvider.ts

示例3: computeRanges

export function computeRanges(model: ITextModel, offSide: boolean, markers?: FoldingMarkers, FoldingRangesLimit = MAX_FOLDING_REGIONS_FOR_INDENT_LIMIT): FoldingRanges {
	const tabSize = model.getOptions().tabSize;
	let result = new RangesCollector(FoldingRangesLimit);

	let pattern = void 0;
	if (markers) {
		pattern = new RegExp(`(${markers.start.source})|(?:${markers.end.source})`);
	}

	let previousRegions: PreviousRegion[] = [];
	previousRegions.push({ indent: -1, line: model.getLineCount() + 1, marker: false }); // sentinel, to make sure there's at least one entry

	for (let line = model.getLineCount(); line > 0; line--) {
		let lineContent = model.getLineContent(line);
		let indent = computeIndentLevel(lineContent, tabSize);
		let previous = previousRegions[previousRegions.length - 1];
		if (indent === -1) {
			if (offSide && !previous.marker) {
				// for offSide languages, empty lines are associated to the next block
				previous.line = line;
			}
			continue; // only whitespace
		}
		let m;
		if (pattern && (m = lineContent.match(pattern))) {
			// folding pattern match
			if (m[1]) { // start pattern match
				// discard all regions until the folding pattern
				let i = previousRegions.length - 1;
				while (i > 0 && !previousRegions[i].marker) {
					i--;
				}
				if (i > 0) {
					previousRegions.length = i + 1;
					previous = previousRegions[i];

					// new folding range from pattern, includes the end line
					result.insertFirst(line, previous.line, indent);
					previous.marker = false;
					previous.indent = indent;
					previous.line = line;
					continue;
				} else {
					// no end marker found, treat line as a regular line
				}
			} else { // end pattern match
				previousRegions.push({ indent: -2, line, marker: true });
				continue;
			}
		}
		if (previous.indent > indent) {
			// discard all regions with larger indent
			do {
				previousRegions.pop();
				previous = previousRegions[previousRegions.length - 1];
			} while (previous.indent > indent);

			// new folding range
			let endLineNumber = previous.line - 1;
			if (endLineNumber - line >= 1) { // needs at east size 1
				result.insertFirst(line, endLineNumber, indent);
			}
		}
		if (previous.indent === indent) {
			previous.line = line;
		} else { // previous.indent < indent
			// new region with a bigger indent
			previousRegions.push({ indent, line, marker: false });
		}
	}
	return result.toIndentRanges(model);
}
開發者ID:SeanKilleen,項目名稱:vscode,代碼行數:72,代碼來源:indentRangeProvider.ts

示例4: computeRanges

export function computeRanges(model: ITextModel, offSide: boolean, markers?: FoldingMarkers, minimumRangeSize: number = 1): IndentRange[] {

	let result: IndentRange[] = [];

	let pattern = void 0;
	if (markers) {
		pattern = new RegExp(`(${markers.start.source})|(?:${markers.end.source})`);
	}

	let previousRegions: PreviousRegion[] = [];
	previousRegions.push({ indent: -1, line: model.getLineCount() + 1, marker: null }); // sentinel, to make sure there's at least one entry

	for (let line = model.getLineCount(); line > 0; line--) {
		let indent = model.getIndentLevel(line);
		let previous = previousRegions[previousRegions.length - 1];
		if (indent === -1) {
			if (offSide) {
				// for offSide languages, empty lines are associated to the next block
				previous.line = line;
			}
			continue; // only whitespace
		}
		let m;
		if (pattern && (m = model.getLineContent(line).match(pattern))) {
			// folding pattern match
			if (m[1]) { // start pattern match
				if (previous.indent >= 0 && !previous.marker) {

					// discard all regions until the folding pattern
					do {
						previousRegions.pop();
						previous = previousRegions[previousRegions.length - 1];
					} while (previous.indent >= 0 && !previous.marker);
				}
				if (previous.marker) {
					// new folding range from pattern, includes the end line
					result.push(new IndentRange(line, previous.line, indent, true));
					previous.marker = null;
					previous.indent = indent;
					previous.line = line;
				}
			} else { // end pattern match
				previousRegions.push({ indent: -2, line, marker: pattern });
			}
		} else {
			if (previous.indent > indent) {
				// discard all regions with larger indent
				do {
					previousRegions.pop();
					previous = previousRegions[previousRegions.length - 1];
				} while (previous.indent > indent);

				// new folding range
				let endLineNumber = previous.line - 1;
				if (endLineNumber - line >= minimumRangeSize) {
					result.push(new IndentRange(line, endLineNumber, indent));
				}
			}
			if (previous.indent === indent) {
				previous.line = line;
			} else { // previous.indent < indent
				// new region with a bigger indent
				previousRegions.push({ indent, line, marker: null });
			}
		}
	}

	return result.reverse();
}
開發者ID:leonardovilarinho,項目名稱:vscode,代碼行數:69,代碼來源:indentRanges.ts

示例5: getIndent

	public getIndent(index: number) {
		const lineNumber = this.getStartLineNumber(index);
		const tabSize = this._model.getOptions().tabSize;
		const lineContent = this._model.getLineContent(lineNumber);
		return computeIndentLevel(lineContent, tabSize);
	}
開發者ID:gokulakrishna9,項目名稱:vscode,代碼行數:6,代碼來源:indentRanges.ts


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