--- a/SmallSense__CompletionController.st Sat Jan 18 22:56:44 2014 +0000
+++ b/SmallSense__CompletionController.st Sat Jan 18 23:41:04 2014 +0000
@@ -3,7 +3,7 @@
"{ NameSpace: SmallSense }"
EditTextViewCompletionSupport subclass:#CompletionController
- instanceVariableNames:'support seqno'
+ instanceVariableNames:'support seqno completeIfUnambiguous'
classVariableNames:''
poolDictionaries:''
category:'SmallSense-Core'
@@ -123,10 +123,11 @@
"/ please change as required (and remove this comment)
"/ support := nil.
seqno := 0.
+ completeIfUnambiguous := UserPreferences current smallSenseCompleteIfUnambiguous.
"/ super initialize. -- commented since inherited method does nothing
- "Modified: / 03-10-2013 / 07:11:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 18-01-2014 / 23:10:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CompletionController methodsFor:'private'!
@@ -166,23 +167,39 @@
!
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."
| matches word |
word := support wordBeforeCursor.
matches := completionView list select:[:po | po stringToComplete startsWith: word ].
matches notEmptyOrNil ifTrue:[
- completionView selection: (matches inject: matches anElement into:[:mostrelevant :each |
- each relevance > mostrelevant relevance
- ifTrue:[each]
- ifFalse:[mostrelevant]
- ]).
+ matches size == 1 ifTrue:[
+ completionView selection: matches anElement.
+ completeIfUnambiguous ifTrue:[
+ self complete.
+ ^ true
+ ]
+ ] ifFalse:[
+ | selection |
+
+ selection := matches inject: matches anElement into:[:mostrelevant :each |
+ each relevance > mostrelevant relevance
+ ifTrue:[each]
+ ifFalse:[mostrelevant]
+ ].
+ completionView selection: selection.
+ ]
] ifFalse:[
completionView selection: nil.
].
+ ^ false.
"Created: / 27-09-2013 / 16:16:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 18-01-2014 / 22:51:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (format): / 18-01-2014 / 23:24:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CompletionController methodsFor:'private-API'!
@@ -258,8 +275,9 @@
].
topView origin:movePos.
"/ topView resizeToFit.
- self updateSelection.
- topView open.
+ self updateSelection ifFalse:[
+ topView open.
+ ].
] ifFalse:[
completionView list:list.
self updateSelection.
@@ -271,7 +289,7 @@
].
"Created: / 27-09-2013 / 14:01:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 18-01-2014 / 22:23:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 18-01-2014 / 23:24:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
updateCompletions: completionResult sequence: sequence