本文整理汇总了TypeScript中vs/editor/common/model/textModel.TextModel.applyEdits方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextModel.applyEdits方法的具体用法?TypeScript TextModel.applyEdits怎么用?TypeScript TextModel.applyEdits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/editor/common/model/textModel.TextModel
的用法示例。
在下文中一共展示了TextModel.applyEdits方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('model insert text with one newline eventing', () => {
let e: ModelRawContentChangedEvent = null;
thisModel.onDidChangeRawContent((_e) => {
if (e !== null) {
assert.fail();
}
e = _e;
});
thisModel.applyEdits([EditOperation.insert(new Position(1, 3), ' new line\nNo longer')]);
assert.deepEqual(e, new ModelRawContentChangedEvent(
[
new ModelRawLineChanged(1, 'My new line First Line'),
new ModelRawLineChanged(1, 'My new line'),
new ModelRawLinesInserted(2, 2, ['No longer First Line']),
],
2,
false,
false
));
});
示例2: testApplyEdits
function testApplyEdits(initial: IBufferLineState[], edits: IEdit[], expected: IBufferLineState[]): void {
const initialText = initial.map(el => el.text).join('\n');
const model = new TextModel(initialText, TextModel.DEFAULT_CREATION_OPTIONS, new LanguageIdentifier('test', 0));
for (let lineIndex = 0; lineIndex < initial.length; lineIndex++) {
const lineTokens = initial[lineIndex].tokens;
const lineTextLength = model.getLineMaxColumn(lineIndex + 1) - 1;
model._tokens._setTokens(0, lineIndex, lineTextLength, TestToken.toTokens(lineTokens));
}
model.applyEdits(edits.map((ed) => ({
identifier: null,
range: ed.range,
text: ed.text,
forceMoveMarkers: false
})));
for (let lineIndex = 0; lineIndex < expected.length; lineIndex++) {
const actualLine = model.getLineContent(lineIndex + 1);
const actualTokens = model.getLineTokens(lineIndex + 1);
assert.equal(actualLine, expected[lineIndex].text);
assertLineTokens(actualTokens, expected[lineIndex].tokens);
}
}
示例3: test
test('model delete text from many lines', () => {
thisModel.applyEdits([EditOperation.delete(new Range(1, 4, 3, 5))]);
assert.equal(thisModel.getLineCount(), 3);
assert.equal(thisModel.getLineContent(1), 'My Third Line');
});
示例4: test
test('decorations are updated when inserting text inside 3', () => {
addDecoration(thisModel, 1, 1, 2, 16, 'myType');
modelHasDecoration(thisModel, 1, 1, 2, 16, 'myType');
thisModel.applyEdits([EditOperation.insert(new Position(2, 2), '\n')]);
modelHasDecoration(thisModel, 1, 1, 3, 15, 'myType');
});