From 1518e267b659976a2166cf59b679a0b1896131ca Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Tue, 26 Jul 2016 15:59:39 +0200 Subject: [PATCH] use selected text with non empty selection, fixes #9762 --- .../editor/contrib/suggest/browser/tabCompletion.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/vs/editor/contrib/suggest/browser/tabCompletion.ts b/src/vs/editor/contrib/suggest/browser/tabCompletion.ts index aa371f14f62..db4779d664c 100644 --- a/src/vs/editor/contrib/suggest/browser/tabCompletion.ts +++ b/src/vs/editor/contrib/suggest/browser/tabCompletion.ts @@ -5,7 +5,6 @@ 'use strict'; -import * as strings from 'vs/base/common/strings'; import {KeyCode} from 'vs/base/common/keyCodes'; import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService'; import {IKeybindingService, KbExpr} from 'vs/platform/keybinding/common/keybinding'; @@ -34,12 +33,17 @@ class TabCompletionController implements editor.IEditorContribution { ) { this._snippetController = getSnippetController(editor); const hasSnippets = keybindingService.createKey(TabCompletionController.ContextKey, undefined); - this._cursorChangeSubscription = editor.onDidChangeCursorPosition(e => { + this._cursorChangeSubscription = editor.onDidChangeCursorSelection(e => { + this._currentSnippets.length = 0; - const prefix = getNonWhitespacePrefix(editor.getModel(), editor.getPosition()); + + const prefix = e.selection.isEmpty() + ? getNonWhitespacePrefix(editor.getModel(), editor.getPosition()) + : editor.getModel().getValueInRange(e.selection); + if (prefix) { snippetsRegistry.visitSnippets(editor.getModel().getModeId(), s => { - if (strings.endsWith(prefix, s.prefix)) { + if (prefix === s.prefix) { this._currentSnippets.push(s); } return true;