class: Workspace
authorClaus Gittinger <cg@exept.de>
Tue, 24 Sep 2013 17:21:54 +0200
changeset 4784 c8866890363a
parent 4783 b24f6d37fa8c
child 4785 7b72e2622200
class: Workspace if there is only a single suggestion AND the completion was via TAB key, immediately insert it.
Workspace.st
--- a/Workspace.st	Tue Sep 24 11:21:06 2013 +0200
+++ b/Workspace.st	Tue Sep 24 17:21:54 2013 +0200
@@ -2483,12 +2483,11 @@
     (v := completionView) isNil ifTrue: [
         ^ self
     ].
-    v topView open.
 
     v sensor
         pushUserEvent:#value
         for:[
-            |top idx preselectIdx|
+            |top idx preselectIdx performCompletion|
 
             (v == completionView) ifTrue: [
                 top := v topView.
@@ -2509,7 +2508,7 @@
                     |pref|
 
                     pref := suggestions at:preselectIdx.
-                    "/ for now, do not move to fron (action may need the index)
+                    "/ for now, do not move to front (action needs the index)
                     suggestions at:preselectIdx put:(pref allBold).
 "/                    suggestions removeAtIndex:preselectIdx.                    
 "/                    suggestions addFirst:(pref allBold).
@@ -2519,34 +2518,7 @@
 "/                    ]
                 ].
 
-                v list:suggestions 
-                        expandTabs:false scanForNonStrings:false
-                        includesNonStrings:false redraw:true.
-
-                implementations notNil ifTrue:[
-                    implementations keysAndValuesDo:[:idx :impls |
-                        |implsMenu|
-
-                        impls notEmptyOrNil ifTrue:[
-                            implsMenu := Menu new.
-                            impls do:[:each |
-                                implsMenu addItem:(MenuItem new label:each name).
-                            ].
-                            v subMenuAt:idx put:implsMenu
-                        ].
-                    ].
-                ].
-
-                v enable:true.
-                preselectIdx notNil ifTrue:[
-                    false ifTrue:[
-                        "/ very disturbing!!
-                        v selection:preselectIdx.
-                    ].
-                ].
-                v extent:completionView preferredExtentForContents.
-
-                v action:
+                performCompletion :=
                     [:selectedListIndex | 
                         |indexInSuggestions|
 
@@ -2554,11 +2526,7 @@
                         indexInSuggestions := selectedListIndex - suggestionOffset.
                         (selectedListIndex == indexOfSnippet) ifTrue:[
                             "/ replace the sniplet
-                            editView sensor
-                                pushUserEvent:#value
-                                for:[
-                                    editView expandAbbreviation
-                                ]
+                            editView sensor pushUserEvent:#expandAbbreviation for:editView
                         ] ifFalse:[
                             LastCompletions isNil ifTrue:[
                                 LastCompletions := OrderedCollection new.
@@ -2576,20 +2544,48 @@
                                 ].
                             ].
                         ].
-                        "/ no, user has made his choice; so don't show more suggestions
-"/                        editView sensor
-"/                            pushUserEvent:#value
-"/                            for:[
-"/                                self updateCompletionList
-"/                            ]
+                        "/ disabled - user has made his choice; so don't show more suggestions
+                        "/ editView sensor pushUserEvent:#updateCompletionList for:self
                     ].
 
-                (top ~~ v) ifTrue:[
-                    top resizeToFit.
-                    top bottom > v device usableHeight ifTrue:[
-                        top origin:((top origin x) @ (v device usableHeight - v height)).
+                ((suggestions size == 1) and:[preselectIdx == 1]) ifTrue:[
+                    "/ do it, right here and now
+                    performCompletion value:preselectIdx.
+                ] ifFalse:[
+                    top open.
+                    v list:suggestions 
+                            expandTabs:false scanForNonStrings:false
+                            includesNonStrings:false redraw:true.
+
+                    implementations notNil ifTrue:[
+                        implementations keysAndValuesDo:[:idx :impls |
+                            |implsMenu|
+
+                            impls notEmptyOrNil ifTrue:[
+                                implsMenu := Menu new.
+                                impls do:[:each |
+                                    implsMenu addItem:(MenuItem new label:each name).
+                                ].
+                                v subMenuAt:idx put:implsMenu
+                            ].
+                        ].
                     ].
-                    top raise.
+
+                    v enable:true.
+                    preselectIdx notNil ifTrue:[
+                        "/ very disturbing!!
+                        v selection:preselectIdx.
+                    ].
+                    v extent:completionView preferredExtentForContents.
+                    v action:performCompletion.
+
+                    (top ~~ v) ifTrue:[
+                        top resizeToFit.
+                        top bottom > v device usableHeight ifTrue:[
+                            top origin:((top origin x) @ (v device usableHeight - v height)).
+                        ].
+                        top raise.
+                    ]
                 ]
             ]
         ]
@@ -2604,10 +2600,10 @@
 !Workspace class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.307 2013-09-24 09:21:06 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.308 2013-09-24 15:21:54 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.307 2013-09-24 09:21:06 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.308 2013-09-24 15:21:54 cg Exp $'
 ! !