SmallSense__EditSupport.st
changeset 446 59afe5adfbf7
parent 445 783f2a4af9c2
child 458 de41bf2025c0
--- a/SmallSense__EditSupport.st	Wed Mar 04 06:01:34 2015 +0000
+++ b/SmallSense__EditSupport.st	Fri Mar 06 07:09:06 2015 +0000
@@ -25,7 +25,8 @@
 Object subclass:#EditSupport
 	instanceVariableNames:'textView backspaceIsUndo completionController
 		completionEnvironment snippets ignoreKeystrokes
-		ignoreKeystrokesPosition electricInsertSuppressed'
+		ignoreKeystrokesPosition ignoreKeystrokesStartLine
+		ignoreKeystrokesStartCol electricInsertSuppressed'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'SmallSense-Core-Services'
@@ -192,9 +193,13 @@
      `ignoreKeystrokeSequence` a sequenceable collection of keys (in a form
             as passed to #keyPress:x:y: method."
     
-    | lineOffset  colOffset  newCursorCol  newCursorLine  advanceCursor |
+    | lineOffset colOffset oldCursorLine oldCursorCol newCursorLine newCursorCol advanceCursor |
 
     advanceCursor := false.
+    ignoreKeystrokeSequence notNil ifTrue:[ 
+        oldCursorLine := textView cursorLine.
+        oldCursorCol := textView cursorCol.
+    ].
     offsetOrNil notNil ifTrue:[
         lineOffset := offsetOrNil isPoint ifTrue:[
                 offsetOrNil x
@@ -228,11 +233,14 @@
     ignoreKeystrokeSequence notEmptyOrNil ifTrue:[
         ignoreKeystrokes := ignoreKeystrokeSequence.
         ignoreKeystrokesPosition := 1.
+        stringOrLines isString ifTrue:[ 
+            ignoreKeystrokesStartLine := oldCursorLine.
+            ignoreKeystrokesStartCol := oldCursorCol + (stringOrLines size - ignoreKeystrokeSequence size)
+        ].
     ].
 
     "Created: / 19-01-2014 / 20:29:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 20-01-2014 / 09:24:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (format): / 22-01-2014 / 21:13:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-03-2015 / 06:29:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 electricInsert:text ignoreKeystrokes:ignore 
@@ -326,19 +334,51 @@
             ignoreKeystrokesPosition := ignoreKeystrokesPosition + 1.
             ignoreKeystrokesPosition > ignoreKeystrokes size ifTrue:[
                 "/ Nil out instvars if there's no more keys to ignore.
-                ignoreKeystrokes := ignoreKeystrokesPosition := nil.
+                ignoreKeystrokes := ignoreKeystrokesPosition := ignoreKeystrokesStartLine := ignoreKeystrokesStartCol := nil.
             ].
             ^ true.
         ] ifFalse:[
-            "/ Nil out instvars, user typed something else!!
-            ignoreKeystrokes := ignoreKeystrokesPosition := nil.
+            "/ User continued typing something else. If it *seems* to be
+            "/ thet user wanted something else, then delete the rest, i.e.,
+            "/ user typed:
+            "/ 
+            "/ th
+            "/ 
+            "/ then the machinery completed `isContext` so the text is
+            "/ 
+            "/ thisContext
+            "/ 
+            "/ and user continues typing `isValue`. In that case user wanted to
+            "/ `thisValue` instead of `thisContext` - in this case remove the rest
+            "/ of what has been completed.
+            "/ 
+            "/ However, imagine following case: user types `th` so it completes
+            "/ `thisContext` like in previous case. Now the user types . (dot).
+            "/ to end the statement. In this case, perhaps `thisContext` is what
+            "/ he needs.
+            "/ 
+            "/ How to tell between those two cases?
+            "/ 
+            "/ Currently, a simple heuristics is used - if the typed character can be
+            "/ part of an identifier, then it's the former case, otherwise assume
+            "/ the latter. We'll see.
+            "/
+            (key isCharacter and:[key isLetterOrDigit or:[key == $_]]) ifTrue:[ 
+                ignoreKeystrokesStartLine notNil ifTrue:[  
+                    textView deleteCharsAtLine: ignoreKeystrokesStartLine fromCol: ignoreKeystrokesStartCol + ignoreKeystrokesPosition - 1 toCol: ignoreKeystrokesStartCol + ignoreKeystrokes size - 1.
+                    textView setCursorLine: ignoreKeystrokesStartLine.
+                    textView setCursorCol: ignoreKeystrokesStartCol + ignoreKeystrokesPosition - (ignoreKeystrokesPosition > 1 ifTrue:[ 1 ] ifFalse:[ 0 ]).
+                ].
+            ].
+            ignoreKeystrokes := ignoreKeystrokesPosition := ignoreKeystrokesStartLine := ignoreKeystrokesStartCol := nil.
             ^ false.
         ].
     ].
     ^ false.
 
     "Created: / 20-01-2014 / 09:11:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (comment): / 11-08-2014 / 14:54:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-03-2015 / 12:47:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 06-03-2015 / 07:08:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 keyPressSpace