本文整理匯總了TypeScript中vs/editor/common/viewModel/prefixSumComputer.PrefixSumComputer.changeValue方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript PrefixSumComputer.changeValue方法的具體用法?TypeScript PrefixSumComputer.changeValue怎麽用?TypeScript PrefixSumComputer.changeValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vs/editor/common/viewModel/prefixSumComputer.PrefixSumComputer
的用法示例。
在下文中一共展示了PrefixSumComputer.changeValue方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: _setLineText
/**
* All changes to a line's text go through this method
*/
private _setLineText(lineIndex:number, newValue:string): void {
this._lines[lineIndex] = newValue;
if (this._lineStarts) {
// update prefix sum
this._lineStarts.changeValue(lineIndex, this._lines[lineIndex].length + this._eol.length);
}
}
示例2: setHiddenAreas
public setHiddenAreas(_ranges:EditorCommon.IRange[], emit:(evenType:string, payload:any)=>void): void {
let ranges = this._reduceRanges(_ranges);
var newDecorations:EditorCommon.IModelDeltaDecoration[] = [];
for (var i = 0; i < ranges.length; i++) {
newDecorations.push({
range: ranges[i],
options: {
}
});
}
this.hiddenAreasIds = this.model.deltaDecorations(this.hiddenAreasIds, newDecorations);
var hiddenAreas = ranges;
var hiddenAreaStart = 1, hiddenAreaEnd = 0;
var hiddenAreaIdx = -1;
var nextLineNumberToUpdateHiddenArea = (hiddenAreaIdx + 1 < hiddenAreas.length) ? hiddenAreaEnd + 1 : this.lines.length + 2;
for (var i = 0; i < this.lines.length; i++) {
var lineNumber = i + 1;
if (lineNumber === nextLineNumberToUpdateHiddenArea) {
hiddenAreaIdx++;
hiddenAreaStart = hiddenAreas[hiddenAreaIdx].startLineNumber;
hiddenAreaEnd = hiddenAreas[hiddenAreaIdx].endLineNumber;
nextLineNumberToUpdateHiddenArea = (hiddenAreaIdx + 1 < hiddenAreas.length) ? hiddenAreaEnd + 1 : this.lines.length + 2;
}
var lineChanged = false;
if (lineNumber >= hiddenAreaStart && lineNumber <= hiddenAreaEnd) {
// Line should be hidden
if (this.lines[i].isVisible()) {
this.lines[i].setVisible(false);
lineChanged = true;
}
} else {
// Line should be visible
if (!this.lines[i].isVisible()) {
this.lines[i].setVisible(true);
lineChanged = true;
}
}
if (lineChanged) {
var newOutputLineCount = this.lines[i].getOutputLineCount();
this.prefixSumComputer.changeValue(i, newOutputLineCount);
}
}
emit(EditorCommon.ViewEventNames.ModelFlushedEvent, null);
}
示例3: onModelLineChanged
public onModelLineChanged(versionId:number, lineNumber:number, newText:string, emit:(evenType:string, payload:any)=>void): boolean {
if (versionId <= this._validModelVersionId) {
return;
}
this._validModelVersionId = versionId;
var lineIndex = lineNumber - 1;
var oldOutputLineCount = this.lines[lineIndex].getOutputLineCount();
var isVisible = this.lines[lineIndex].isVisible();
var line = createSplitLine(this.linePositionMapperFactory, newText, this.tabSize, this.wrappingColumn, this.columnsForFullWidthChar, this.wrappingIndent, isVisible);
this.lines[lineIndex] = line;
var newOutputLineCount = this.lines[lineIndex].getOutputLineCount();
var lineMappingChanged = false,
changeFrom = 0,
changeTo = -1,
insertFrom = 0,
insertTo = -1,
deleteFrom = 0,
deleteTo = -1;
if (oldOutputLineCount > newOutputLineCount) {
changeFrom = (lineNumber === 1 ? 1 : this.prefixSumComputer.getAccumulatedValue(lineNumber - 2) + 1);
changeTo = changeFrom + newOutputLineCount - 1;
deleteFrom = changeTo + 1;
deleteTo = deleteFrom + (oldOutputLineCount - newOutputLineCount) - 1;
lineMappingChanged = true;
} else if (oldOutputLineCount < newOutputLineCount) {
changeFrom = (lineNumber === 1 ? 1 : this.prefixSumComputer.getAccumulatedValue(lineNumber - 2) + 1);
changeTo = changeFrom + oldOutputLineCount - 1;
insertFrom = changeTo + 1;
insertTo = insertFrom + (newOutputLineCount - oldOutputLineCount) - 1;
lineMappingChanged = true;
} else {
changeFrom = (lineNumber === 1 ? 1 : this.prefixSumComputer.getAccumulatedValue(lineNumber - 2) + 1);
changeTo = changeFrom + newOutputLineCount - 1;
}
this.prefixSumComputer.changeValue(lineIndex, newOutputLineCount);
var i:number,
e1:editorCommon.IViewLineChangedEvent,
e2:editorCommon.IViewLinesInsertedEvent,
e3:editorCommon.IViewLinesDeletedEvent;
if (changeFrom <= changeTo) {
for (var i = changeFrom; i <= changeTo; i++) {
e1 = {
lineNumber: i
};
emit(editorCommon.ViewEventNames.LineChangedEvent, e1);
}
}
if (insertFrom <= insertTo) {
e2 = {
fromLineNumber: insertFrom,
toLineNumber: insertTo
};
emit(editorCommon.ViewEventNames.LinesInsertedEvent, e2);
}
if (deleteFrom <= deleteTo) {
e3 = {
fromLineNumber: deleteFrom,
toLineNumber: deleteTo
};
emit(editorCommon.ViewEventNames.LinesDeletedEvent, e3);
}
return lineMappingChanged;
}
示例4: setHiddenAreas
public setHiddenAreas(_ranges:editorCommon.IRange[], emit:(evenType:string, payload:any)=>void): boolean {
let newRanges = this._reduceRanges(_ranges);
// BEGIN TODO@Martin: Please stop calling this method on each model change!
let oldRanges = this.hiddenAreasIds.map((areaId) => this.model.getDecorationRange(areaId)).sort(Range.compareRangesUsingStarts);
if (newRanges.length === oldRanges.length) {
let hasDifference = false;
for (let i = 0; i < newRanges.length; i++) {
if (!newRanges[i].equalsRange(oldRanges[i])) {
hasDifference = true;
break;
}
}
if (!hasDifference) {
return false;
}
}
// END TODO@Martin: Please stop calling this method on each model change!
let newDecorations:editorCommon.IModelDeltaDecoration[] = [];
for (let i = 0; i < newRanges.length; i++) {
newDecorations.push({
range: newRanges[i],
options: {
}
});
}
this.hiddenAreasIds = this.model.deltaDecorations(this.hiddenAreasIds, newDecorations);
let hiddenAreas = newRanges;
let hiddenAreaStart = 1, hiddenAreaEnd = 0;
let hiddenAreaIdx = -1;
let nextLineNumberToUpdateHiddenArea = (hiddenAreaIdx + 1 < hiddenAreas.length) ? hiddenAreaEnd + 1 : this.lines.length + 2;
for (let i = 0; i < this.lines.length; i++) {
let lineNumber = i + 1;
if (lineNumber === nextLineNumberToUpdateHiddenArea) {
hiddenAreaIdx++;
hiddenAreaStart = hiddenAreas[hiddenAreaIdx].startLineNumber;
hiddenAreaEnd = hiddenAreas[hiddenAreaIdx].endLineNumber;
nextLineNumberToUpdateHiddenArea = (hiddenAreaIdx + 1 < hiddenAreas.length) ? hiddenAreaEnd + 1 : this.lines.length + 2;
}
let lineChanged = false;
if (lineNumber >= hiddenAreaStart && lineNumber <= hiddenAreaEnd) {
// Line should be hidden
if (this.lines[i].isVisible()) {
this.lines[i].setVisible(false);
lineChanged = true;
}
} else {
// Line should be visible
if (!this.lines[i].isVisible()) {
this.lines[i].setVisible(true);
lineChanged = true;
}
}
if (lineChanged) {
let newOutputLineCount = this.lines[i].getOutputLineCount();
this.prefixSumComputer.changeValue(i, newOutputLineCount);
}
}
emit(editorCommon.ViewEventNames.ModelFlushedEvent, null);
return true;
}
示例5: _setLineContent
private _setLineContent(lineNumber: number, content: string): void {
this._lines[lineNumber - 1] = content;
this._lineStarts.changeValue(lineNumber - 1, content.length + this._EOL.length);
}
示例6: test
test('PrefixSumComputer', () => {
var indexOfResult:IPrefixSumIndexOfResult = {
index: 0,
remainder: 0
};
var psc = new PrefixSumComputer([1, 1, 2, 1, 3]);
assert.equal(psc.getTotalValue(), 8);
assert.equal(psc.getAccumulatedValue(-1), 0);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 2);
assert.equal(psc.getAccumulatedValue(2), 4);
assert.equal(psc.getAccumulatedValue(3), 5);
assert.equal(psc.getAccumulatedValue(4), 8);
psc.getIndexOf(0, indexOfResult);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(1, indexOfResult);
assert.equal(indexOfResult.index, 1);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(2, indexOfResult);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(3, indexOfResult);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 1);
psc.getIndexOf(4, indexOfResult);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(5, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(6, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 1);
psc.getIndexOf(7, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 2);
psc.getIndexOf(8, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 3);
// [1, 2, 2, 1, 3]
psc.changeValue(1, 2);
assert.equal(psc.getTotalValue(), 9);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 3);
assert.equal(psc.getAccumulatedValue(2), 5);
assert.equal(psc.getAccumulatedValue(3), 6);
assert.equal(psc.getAccumulatedValue(4), 9);
// [1, 0, 2, 1, 3]
psc.changeValue(1, 0);
assert.equal(psc.getTotalValue(), 7);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 1);
assert.equal(psc.getAccumulatedValue(2), 3);
assert.equal(psc.getAccumulatedValue(3), 4);
assert.equal(psc.getAccumulatedValue(4), 7);
psc.getIndexOf(0, indexOfResult);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(1, indexOfResult);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(2, indexOfResult);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 1);
psc.getIndexOf(3, indexOfResult);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(4, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(5, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 1);
psc.getIndexOf(6, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 2);
psc.getIndexOf(7, indexOfResult);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 3);
// [1, 0, 0, 1, 3]
psc.changeValue(2, 0);
assert.equal(psc.getTotalValue(), 5);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 1);
assert.equal(psc.getAccumulatedValue(2), 1);
assert.equal(psc.getAccumulatedValue(3), 2);
assert.equal(psc.getAccumulatedValue(4), 5);
psc.getIndexOf(0, indexOfResult);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(1, indexOfResult);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
psc.getIndexOf(2, indexOfResult);
assert.equal(indexOfResult.index, 4);
//.........這裏部分代碼省略.........
示例7: test
test('PrefixSumComputer', () => {
let indexOfResult: PrefixSumIndexOfResult;
let psc = new PrefixSumComputer(toUint32Array([1, 1, 2, 1, 3]));
assert.equal(psc.getTotalValue(), 8);
assert.equal(psc.getAccumulatedValue(-1), 0);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 2);
assert.equal(psc.getAccumulatedValue(2), 4);
assert.equal(psc.getAccumulatedValue(3), 5);
assert.equal(psc.getAccumulatedValue(4), 8);
indexOfResult = psc.getIndexOf(0);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(1);
assert.equal(indexOfResult.index, 1);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(2);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(3);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 1);
indexOfResult = psc.getIndexOf(4);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(5);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(6);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 1);
indexOfResult = psc.getIndexOf(7);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 2);
indexOfResult = psc.getIndexOf(8);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 3);
// [1, 2, 2, 1, 3]
psc.changeValue(1, 2);
assert.equal(psc.getTotalValue(), 9);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 3);
assert.equal(psc.getAccumulatedValue(2), 5);
assert.equal(psc.getAccumulatedValue(3), 6);
assert.equal(psc.getAccumulatedValue(4), 9);
// [1, 0, 2, 1, 3]
psc.changeValue(1, 0);
assert.equal(psc.getTotalValue(), 7);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 1);
assert.equal(psc.getAccumulatedValue(2), 3);
assert.equal(psc.getAccumulatedValue(3), 4);
assert.equal(psc.getAccumulatedValue(4), 7);
indexOfResult = psc.getIndexOf(0);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(1);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(2);
assert.equal(indexOfResult.index, 2);
assert.equal(indexOfResult.remainder, 1);
indexOfResult = psc.getIndexOf(3);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(4);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(5);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 1);
indexOfResult = psc.getIndexOf(6);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 2);
indexOfResult = psc.getIndexOf(7);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 3);
// [1, 0, 0, 1, 3]
psc.changeValue(2, 0);
assert.equal(psc.getTotalValue(), 5);
assert.equal(psc.getAccumulatedValue(0), 1);
assert.equal(psc.getAccumulatedValue(1), 1);
assert.equal(psc.getAccumulatedValue(2), 1);
assert.equal(psc.getAccumulatedValue(3), 2);
assert.equal(psc.getAccumulatedValue(4), 5);
indexOfResult = psc.getIndexOf(0);
assert.equal(indexOfResult.index, 0);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(1);
assert.equal(indexOfResult.index, 3);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(2);
assert.equal(indexOfResult.index, 4);
assert.equal(indexOfResult.remainder, 0);
indexOfResult = psc.getIndexOf(3);
assert.equal(indexOfResult.index, 4);
//.........這裏部分代碼省略.........
示例8: _setLineContent
private _setLineContent(lineNumber: number, content: string, rawContentChanges: ModelRawChange[]): void {
this._lines[lineNumber - 1] = content;
this._lineStarts.changeValue(lineNumber - 1, content.length + this._EOL.length);
rawContentChanges.push(new ModelRawLineChanged(lineNumber, content));
}