Bug fix in completion (#updateSelection).
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 17 Jun 2014 09:06:21 +0100
changeset 239 e1b7b5f0f4b7
parent 238 d5a32e41181f
child 240 e2277fd8f082
Bug fix in completion (#updateSelection). When selection in code completion view is updated, take in an account a key just typed. The character may not be processed (and this inserted in text) by textView's in case #updateSelection is called in CompletionController>>handleKeyPress:x:y:. so the character just pressed must be passed down (hence #updateSelectionAfterKeyPress:). Also, care for empty lines which are not even in textView's list - TextView shrinks list to last non-empty line so `textView list at: cursorCol` may lead into index out of bounds.
SmallSense__CompletionController.st
SmallSense__EditSupport.st
--- a/SmallSense__CompletionController.st	Sat Jun 14 00:35:03 2014 +0100
+++ b/SmallSense__CompletionController.st	Tue Jun 17 09:06:21 2014 +0100
@@ -93,13 +93,13 @@
             ^ true
         ].
         key isCharacter ifTrue:[
-            self updateSelection.
+            self updateSelectionAfterKeyPress: key.
         ].
     ].
     ^ super handleKeyPress:key x:x y:y
 
     "Created: / 27-09-2013 / 15:38:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 31-03-2014 / 22:55:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 17-06-2014 / 07:24:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 handleKeyPressTab
@@ -270,10 +270,24 @@
 !
 
 updateSelection
-    "Updates selection in completion view based on
-     currently typed partial text. Return true if
-     the complection window should be closed or false
-     if it shall be kept open."
+    "Updates selection in completion view based on currently typed partial 
+     text. Return true if the complection window should be closed or false
+     if it shall be kept open. "
+
+    ^ self updateSelectionAfterKeyPress: nil
+
+    "Created: / 27-09-2013 / 16:16:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (comment): / 17-06-2014 / 07:24:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+updateSelectionAfterKeyPress: keyOrNil
+    "Updates selection in completion view based on currently typed partial 
+     text. Return true if the complection window should be closed or false
+     if it shall be kept open.
+
+     If `keyOrNil` is not nil, then it's a key press that triggered the update
+     which HAS NOT YET been processed by a `editView`.
+     "
 
     | list prefix matcher1 matches1 matcher2 matches2 |
 
@@ -281,6 +295,9 @@
     matcher1 := CompletionEngine exactMatcher.
     matcher2 := CompletionEngine inexactMatcher.
     prefix := self prefixAlreadyWritten.
+    keyOrNil isCharacter ifTrue:[ 
+        prefix := prefix , keyOrNil
+    ].
 
     matches1 := list select:[:po | matcher1 value: prefix value: po stringToComplete ].
     matches1 notEmptyOrNil ifTrue:[
@@ -322,8 +339,7 @@
     ].
     ^ false.
 
-    "Created: / 27-09-2013 / 16:16:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-05-2014 / 13:57:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 17-06-2014 / 07:19:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompletionController methodsFor:'private-API'!
--- a/SmallSense__EditSupport.st	Sat Jun 14 00:35:03 2014 +0100
+++ b/SmallSense__EditSupport.st	Tue Jun 17 09:06:21 2014 +0100
@@ -351,7 +351,7 @@
 
 wordBeforeCursorConsisitingOfCharactersMatching: characterMatchBlock
     |  currentLine wordStart wordEnd |
-    currentLine := textView list at: textView cursorLine.
+    currentLine := textView list at: textView cursorLine ifAbsent:[ ^ '' ].
     currentLine isNil ifTrue:[ ^ '' ].
     wordEnd := textView cursorCol - 1.
     wordEnd > currentLine size ifTrue:[ ^ '' ].
@@ -368,7 +368,7 @@
     ^ ''
 
     "Created: / 31-03-2014 / 23:02:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 01-04-2014 / 18:00:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 17-06-2014 / 07:27:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !EditSupport methodsFor:'private-scanning'!