mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
Insert snippet API changes.
This commit is contained in:
@@ -12,7 +12,6 @@ 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';
|
||||
@@ -60,12 +59,19 @@ export enum TextEditorRevealType {
|
||||
InCenterIfOutsideViewport = 2
|
||||
}
|
||||
|
||||
export interface IApplyEditsOptions {
|
||||
export interface IUndoStopOptions {
|
||||
undoStopBefore: boolean;
|
||||
undoStopAfter: boolean;
|
||||
}
|
||||
|
||||
export interface IApplyEditsOptions extends IUndoStopOptions {
|
||||
setEndOfLine: EndOfLine;
|
||||
}
|
||||
|
||||
export interface IInsertSnippetOptions extends IUndoStopOptions {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Text Editor that is permanently bound to the same model.
|
||||
* It can be bound or not to a CodeEditor.
|
||||
@@ -386,24 +392,22 @@ export class MainThreadTextEditor {
|
||||
return false;
|
||||
}
|
||||
|
||||
insertSnippet(template: string, posOrRange: EditorCommon.IPosition | EditorCommon.IRange) {
|
||||
insertSnippet(template: string, opts: IInsertSnippetOptions) {
|
||||
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.insertSnippetWithReplaceRange(template, range);
|
||||
if (opts.undoStopBefore) {
|
||||
this._codeEditor.pushUndoStop();
|
||||
}
|
||||
else {
|
||||
snippetController.insertSnippet(template, 0, 0);
|
||||
|
||||
snippetController.insertSnippet(template, 0, 0);
|
||||
|
||||
if (opts.undoStopAfter) {
|
||||
this._codeEditor.pushUndoStop();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user