@@ -13,7 +13,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
1313import { IThreadService } from 'vs/workbench/services/thread/common/threadService' ;
1414import { ExtHostDocuments , ExtHostDocumentData } from 'vs/workbench/api/node/extHostDocuments' ;
1515import { Selection , Range , Position , EndOfLine , TextEditorRevealType , TextEditorSelectionChangeKind , TextEditorLineNumbersStyle , SnippetString } from './extHostTypes' ;
16- import { ISingleEditOperation , TextEditorCursorStyle } from 'vs/editor/common/editorCommon' ;
16+ import { ISingleEditOperation , TextEditorCursorStyle , IRange } from 'vs/editor/common/editorCommon' ;
1717import { IResolvedTextEditorConfiguration , ISelectionChangeEvent , ITextEditorConfigurationUpdate } from 'vs/workbench/api/node/mainThreadEditorsTracker' ;
1818import * as TypeConverters from './extHostTypeConverters' ;
1919import { MainContext , MainThreadEditorsShape , ExtHostEditorsShape , ITextEditorAddData , ITextEditorPositionData } from './extHost.protocol' ;
@@ -620,17 +620,32 @@ class ExtHostTextEditor implements vscode.TextEditor {
620620 } ) ;
621621 }
622622
623- insertSnippet ( snippet : SnippetString , where ?: Selection | Selection [ ] , options : { undoStopBefore : boolean ; undoStopAfter : boolean ; } = { undoStopBefore : true , undoStopAfter : true } ) : Thenable < boolean > {
623+ insertSnippet ( snippet : SnippetString , where ?: Position | Position [ ] | Range | Range [ ] , options : { undoStopBefore : boolean ; undoStopAfter : boolean ; } = { undoStopBefore : true , undoStopAfter : true } ) : Thenable < boolean > {
624+
625+ let ranges : IRange [ ] ;
624626
625627 if ( ! where || ( Array . isArray ( where ) && where . length === 0 ) ) {
626- where = this . _selections ;
627- }
628+ ranges = this . _selections . map ( TypeConverters . fromRange ) ;
629+
630+ } else if ( where instanceof Position ) {
631+ const { lineNumber, column} = TypeConverters . fromPosition ( where ) ;
632+ ranges = [ { startLineNumber : lineNumber , startColumn : column , endLineNumber : lineNumber , endColumn : column } ] ;
628633
629- const selections = Array . isArray ( where )
630- ? where . map ( TypeConverters . fromSelection )
631- : [ TypeConverters . fromSelection ( where ) ] ;
634+ } else if ( where instanceof Range ) {
635+ ranges = [ TypeConverters . fromRange ( where ) ] ;
636+ } else {
637+ ranges = [ ] ;
638+ for ( const posOrRange of where ) {
639+ if ( posOrRange instanceof Range ) {
640+ ranges . push ( TypeConverters . fromRange ( posOrRange ) ) ;
641+ } else {
642+ const { lineNumber, column} = TypeConverters . fromPosition ( posOrRange ) ;
643+ ranges . push ( { startLineNumber : lineNumber , startColumn : column , endLineNumber : lineNumber , endColumn : column } ) ;
644+ }
645+ }
646+ }
632647
633- return this . _proxy . $tryInsertSnippet ( this . _id , snippet . value , selections , options ) ;
648+ return this . _proxy . $tryInsertSnippet ( this . _id , snippet . value , ranges , options ) ;
634649 }
635650
636651 // ---- util
0 commit comments