Yet another fix in completion view.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 04 Apr 2014 11:52:33 +0200
changeset 189 8c32268000c5
parent 188 cfd4d30fcad7
child 190 c4dbecf1d9a7
Yet another fix in completion view. First, pre-select item that matches typed prefix exactly, if none, filter using similarity matching. If none matches exactly, do not autocomplete.
SmallSense__CompletionController.st
--- a/SmallSense__CompletionController.st	Thu Apr 03 23:06:01 2014 +0200
+++ b/SmallSense__CompletionController.st	Fri Apr 04 11:52:33 2014 +0200
@@ -231,25 +231,42 @@
      the complection window should be closed or false
      if it shall be kept open."
 
-    | prefix matcher matches |
+    | list prefix matcher matches1 matches2 |
 
+    list := completionView list.
     matcher := CompletionEngine matcher.
     prefix := support wordBeforeCursor.
-    matches := completionView list select:[:po | matcher value: prefix value: po stringToComplete ].
-    matches notEmptyOrNil ifTrue:[
-        matches size == 1 ifTrue:[
-            completionView selection:  matches anElement.
+
+    matches1 := list select:[:po | po stringToComplete startsWith: prefix string ].
+    matches1 notEmptyOrNil ifTrue:[
+        matches1 size == 1 ifTrue:[
+            completionView selection:  matches1 anElement.
             completeIfUnambiguous ifTrue:[
-                "/ Do complete only if prefix matches!!
-                (matches anElement stringToComplete startsWith: prefix) ifTrue:[
-                    self complete.
-                    ^ true
-                ].
-            ]
+                self complete.
+                ^ true
+            ].
+            ^ false
         ] ifFalse:[
             | selection |
 
-            selection := matches inject: matches anElement into:[:mostrelevant :each |
+            selection := matches1 inject: matches1 anElement into:[:mostrelevant :each |
+                each relevance > mostrelevant relevance 
+                    ifTrue:[each]
+                    ifFalse:[mostrelevant]
+            ].
+            completionView selection: selection.
+            ^ false.
+        ]
+    ].
+
+    matches2 := completionView list select:[:po | matcher value: prefix value: po stringToComplete ].
+    matches2 notEmptyOrNil ifTrue:[
+        matches2 size == 1 ifTrue:[
+            completionView selection:  matches2 anElement.
+        ] ifFalse:[
+            | selection |
+
+            selection := matches2 inject: matches2 anElement into:[:mostrelevant :each |
                 each relevance > mostrelevant relevance 
                     ifTrue:[each]
                     ifFalse:[mostrelevant]
@@ -262,7 +279,7 @@
     ^ false.
 
     "Created: / 27-09-2013 / 16:16:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-04-2014 / 22:42:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 03-04-2014 / 23:57:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompletionController methodsFor:'private-API'!