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


TypeScript PrefixSumComputer.insertValues方法代码示例

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


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

示例1: onModelLinesInserted

	public onModelLinesInserted(versionId:number, fromLineNumber:number, toLineNumber:number, text:string[], emit:(evenType:string, payload:any)=>void): void {
		if (versionId <= this._validModelVersionId) {
			return;
		}
		this._validModelVersionId = versionId;

		var hiddenAreas = this.getHiddenAreas();
		var isInHiddenArea = false;
		var testPosition = new Position(fromLineNumber, 1);
		for (var i = 0; i < hiddenAreas.length; i++) {
			if (hiddenAreas[i].containsPosition(testPosition)) {
				isInHiddenArea = true;
				break;
			}
		}

		var outputFromLineNumber = (fromLineNumber === 1 ? 1 : this.prefixSumComputer.getAccumulatedValue(fromLineNumber - 2) + 1);

		var line: ISplitLine,
			outputLineCount: number,
			totalOutputLineCount = 0;

		var insertLines: ISplitLine[] = [],
			insertPrefixSumValues: number[] = [];

		for (var i = 0, len = text.length; i < len; i++) {
			var line = createSplitLine(this.linePositionMapperFactory, text[i], this.tabSize, this.wrappingColumn, this.columnsForFullWidthChar, this.wrappingIndent, !isInHiddenArea);
			insertLines.push(line);

			outputLineCount = line.getOutputLineCount();
			totalOutputLineCount += outputLineCount;
			insertPrefixSumValues.push(outputLineCount);
		}

		this.lines = this.lines.slice(0, fromLineNumber - 1).concat(insertLines).concat(this.lines.slice(fromLineNumber - 1));

		this.prefixSumComputer.insertValues(fromLineNumber - 1, insertPrefixSumValues);

		var e:editorCommon.IViewLinesInsertedEvent = {
			fromLineNumber: outputFromLineNumber,
			toLineNumber: outputFromLineNumber + totalOutputLineCount - 1
		};
		emit(editorCommon.ViewEventNames.LinesInsertedEvent, e);
	}
开发者ID:pieandcakes,项目名称:vscode,代码行数:44,代码来源:splitLinesCollection.ts

示例2: _acceptInsertText

	private _acceptInsertText(position: IPosition, insertText:string): void {
		if (insertText.length === 0) {
			// Nothing to insert
			return;
		}
		let insertLines = insertText.split(/\r\n|\r|\n/);
		if (insertLines.length === 1) {
			// Inserting text on one line
			this._setLineText(position.lineNumber - 1,
				this._lines[position.lineNumber - 1].substring(0, position.column - 1)
				+ insertLines[0]
				+ this._lines[position.lineNumber - 1].substring(position.column - 1)
			);
			return;
		}

		// Append overflowing text from first line to the end of text to insert
		insertLines[insertLines.length - 1] += this._lines[position.lineNumber - 1].substring(position.column - 1);

		// Delete overflowing text from first line and insert text on first line
		this._setLineText(position.lineNumber - 1,
			this._lines[position.lineNumber - 1].substring(0, position.column - 1)
			+ insertLines[0]
		);

		// Insert new lines & store lengths
		let newLengths:number[] = new Array<number>(insertLines.length - 1);
		for (let i = 1; i < insertLines.length; i++) {
			this._lines.splice(position.lineNumber + i - 1, 0, insertLines[i]);
			newLengths[i - 1] = insertLines[i].length + this._eol.length;
		}

		if (this._lineStarts) {
			// update prefix sum
			this._lineStarts.insertValues(position.lineNumber, newLengths);
		}
	}
开发者ID:13572293130,项目名称:vscode,代码行数:37,代码来源:mirrorModel2.ts

示例3: _doApplyEdits

	private _doApplyEdits(operations: IValidatedEditOperation[]): IInternalModelContentChange[] {

		// Sort operations descending
		operations.sort(LinesTextBuffer._sortOpsDescending);

		let contentChanges: IInternalModelContentChange[] = [];

		for (let i = 0, len = operations.length; i < len; i++) {
			const op = operations[i];

			const startLineNumber = op.range.startLineNumber;
			const startColumn = op.range.startColumn;
			const endLineNumber = op.range.endLineNumber;
			const endColumn = op.range.endColumn;

			if (startLineNumber === endLineNumber && startColumn === endColumn && (!op.lines || op.lines.length === 0)) {
				// no-op
				continue;
			}

			const deletingLinesCnt = endLineNumber - startLineNumber;
			const insertingLinesCnt = (op.lines ? op.lines.length - 1 : 0);
			const editingLinesCnt = Math.min(deletingLinesCnt, insertingLinesCnt);

			for (let j = editingLinesCnt; j >= 0; j--) {
				const editLineNumber = startLineNumber + j;
				let editText = (op.lines ? op.lines[j] : '');

				if (editLineNumber === startLineNumber || editLineNumber === endLineNumber) {
					const editStartColumn = (editLineNumber === startLineNumber ? startColumn : 1);
					const editEndColumn = (editLineNumber === endLineNumber ? endColumn : this.getLineLength(editLineNumber) + 1);

					editText = (
						this._lines[editLineNumber - 1].substring(0, editStartColumn - 1)
						+ editText
						+ this._lines[editLineNumber - 1].substring(editEndColumn - 1)
					);
				}

				this._setLineContent(editLineNumber, editText);
			}

			if (editingLinesCnt < deletingLinesCnt) {
				// Must delete some lines

				const spliceStartLineNumber = startLineNumber + editingLinesCnt;
				const endLineRemains = this._lines[endLineNumber - 1].substring(endColumn - 1);

				// Reconstruct first line
				this._setLineContent(spliceStartLineNumber, this._lines[spliceStartLineNumber - 1] + endLineRemains);

				this._lines.splice(spliceStartLineNumber, endLineNumber - spliceStartLineNumber);
				this._lineStarts.removeValues(spliceStartLineNumber, endLineNumber - spliceStartLineNumber);
			}

			if (editingLinesCnt < insertingLinesCnt) {
				// Must insert some lines

				const spliceLineNumber = startLineNumber + editingLinesCnt;
				let spliceColumn = (spliceLineNumber === startLineNumber ? startColumn : 1);
				if (op.lines) {
					spliceColumn += op.lines[editingLinesCnt].length;
				}

				// Split last line
				const leftoverLine = this._lines[spliceLineNumber - 1].substring(spliceColumn - 1);

				this._setLineContent(spliceLineNumber, this._lines[spliceLineNumber - 1].substring(0, spliceColumn - 1));

				// Lines in the middle
				let newLines: string[] = new Array<string>(insertingLinesCnt - editingLinesCnt);
				let newLinesLengths = new Uint32Array(insertingLinesCnt - editingLinesCnt);
				for (let j = editingLinesCnt + 1; j <= insertingLinesCnt; j++) {
					newLines[j - editingLinesCnt - 1] = op.lines[j];
					newLinesLengths[j - editingLinesCnt - 1] = op.lines[j].length + this._EOL.length;
				}
				newLines[newLines.length - 1] += leftoverLine;
				newLinesLengths[newLines.length - 1] += leftoverLine.length;
				this._lines = arrays.arrayInsert(this._lines, startLineNumber + editingLinesCnt, newLines);
				this._lineStarts.insertValues(startLineNumber + editingLinesCnt, newLinesLengths);
			}

			const contentChangeRange = new Range(startLineNumber, startColumn, endLineNumber, endColumn);
			const text = (op.lines ? op.lines.join(this.getEOL()) : '');
			contentChanges.push({
				range: contentChangeRange,
				rangeLength: op.rangeLength,
				text: text,
				rangeOffset: op.rangeOffset,
				forceMoveMarkers: op.forceMoveMarkers
			});
		}

		return contentChanges;
	}
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:95,代码来源:linesTextBuffer.ts


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