mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
Adding insertSnippet to TextEditor extension API.
This commit is contained in:
@@ -12,8 +12,10 @@ import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
import { IdGenerator } from 'vs/base/common/idGenerator';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { SnippetController } from 'vs/editor/contrib/snippet/common/snippetController';
|
||||
import { EndOfLine, TextEditorLineNumbersStyle } from 'vs/workbench/api/node/extHostTypes';
|
||||
|
||||
export interface ITextEditorConfigurationUpdate {
|
||||
@@ -383,6 +385,29 @@ export class MainThreadTextEditor {
|
||||
console.warn('applyEdits on invisible editor');
|
||||
return false;
|
||||
}
|
||||
|
||||
insertSnippet(template: string, posOrRange: EditorCommon.IPosition | EditorCommon.IRange) {
|
||||
const snippetController = SnippetController.get(this._codeEditor);
|
||||
if (snippetController.inSnippetMode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const range = Range.isIRange(posOrRange) ? Range.lift(posOrRange) : null;
|
||||
const position = Position.isIPosition(posOrRange) ? Position.lift(posOrRange) : range.getStartPosition();
|
||||
|
||||
this._codeEditor.setPosition(position);
|
||||
this._codeEditor.revealLine(position.lineNumber);
|
||||
this._codeEditor.focus();
|
||||
|
||||
if (range) {
|
||||
snippetController.insertSnippet(template, 0, 0);
|
||||
}
|
||||
else {
|
||||
snippetController.insertSnippetWithReplaceRange(template, range);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user