本文整理匯總了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');
});