瀏覽代碼

When the completer is active, complete a common subset on tab rather
than selecting the active item.

Ian Rose 6 年之前
父節點
當前提交
7849e6c549
共有 3 個文件被更改,包括 16 次插入9 次删除
  1. 6 0
      packages/completer/src/handler.ts
  2. 0 2
      packages/completer/src/model.ts
  3. 10 7
      packages/completer/src/widget.ts

+ 6 - 0
packages/completer/src/handler.ts

@@ -261,6 +261,12 @@ export class CompletionHandler implements IDisposable {
       return;
     }
 
+    // If we are currently performing a subset match,
+    // return without resetting the completer.
+    if (model.subsetMatch) {
+      return;
+    }
+
     const position = editor.getCursorPosition();
     const line = editor.getLine(position.line);
     if (!line) {

+ 0 - 2
packages/completer/src/model.ts

@@ -233,7 +233,6 @@ export class CompleterModel implements Completer.IModel {
       this._options = values;
       this._typeMap = types;
       this._orderedTypes = Private.findOrderedTypes(types);
-      this._subsetMatch = true;
     } else {
       this._options = [];
       this._typeMap = {};
@@ -358,7 +357,6 @@ export class CompleterModel implements Completer.IModel {
     if (!hard && this._subsetMatch) {
       return;
     }
-    this._subsetMatch = false;
     this._reset();
     this._stateChanged.emit(undefined);
   }

+ 10 - 7
packages/completer/src/widget.ts

@@ -265,10 +265,8 @@ export class Completer extends Widget {
 
     // If this is the first time the current completer session has loaded,
     // populate any initial subset match.
-    if (model.subsetMatch) {
+    if (!model.query) {
       const populated = this._populateSubset();
-
-      model.subsetMatch = false;
       if (populated) {
         this.update();
         return;
@@ -346,13 +344,18 @@ export class Completer extends Widget {
         if (!model) {
           return;
         }
-        model.subsetMatch = true;
         let populated = this._populateSubset();
-        model.subsetMatch = false;
+        // If there is a common subset in the options,
+        // then emit a completion signal with that subset.
+        if (model.query) {
+          model.subsetMatch = true;
+          this._selected.emit(model.query);
+          model.subsetMatch = false;
+        }
+        // If the query changed, update rendering of the options.
         if (populated) {
-          return;
+          this.update();
         }
-        this.selectActive();
         return;
       case 27: // Esc key
         event.preventDefault();