Initial support for complete-as-you-type.
Highly experimental, do not use it now!
"{ Package: 'jv:smallsense' }"
"{ NameSpace: SmallSense }"
Object subclass:#EditSupport
instanceVariableNames:'service textView backspaceIsUndo completionWindow
completionSuppressed'
classVariableNames:''
poolDictionaries:''
category:'SmallSense-Core-Services'
!
!EditSupport class methodsFor:'instance creation'!
forLanguage: aProgrammingLanguage
aProgrammingLanguage notNil ifTrue:[
aProgrammingLanguage isSmalltalk ifTrue:[
^ SmalltalkEditSupport new
].
aProgrammingLanguage isJava ifTrue:[
^ JavaEditSupport new
]
].
^GenericEditSupport new.
"Created: / 24-07-2013 / 23:20:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 04-08-2013 / 02:06:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!EditSupport methodsFor:'accessing'!
language
^ self subclassResponsibility.
"Created: / 24-07-2013 / 23:44:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
service
^ service
!
service:aSmallSenseService
service := aSmallSenseService.
textView := aSmallSenseService textView.
completionWindow := nil.
completionSuppressed := false.
backspaceIsUndo := false.
"Modified: / 24-09-2013 / 01:18:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!EditSupport methodsFor:'editing'!
insertDo: aBlock
textView hasSelection ifTrue:[
textView undoableDo:[
textView deleteSelection
].
].
textView undoableDo: [
aBlock value.
].
backspaceIsUndo := true.
"Created: / 17-09-2013 / 23:15:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
insertElectricBlockOpenedBy: openText closedBy: closeText
| line col indent |
indent := self indentAtCursorLine.
textView undoableDo:[
textView insertStringAtCursor: (openText ? '') , Character cr , Character cr, (String new:indent withAll:Character space) , closeText , Character cr.
line := textView cursorLine - 1.
col := textView cursorCol + 3.
textView cursorLine: line col: col.
].
"Created: / 25-07-2013 / 10:41:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 04-08-2013 / 02:15:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!EditSupport methodsFor:'event handling'!
doKeyPressComplete
^ self doKeyPressComplete: false
"Created: / 04-08-2013 / 02:33:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 24-09-2013 / 00:53:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
doKeyPressComplete: auto
"Not supported in generic edit support"
textView flash.
^ auto not
"Created: / 24-09-2013 / 00:59:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
keyPress: key x:x y:y in: view
"Handles an event in given view (a subview of codeView).
If the method returns true, the event will not be processed
by the view."
| codeView line |
key == #CodeCompletion ifTrue: [
^ self doKeyPressComplete.
].
(key isCharacter and:[key isAlphaNumeric and:[UserPreferences current immediateCodeCompletion]]) ifTrue:[
completionSuppressed ifTrue:[ ^ false ].
"/ completionWindow notNil ifTrue:[ ^ false ].
codeView := service codeView.
line := (codeView list at: codeView cursorLine).
line isEmptyOrNil ifTrue:[ ^ false ].
line := line string.
((line size >= codeView cursorCol) and:[
(line at: codeView cursorCol) isAlphaNumeric]) ifTrue:[ ^ false ].
(line size < (codeView cursorCol - 1)) ifTrue:[ ^ false ].
(line at: codeView cursorCol - 1) isAlphaNumeric ifFalse:[ ^ false ].
(line at: codeView cursorCol - 2) isAlphaNumeric ifFalse:[ ^ false ].
completionSuppressed := true.
codeView sensor pushUserEvent: #doKeyPressComplete: for: self withArgument: true.
] ifFalse:[
completionSuppressed := false.
].
^false
"Created: / 24-07-2013 / 23:31:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 24-09-2013 / 01:49:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!EditSupport methodsFor:'private'!
indentAtCursorLine
| line |
line := service textView listAt: service textView cursorLine.
^ line isNil ifTrue:[
service textView cursorCol - 1.
] ifFalse:[
line indexOfNonSeparator - 1.
]
"Created: / 25-07-2013 / 00:13:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 04-08-2013 / 02:13:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !