vscode#TextDocumentContentChangeEvent TypeScript Examples
The following examples show how to use
vscode#TextDocumentContentChangeEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: text-utils.ts From vscode-stories with MIT License | 8 votes |
executeChanges = (
textChunks: string[],
changeBlock: TextDocumentContentChangeEvent[]
) => {
for (const change of changeBlock) {
if (change.text === "") {
deleteTextChunk(textChunks, change.range[0], change.range[1]);
} else if (change.rangeLength === 0) {
insertTextChunk(textChunks, change.range[0], change.text);
} else {
replaceTextChunk(
textChunks,
change.range[0],
change.range[1],
change.text
);
}
}
}
Example #2
Source File: DoComment.ts From vscode-alxmldocumentation with MIT License | 5 votes |
/**
* Do comment on current event.
* @param activeEditor TextEditor object.
* @param event TextDocumentContentChangeEvent object.
*/
public async DoComment(activeEditor: TextEditor, event: TextDocumentContentChangeEvent) {
this.event = event;
this.vsCodeApi = new VSCodeApi(activeEditor);
this.activeEditor = activeEditor;
if ((this.event === undefined) || (this.event === null) || (this.activeEditor === undefined) || (this.activeEditor === null)) {
return;
}
// if action comes from snippet an additional '/// ' is included
var doubleDocCommentIndex = this.vsCodeApi.ReadLineAtCurrent().indexOf('/// /// ');
if (doubleDocCommentIndex !== -1) {
const position: Position = this.vsCodeApi.GetPosition(this.vsCodeApi.GetActiveLine(), doubleDocCommentIndex);
const anchor: Position = this.vsCodeApi.GetPosition(position.line, position.character + 4);
const replaceSelection = this.vsCodeApi.GetSelectionByPosition(anchor, position);
this.activeEditor.edit((editBuilder) => {
editBuilder.replace(replaceSelection, '');
});
}
// If we're not we in a XML documentation line
if (!(this.vsCodeApi.ReadLine(this.vsCodeApi.GetActiveLine()).trim().startsWith('///'))) {
if (this.event.text !== '/') {
return;
}
}
if (!this.IsDoCommentTrigger()) {
return;
}
if (this.isEnterKey) {
var indent = StringUtil.GetIndentSpaces(this.vsCodeApi.ReadLine(this.vsCodeApi.GetActiveLine()).indexOf('///'));
const position: Position = this.vsCodeApi.GetActivePosition();
const anchor: Position = this.vsCodeApi.GetPosition(this.vsCodeApi.GetNextLine(), indent.length);
const replaceSelection = this.vsCodeApi.GetSelectionByPosition(anchor, position);
this.activeEditor.edit((editBuilder) => {
editBuilder.replace(replaceSelection, `\n${indent}/// `);
});
return;
}
if (this.vsCodeApi.ReadLine(this.vsCodeApi.GetNextLine()).trim().startsWith('///')) {
return;
}
if (!Configuration.DirectDocumentationIsEnabled(this.activeEditor.document.uri)) {
return;
}
await this.WriteDocString();
}
Example #3
Source File: DoComment.ts From vscode-alxmldocumentation with MIT License | 5 votes |
private event!: TextDocumentContentChangeEvent;
Example #4
Source File: split-provider.ts From plugin-vscode with Apache License 2.0 | 5 votes |
public updateDocument(event: TextDocumentChangeEvent) {
const editor = window.activeTextEditor;
if (!editor || !editor.document.fileName.endsWith('.bal') || event.contentChanges.length === 0) {
return;
}
let documentChange: TextDocumentContentChangeEvent | undefined;
event.contentChanges.forEach(change => {
if (change.text.startsWith(newLine)) {
documentChange = change;
}
});
if (!documentChange) {
return;
}
const range: Range = documentChange!.range;
if (this instanceof BallerinaExtension) {
if (!this.langClient) {
return;
}
const extension: BallerinaExtension = this;
this.langClient.getSyntaxTreeNode({
documentIdentifier: {
uri: editor.document.uri.toString()
},
range: {
start: {
line: range.start.line,
character: range.start.character
},
end: {
line: range.end.line,
character: range.end.character
}
}
}).then((response) => {
if (!response.kind) {
return;
}
if (response.kind === STRING_LITERAL) {
sendTelemetryEvent(extension, TM_EVENT_STRING_SPLIT, CMP_STRING_SPLIT);
editor.edit(editBuilder => {
const startPosition = new Position(range.start.line, range.start.character);
const nextLinePosition = new Position(range.start.line + 1, documentChange!.text.length - 1);
const endPosition = new Position(range.end.line + 1, documentChange!.text.indexOf('\n'));
editBuilder.insert(startPosition, `\" +${newLine}`);
editBuilder.insert(nextLinePosition, `\"`);
editBuilder.delete(new Range(startPosition, endPosition));
});
}
});
}
}
Example #5
Source File: q-dict.ts From vscode-q with MIT License | 5 votes |
private _onDidChangeTextDocument: EventEmitter<TextDocumentContentChangeEvent> = new EventEmitter<TextDocumentContentChangeEvent>();
Example #6
Source File: q-dict.ts From vscode-q with MIT License | 5 votes |
readonly onDidChangeTextDocument: Event<TextDocumentContentChangeEvent> = this._onDidChangeTextDocument.event;