SmallSense__CompletionController.st
author Jan Vrany <jan.vrany@labware.com>
Thu, 01 Jun 2023 20:20:33 +0100
changeset 1149 33f8a8571e92
parent 1146 fe97cb7caab4
permissions -rw-r--r--
Fix class selection drop-in dialog Commit 93164087c56a added class selection dialog to SmallSense's `DialogBox`. This commit selever bugs in the implementation.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
252
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
     1
"
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
     2
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
374
e65bd2bf892a Updated copyright notice.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 285
diff changeset
     3
Copyright (C) 2013-2015 Jan Vrany
1072
a44c741ee5ef Copyright updates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1071
diff changeset
     4
Copyright (C) 2014 Claus Gittinger
a44c741ee5ef Copyright updates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1071
diff changeset
     5
Copyright (C) 2018 Jan Vrany
1122
936418b830a2 Fix invalid completion when tab is pressed and completion is *UN*ambiguous
Jan Vrany <jan.vrany@labware.com>
parents: 1072
diff changeset
     6
Copyright (C) 2020 LabWare
1146
fe97cb7caab4 Call `#setForegroundWindow` on application window when completion view closes
Jan Vrany <jan.vrany@labware.com>
parents: 1122
diff changeset
     7
Copyright (C) 2023 LabWare
252
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
     8
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
     9
This library is free software; you can redistribute it and/or
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    10
modify it under the terms of the GNU Lesser General Public
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    11
License as published by the Free Software Foundation; either
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    12
version 2.1 of the License. 
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    13
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    14
This library is distributed in the hope that it will be useful,
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    15
but WITHOUT ANY WARRANTY; without even the implied warranty of
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    17
Lesser General Public License for more details.
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    18
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    19
You should have received a copy of the GNU Lesser General Public
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    20
License along with this library; if not, write to the Free Software
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    22
"
249
8bc64027b189 Package renamed to stx:goodies/smallsense
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 245
diff changeset
    23
"{ Package: 'stx:goodies/smallsense' }"
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
"{ NameSpace: SmallSense }"
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
EditTextViewCompletionSupport subclass:#CompletionController
455
f1cd6e210528 Bugfix: do not cache #completeIfUnambiguous, always ask preferences.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 445
diff changeset
    28
	instanceVariableNames:'support seqno'
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
	classVariableNames:''
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
	poolDictionaries:''
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
	category:'SmallSense-Core'
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
252
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    34
!CompletionController class methodsFor:'documentation'!
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    35
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    36
copyright
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    37
"
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    38
stx:goodies/smallsense - A productivity plugin for Smalltalk/X IDE
374
e65bd2bf892a Updated copyright notice.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 285
diff changeset
    39
Copyright (C) 2013-2015 Jan Vrany
1072
a44c741ee5ef Copyright updates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1071
diff changeset
    40
Copyright (C) 2014 Claus Gittinger
a44c741ee5ef Copyright updates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1071
diff changeset
    41
Copyright (C) 2018 Jan Vrany
1122
936418b830a2 Fix invalid completion when tab is pressed and completion is *UN*ambiguous
Jan Vrany <jan.vrany@labware.com>
parents: 1072
diff changeset
    42
Copyright (C) 2020 LabWare
1146
fe97cb7caab4 Call `#setForegroundWindow` on application window when completion view closes
Jan Vrany <jan.vrany@labware.com>
parents: 1122
diff changeset
    43
