Workspace.st
changeset 4737 91c1c2ec2dc2
parent 4736 3a57f058b140
child 4741 289a3dde9ab8
--- a/Workspace.st	Wed Sep 04 00:57:28 2013 +0200
+++ b/Workspace.st	Wed Sep 04 19:22:04 2013 +0200
@@ -26,7 +26,7 @@
 !
 
 Object subclass:#CodeCompletionService
-	instanceVariableNames:'completionView completionProcess editView state seqNr'
+	instanceVariableNames:'completionView completionProcess editView autoSelect'
 	classVariableNames:'LastCompletions'
 	poolDictionaries:''
 	privateIn:Workspace
@@ -2198,12 +2198,25 @@
 handleKeyPress:key x:x y:y
     "return true, if I have eaten this keypress"
 
-    "/ open on CTRL-key?
+    |ch|
+
+    "/ open on CTRL- or TAB-key?
     (completionView isNil or:[completionView realized not]) ifTrue:[
-        (key == #Control_L or:[ key == #Control_R or:[ key == #Control]]) ifTrue:[
-            editView hasSelection ifFalse:[
-                UserPreferences current codeCompletionOnControlKey ifTrue:[
-                    self updateCompletionList
+        editView hasSelection ifFalse:[
+            ((ch := editView characterBeforeCursor) notNil "/ i.e. not at begin of line
+            and:[ ch isSeparator not ]) ifTrue:[
+                (key == #Control_L or:[ key == #Control_R or:[ key == #Control]]) ifTrue:[
+                    UserPreferences current codeCompletionOnControlKey ifTrue:[
+                        autoSelect := true.
+                        self updateCompletionList
+                    ]
+                ].
+                (key == #Tab) ifTrue:[
+                    UserPreferences current codeCompletionOnTabKey ifTrue:[
+                        autoSelect := true.
+                        self updateCompletionList.
+                        ^ true
+                    ].
                 ]
             ].
         ].
@@ -2220,13 +2233,17 @@
                 or:[ (key == #CursorRight)
                 or:[ ((key == #Return) and:[ completionView hasSelection ])
             ]]]]) ifTrue:[
-                "/ forward to completion view
-                completionView sensor pushUserEvent:#value for:[ completionView keyPress:key x:0 y:0 ].
-                ^ true.
+                "/ only with shift - normal user typing should not interfere with completion
+                true "editView sensor shiftDown" ifTrue:[
+                    "/ forward to completion view
+                    completionView sensor pushUserEvent:#value for:[ completionView keyPress:key x:0 y:0 ].
+                    ^ true.
+                ].
             ].
+
             (key == #Control_L or:[ key == #Control_R or:[ key == #Control]]) ifTrue:[
                 "/ CTRL is a toggle
-                self closeCompletionView.
+                self closeCompletionView.   
                 ^ true.
                 "/ ^ false
             ].
@@ -2253,6 +2270,7 @@
     ].
 
     (key == #BackSpace or:[key == #BasicBackspace]) ifTrue:[
+        autoSelect := false.
         self updateCompletionList.
         ^ self
     ].
@@ -2261,6 +2279,7 @@
         key isSeparator ifTrue:[
             self closeCompletionView
         ] ifFalse:[
+            autoSelect := false.
             self updateCompletionList.
         ].
         ^ self
@@ -2355,9 +2374,9 @@
             "/ Transcript show:'suggestions: '; showCR:suggestions.
             "/ Transcript show:'actions: '; showCR:actions.  
             editView sensor
-                pushUserEvent:#'suggestionsArrived:actions:'
+                pushUserEvent:#'suggestionsArrived:actions:autoSelect:'
                 for:self
-                withArguments:{suggestions . actions }
+                withArguments:{suggestions . actions . autoSelect }
         ] forkAt:(Processor activePriority - 1).
 !
 
@@ -2372,7 +2391,7 @@
     ].
 !
 
-suggestionsArrived:suggestions actions:actions
+suggestionsArrived:suggestions actions:actions autoSelect:autoSelectArg
     "the background process has generated some suggestions"
 
     |v list suggestionOffset keyAndSniplet lastEntryIsSniplet|
@@ -2417,7 +2436,6 @@
         self closeCompletionView.
         ^ self
     ].
-
     (v := completionView) isNil ifTrue: [
         ^ self
     ].
@@ -2438,8 +2456,10 @@
                         preselectIdx := list indexOf:(LastCompletions at:idx).
                     ].
                 ].
-                (preselectIdx isNil and:[list size == 1]) ifTrue:[
-                    preselectIdx := 1.
+                autoSelectArg ifTrue:[
+                    (preselectIdx isNil and:[list size == 1]) ifTrue:[
+                        preselectIdx := 1.
+                    ].
                 ].
 
                 v list:list. 
@@ -2508,10 +2528,10 @@
 !Workspace class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.292 2013-09-03 22:57:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.293 2013-09-04 17:22:04 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.292 2013-09-03 22:57:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.293 2013-09-04 17:22:04 cg Exp $'
 ! !