Copyright (C) 2023 LabWare
252
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    44
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    45
This library is free software; you can redistribute it and/or
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    46
modify it under the terms of the GNU Lesser General Public
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    47
License as published by the Free Software Foundation; either
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    48
version 2.1 of the License. 
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    49
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    50
This library is distributed in the hope that it will be useful,
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    51
but WITHOUT ANY WARRANTY; without even the implied warranty of
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    52
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    53
Lesser General Public License for more details.
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    54
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    55
You should have received a copy of the GNU Lesser General Public
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    56
License along with this library; if not, write to the Free Software
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    57
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    58
"
feba6ee5c814 Added copyright notice and license information (LGPL2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 249
diff changeset
    59
! !
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
    60
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
    61
!CompletionController class methodsFor:'instance creation'!
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
    62
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
    63
new
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
    64
    "return an initialized instance"
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
    65
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
    66
    ^ self basicNew initialize.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
    67
! !
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
    68
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
!CompletionController methodsFor:'accessing'!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
218
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    71
completionEngine
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    72
    | engineClass |
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    73
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    74
    engineClass := self completionEngineClass.
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    75
    ^ engineClass notNil 
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    76
        ifTrue:[ engineClass new ]
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    77
        ifFalse:[ nil ].
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    78
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    79
    "Created: / 18-05-2014 / 11:58:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    80
!
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    81
1070
031924a79f90 Issue #176: fix handling of keyboard events when completion view has focus.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 455
diff changeset
    82
editView
031924a79f90 Issue #176: fix handling of keyboard events when completion view has focus.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 455
diff changeset
    83
    ^ editView
031924a79f90 Issue #176: fix handling of keyboard events when completion view has focus.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 455
diff changeset
    84
!
031924a79f90 Issue #176: fix handling of keyboard events when completion view has focus.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 455
diff changeset
    85
218
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    86
environment
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    87
    ^ support notNil 
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    88
        ifTrue:[support environment]
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    89
        ifFalse:[Smalltalk].
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    90
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    91
    "Created: / 18-05-2014 / 11:53:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    92
!
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
    93
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    94
support
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    95
    ^ support
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    96
!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    97
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    98
support:anEditSupport
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    99
    support := anEditSupport.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   100
! !
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   101
218
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   102
!CompletionController methodsFor:'accessing-classes'!
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   103
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   104
completionEngineClass
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   105
    ^ support notNil 
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   106
        ifTrue:[ support completionEngineClass ]
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   107
        ifFalse:[ nil ].
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   108
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   109
    "Created: / 18-05-2014 / 11:55:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   110
! !
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   111
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   112
!CompletionController methodsFor:'events'!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   113
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   114
handleKeyPress:key x:x y:y
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   115
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   116
    key == #Control_L ifTrue:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   117
        completionView notNil ifTrue:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   118
            ^ false.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   119
        ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   120
    ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   121
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   122
    key == #CodeCompletion  ifTrue: [
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   123
        autoSelect := true.    
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   124
        self startCompletionProcess.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   125
        ^ true
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   126
    ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   127
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   128
    (key == #BackSpace or:[key == #BasicBackspace]) ifTrue:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   129
        | c |
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   130
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   131
        c := editView characterBeforeCursor.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   132
        (c notNil and:[c isAlphaNumeric]) ifTrue:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   133
             ^ false
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   134
        ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   135
    ].     
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   136
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   137
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   138
    completionView notNil ifTrue:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   139
        (key == #Return and:[completionView hasSelection]) ifTrue:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   140
            self complete.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   141
            ^ true.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   142
        ].
185
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   143
        key == #Tab ifTrue:[ 
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   144
            self handleKeyPressTab.  
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   145
            ^ true
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   146
        ].
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   147
        key isCharacter ifTrue:[
241
174331ea79a5 Oops, fix for previous commit: avoid duplicate characters inserted when completion is unambiguous.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 239
diff changeset
   148
            (self updateSelectionAfterKeyPress: key) ifTrue:[ 
174331ea79a5 Oops, fix for previous commit: avoid duplicate characters inserted when completion is unambiguous.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 239
diff changeset
   149
                ^ true
174331ea79a5 Oops, fix for previous commit: avoid duplicate characters inserted when completion is unambiguous.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 239
diff changeset
   150
            ].
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   151
        ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   152
    ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   153
    ^ super handleKeyPress:key x:x y:y
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   154
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   155
    "Created: / 27-09-2013 / 15:38:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
241
174331ea79a5 Oops, fix for previous commit: avoid duplicate characters inserted when completion is unambiguous.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 239
diff changeset
   156
    "Modified: / 18-06-2014 / 10:17:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
185
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   157
!
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   158
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   159
handleKeyPressTab
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   160
    "Tab has been pressed, try to complete longest common prefix"
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   161
1122
936418b830a2 Fix invalid completion when tab is pressed and completion is *UN*ambiguous
Jan Vrany <jan.vrany@labware.com>
parents: 1072
diff changeset
   162
    | prefix matching longest minlen |
185
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   163
221
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   164
    prefix := self prefixAlreadyWritten.
185
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   165
    matching := OrderedCollection new.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   166
    minlen := SmallInteger maxVal.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   167
    completionView list do:[:po |
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   168
        | s |
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   169
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   170
        s := po stringToComplete.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   171
        (s startsWith: prefix) ifTrue:[
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   172
            matching add: po -> s.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   173
            minlen := minlen min: s size.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   174
        ].
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   175
    ].
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   176
    matching isEmpty ifTrue:[
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   177
        completionView flash.
1122
936418b830a2 Fix invalid completion when tab is pressed and completion is *UN*ambiguous
Jan Vrany <jan.vrany@labware.com>
parents: 1072
diff changeset
   178
        ^ self.
185
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   179
    ].
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   180
    matching size == 1 ifTrue:[
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   181
        self complete: matching first key.
1122
936418b830a2 Fix invalid completion when tab is pressed and completion is *UN*ambiguous
Jan Vrany <jan.vrany@labware.com>
parents: 1072
diff changeset
   182
        ^ self.
185
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   183
    ].
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   184
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   185
    longest := String streamContents:[:s |
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   186
        | i |
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   187
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   188
        s nextPutAll: prefix.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   189
        i := prefix size + 1.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   190
        [ i <= minlen ] whileTrue:[
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   191
            | c |
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   192
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   193
            c := matching first value at: i.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   194
            (matching allSatisfy:[:e|(e value at: i) == c]) ifTrue:[
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   195
                s nextPut:c.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   196
                i := i + 1.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   197
            ] ifFalse:[
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   198
                "/ terminate the loop    
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   199
                i := minlen + 2.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   200
            ]
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   201
        ]
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   202
    ].
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   203
    longest size = prefix size ifTrue:[
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   204
        completionView flash.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   205
        ^self.
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   206
    ].
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   207
    editView insertStringAtCursor:(longest copyFrom: prefix size + 1).
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   208
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   209
    "Created: / 31-03-2014 / 22:55:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
221
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   210
    "Modified: / 18-05-2014 / 13:55:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1122
936418b830a2 Fix invalid completion when tab is pressed and completion is *UN*ambiguous
Jan Vrany <jan.vrany@labware.com>
parents: 1072
diff changeset
   211
    "Modified: / 12-06-2020 / 22:05:10 / Jan Vrany <jan.vrany@labware.com>"
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   212
!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   213
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   214
postKeyPress:key
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   215
    seqno := seqno + 1.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   216
    seqno == SmallInteger maxVal ifTrue:[
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   217
        seqno := 0.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   218
    ].
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   219
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   220
    UserPreferences current immediateCodeCompletion ifFalse:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   221
        "/ only update, if already open
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   222
        completionView isNil ifTrue:[^ self].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   223
    ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   224
198
a199868d1eab Do not close completion view when backspace is pressed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 192
diff changeset
   225
"/    (key == #BackSpace or:[key == #BasicBackspace]) ifTrue:[
a199868d1eab Do not close completion view when backspace is pressed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 192
diff changeset
   226
"/        self closeCompletionView.
a199868d1eab Do not close completion view when backspace is pressed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 192
diff changeset
   227
"/        ^ self
a199868d1eab Do not close completion view when backspace is pressed
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 192
diff changeset
   228
"/    ].
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   229
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   230
    key isCharacter ifTrue:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   231
        key isLetterOrDigit not ifTrue:[
221
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   232
            "/ Hack for Java - should be delegated to completion engine    
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   233
            (key == $. and:[support notNil and:[ support language isJavaLike ]]) ifTrue:[ 
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   234
                ^ self
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   235
            ].
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   236
            self closeCompletionView
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   237
        ] ifFalse:[
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   238
            | c |
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   239
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   240
            c := editView characterBeforeCursor.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   241
            (c notNil and:[c isLetterOrDigit]) ifTrue:[
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   242
                c := editView characterUnderCursor.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   243
                c isSeparator ifTrue:[
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   244
                    autoSelect := false.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   245
                    self updateCompletionList.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   246
                ].
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   247
            ]
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   248
        ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   249
        ^ self
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   250
    ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   251
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   252
    "Created: / 28-09-2013 / 00:21:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
221
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   253
    "Modified: / 18-05-2014 / 13:53:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   254
! !
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   255
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   256
!CompletionController methodsFor:'initialization'!
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   257
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   258
initialize
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   259
    "Invoked when a new instance is created."
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   260
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   261
    "/ please change as required (and remove this comment)
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   262
    "/ support := nil.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   263
    seqno := 0.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   264
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   265
    "/ super initialize.   -- commented since inherited method does nothing
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   266
455
f1cd6e210528 Bugfix: do not cache #completeIfUnambiguous, always ask preferences.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 445
diff changeset
   267
    "Modified: / 02-05-2015 / 22:07:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   268
! !
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   269
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   270
!CompletionController methodsFor:'private'!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   271
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   272
complete
185
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   273
    self complete: completionView selection.
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   274
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   275
    "Created: / 27-09-2013 / 15:38:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
185
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   276
    "Modified: / 31-03-2014 / 23:22:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   277
!
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   278
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   279
complete: item
274
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   280
    ^ self complete: item afterKeyPress: nil
185
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   281
75738108cc3f Support for Tab in code completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 178
diff changeset
   282
    "Created: / 31-03-2014 / 23:21:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
274
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   283
    "Modified: / 11-08-2014 / 14:53:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   284
!
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   285
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   286
complete: item afterKeyPress: keyOrNil
285
a5640bc14376 Small fix or issue#10: do not flush key events upon completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 283
diff changeset
   287
     self closeCompletionView.
a5640bc14376 Small fix or issue#10: do not flush key events upon completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 283
diff changeset
   288
     item insert.
a5640bc14376 Small fix or issue#10: do not flush key events upon completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 283
diff changeset
   289
     keyOrNil notNil ifTrue:[  
a5640bc14376 Small fix or issue#10: do not flush key events upon completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 283
diff changeset
   290
         support keyPressIgnored.
a5640bc14376 Small fix or issue#10: do not flush key events upon completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 283
diff changeset
   291
     ].
274
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   292
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   293
    "Created: / 11-08-2014 / 14:53:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   294
!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   295
221
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   296
prefixAlreadyWritten
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   297
    | list first |
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   298
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   299
    completionView notNil ifTrue:[ 
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   300
        list := completionView list.
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   301
        list notEmptyOrNil ifTrue:[ 
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   302
            first := list first.
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   303
            (completionView list allSatisfy:[:e | e class == first class ]) ifTrue:[ 
245
172822a63cff Fix in CompletionController>>prefixAlreadyWritten - let the first PO answer the prefix written...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 241
diff changeset
   304
                ^ first stringAlreadyWritten 
221
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   305
            ]
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   306
        ]
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   307
    ].
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   308
    ^ support wordBeforeCursor string .
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   309
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   310
    "Created: / 18-05-2014 / 13:55:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
245
172822a63cff Fix in CompletionController>>prefixAlreadyWritten - let the first PO answer the prefix written...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 241
diff changeset
   311
    "Modified: / 24-06-2014 / 11:40:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
221
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   312
!
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   313
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   314
stopCompletionProcess
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   315
    "kill any background completion process"
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   316
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   317
    editView sensor flushUserEventsFor: self.     
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   318
    super stopCompletionProcess
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   319
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   320
    "Created: / 02-10-2013 / 15:09:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   321
    "Modified: / 03-10-2013 / 11:03:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   322
!
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   323
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   324
updateCompletionList
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   325
    "called for keypress events"
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   326
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   327
    completionView isNil ifTrue:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   328
        super updateCompletionList
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   329
    ] ifFalse:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   330
         self updateSelection.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   331
    ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   332
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   333
    "Created: / 27-09-2013 / 15:58:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   334
    "Modified: / 28-09-2013 / 00:15:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   335
!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   336
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   337
updateSelection
239
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   338
    "Updates selection in completion view based on currently typed partial 
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   339
     text. Return true if the complection window should be closed or false
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   340
     if it shall be kept open. "
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   341
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   342
    ^ self updateSelectionAfterKeyPress: nil
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   343
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   344
    "Created: / 27-09-2013 / 16:16:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   345
    "Modified (comment): / 17-06-2014 / 07:24:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   346
!
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   347
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   348
updateSelectionAfterKeyPress: keyOrNil
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   349
    "Updates selection in completion view based on currently typed partial 
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   350
     text. Return true if the complection window should be closed or false
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   351
     if it shall be kept open.
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   352
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   353
     If `keyOrNil` is not nil, then it's a key press that triggered the update
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   354
     which HAS NOT YET been processed by a `editView`.
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   355
     "
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   356
192
f27ce6dac101 Initial support for completing selector parts.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 189
diff changeset
   357
    | list prefix matcher1 matches1 matcher2 matches2 |
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   358
189
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   359
    list := completionView list.
192
f27ce6dac101 Initial support for completing selector parts.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 189
diff changeset
   360
    matcher1 := CompletionEngine exactMatcher.
f27ce6dac101 Initial support for completing selector parts.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 189
diff changeset
   361
    matcher2 := CompletionEngine inexactMatcher.
221
5590362d7223 Anchor completion patterns to cursor position for more accurate match.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 218
diff changeset
   362
    prefix := self prefixAlreadyWritten.
239
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   363
    keyOrNil isCharacter ifTrue:[ 
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   364
        prefix := prefix , keyOrNil
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   365
    ].
192
f27ce6dac101 Initial support for completing selector parts.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 189
diff changeset
   366
    matches1 := list select:[:po | matcher1 value: prefix value: po stringToComplete ].
189
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   367
    matches1 notEmptyOrNil ifTrue:[
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   368
        matches1 size == 1 ifTrue:[
445
783f2a4af9c2 Electric insert: do not insert again and again when insertion was deleted by pressing backspace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 374
diff changeset
   369
            | selection completeElectric |
274
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   370
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   371
            selection := matches1 anElement.
455
f1cd6e210528 Bugfix: do not cache #completeIfUnambiguous, always ask preferences.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 445
diff changeset
   372
            completeElectric := (UserPreferences current smallSenseCompleteIfUnambiguous) and:[ support electricInsertSuppressed not ].
445
783f2a4af9c2 Electric insert: do not insert again and again when insertion was deleted by pressing backspace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 374
diff changeset
   373
            (completeElectric and: [(editView sensor hasKeyEventFor:editView) not]) ifTrue:[
274
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   374
                self complete: selection afterKeyPress: keyOrNil.
189
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   375
                ^ true
274
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   376
            ] ifFalse:[ 
2cfcd8eb9761 Fixes for issue #10: Extra characters inserted when typing too fast and complete-if-ambiguous is on
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 252
diff changeset
   377
                completionView selection: selection
189
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   378
            ].
154
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   379
        ] ifFalse:[
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   380
            | selection |
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   381
189
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   382
            selection := matches1 inject: matches1 anElement into:[:mostrelevant :each |
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   383
                each relevance > mostrelevant relevance 
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   384
                    ifTrue:[each]
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   385
                    ifFalse:[mostrelevant]
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   386
            ].
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   387
            completionView selection: selection.
192
f27ce6dac101 Initial support for completing selector parts.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 189
diff changeset
   388
        ].
f27ce6dac101 Initial support for completing selector parts.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 189
diff changeset
   389
        ^ false
189
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   390
    ].
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   391
192
f27ce6dac101 Initial support for completing selector parts.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 189
diff changeset
   392
    matches2 := completionView list select:[:po | matcher2 value: prefix value: po stringToComplete ].
189
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   393
    matches2 notEmptyOrNil ifTrue:[
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   394
        matches2 size == 1 ifTrue:[
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   395
            completionView selection:  matches2 anElement.
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   396
        ] ifFalse:[
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   397
            | selection |
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   398
8c32268000c5 Yet another fix in completion view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 188
diff changeset
   399
            selection := matches2 inject: matches2 anElement into:[:mostrelevant :each |
154
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   400
                each relevance > mostrelevant relevance 
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   401
                    ifTrue:[each]
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   402
                    ifFalse:[mostrelevant]
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   403
            ].
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   404
            completionView selection: selection.
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   405
        ]
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   406
    ] ifFalse:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   407
        completionView selection: nil.
153
b04d591c8788 Added relevance value to completion item. Pre-select the most relevant item in complection view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 143
diff changeset
   408
    ].
154
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   409
    ^ false.
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   410
239
e1b7b5f0f4b7 Bug fix in completion (#updateSelection).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 221
diff changeset
   411
    "Created: / 17-06-2014 / 07:19:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
455
f1cd6e210528 Bugfix: do not cache #completeIfUnambiguous, always ask preferences.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 445
diff changeset
   412
    "Modified: / 02-05-2015 / 22:07:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   413
! !
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   414
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   415
!CompletionController methodsFor:'private-API'!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   416
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   417
closeCompletionView
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   418
    |v|
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   419
123
1b949542c4b2 Improvements for completion of Java classes/methods in Smalltalk code.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 118
diff changeset
   420
    self stopCompletionProcess.
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   421
    (v := completionView) notNil ifTrue:[
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   422
        completionView := nil.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   423
        "/ let it close itself - avoids synchronization problems
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   424
        v sensor
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   425
            pushUserEvent:#value
1146
fe97cb7caab4 Call `#setForegroundWindow` on application window when completion view closes
Jan Vrany <jan.vrany@labware.com>
parents: 1122
diff changeset
   426
            for:[ v topView destroy. editView topView setForegroundWindow ].
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   427
    ].
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   428
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   429
    "Created: / 02-10-2013 / 13:57:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
123
1b949542c4b2 Improvements for completion of Java classes/methods in Smalltalk code.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 118
diff changeset
   430
    "Modified: / 04-10-2013 / 21:14:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1146
fe97cb7caab4 Call `#setForegroundWindow` on application window when completion view closes
Jan Vrany <jan.vrany@labware.com>
parents: 1122
diff changeset
   431
    "Modified: / 13-03-2023 / 22:46:17 / Jan Vrany <jan.vrany@labware.com>"
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   432
!
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   433
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   434
computeCompletions
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   435
    "Actually compute the completions and update the completion view."  
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   436
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   437
    | completions |
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   438
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   439
    editView sensor flushUserEventsFor: self.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   440
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   441
    "/ Wait a while to give user chance finish typing.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   442
    "/ This also reduces CPU consumption by avoiding
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   443
    "/ useless computation
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   444
    Delay waitForMilliseconds: 200. 
218
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   445
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   446
    completions := self computeCompletionsInContext.
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   447
    completions notEmptyOrNil ifTrue:[
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   448
        editView sensor pushUserEvent: #updateCompletions:sequence: for: self withArguments: (Array with: completions with: seqno)
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   449
    ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   450
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   451
    "Created: / 27-09-2013 / 13:12:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
218
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   452
    "Modified: / 18-05-2014 / 11:50:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   453
!
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   454
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   455
computeCompletionsInContext
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   456
    | context |
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   457
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   458
    context := CompletionContext new.
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   459
    context environment: self environment.
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   460
    context support: support.
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   461
    ^self computeCompletionsInContext: context.
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   462
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   463
    "Created: / 18-05-2014 / 11:50:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   464
!
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   465
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   466
computeCompletionsInContext: aCompletionContext
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   467
    | engine |
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   468
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   469
    engine := self completionEngine.
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   470
    ^engine notNil 
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   471
        ifTrue:[ engine complete: aCompletionContext ]
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   472
        ifFalse:[ nil ]
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   473
0f5b160ecb9d Let the CompletionController itself to instantiate completion engine.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 212
diff changeset
   474
    "Created: / 18-05-2014 / 11:53:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   475
!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   476
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   477
openCompletionView
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   478
    self openCompletionView: #()
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   479
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   480
    "Created: / 27-09-2013 / 16:17:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   481
!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   482
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   483
openCompletionView: list
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   484
    "Makes sure the completion view is opened and with given `list`."
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   485
    
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   486
    | movePos topView x y  windowExtent screenExtent |
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   487
    "/ move the window
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   488
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   489
    list isEmpty ifTrue:[ ^ self ].
153
b04d591c8788 Added relevance value to completion item. Pre-select the most relevant item in complection view.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 143
diff changeset
   490
    list = #( 'Busy...' ) ifTrue:[ ^ self ].  
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   491
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   492
    x := (editView xOfCol:editView cursorCol  inVisibleLine:editView cursorLine)
212
a2caebc602a7 Fixes and improvements for Java/Groovy completion (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 205
diff changeset
   493
            - 16"icon" - (editView widthOfString:  "support wordBeforeCursor"list first stringAlreadyWritten) - 5"magic constant".
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   494
    y := editView yOfCursor + editView font maxHeight + 3.
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   495
    movePos := (editView originRelativeTo: nil) + (x @ y).
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   496
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   497
    completionView isNil ifTrue:[
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   498
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   499
        completionView := CompletionView new.
178
f98d96568600 Fix for issue #8: allow for selecting completion using mouse and doubleclick.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 176
diff changeset
   500
        completionView completionController: self.  
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   501
        completionView list:list.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   502
        completionView font: editView font.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   503
        topView := completionView.
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   504
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   505
        windowExtent := completionView extent copy.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   506
        screenExtent := Screen current monitorBoundsAt: movePos.
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   507
        (screenExtent height) < (movePos y + windowExtent y) ifTrue:[
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   508
            movePos y: (movePos y - windowExtent y - editView font maxHeight - 5).
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   509
        ].
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   510
        topView origin:movePos.
1071
b6dbdc4fd7f5 Issue #176: fix "disappearing" completon view when pointer moves out of it
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1070
diff changeset
   511
        topView 
b6dbdc4fd7f5 Issue #176: fix "disappearing" completon view when pointer moves out of it
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1070
diff changeset
   512
            bePopUpView;
b6dbdc4fd7f5 Issue #176: fix "disappearing" completon view when pointer moves out of it
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1070
diff changeset
   513
            beSlave.
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   514
"/        topView resizeToFit.
154
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   515
        self updateSelection ifFalse:[
1071
b6dbdc4fd7f5 Issue #176: fix "disappearing" completon view when pointer moves out of it
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1070
diff changeset
   516
            topView openModal.
154
b96fbde91144 Support for auto-completion of unambigous items (such as instvars)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 153
diff changeset
   517
        ].
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   518
    ] ifFalse:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   519
        completionView list:list.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   520
        self updateSelection.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   521
"/        topView := completionView topView.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   522
"/        topView ~~ completionView ifTrue:[
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   523
"/            topView origin:movePos.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   524
"/            topView resizeToFit.
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   525
"/        ]
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   526
    ].
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   527
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   528
    "Created: / 27-09-2013 / 14:01:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
212
a2caebc602a7 Fixes and improvements for Java/Groovy completion (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 205
diff changeset
   529
    "Modified: / 15-05-2014 / 11:30:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1071
b6dbdc4fd7f5 Issue #176: fix "disappearing" completon view when pointer moves out of it
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 1070
diff changeset
   530
    "Modified (format): / 15-03-2018 / 10:47:27 / jv"
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   531
!
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   532
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   533
updateCompletions: completionResult sequence: sequence
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   534
    seqno == sequence ifTrue:[
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   535
        self openCompletionView: completionResult 
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   536
    ].
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   537
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   538
    "Created: / 03-10-2013 / 07:14:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   539
    "Modified: / 03-10-2013 / 11:02:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
117
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   540
! !
441529422c2f Completion support refactored to make it more pluggable/extendable.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   541
118
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   542
!CompletionController class methodsFor:'documentation'!
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   543
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   544
version_HG
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   545
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   546
    ^ '$Changeset: <not expanded> $'
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   547
! !
88e6fd734a11 Some more fixes in complete-as-you-type support...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 117
diff changeset
   548