--- a/SmallSense__EditSupport.st Sun Oct 20 03:10:44 2013 +0100
+++ b/SmallSense__EditSupport.st Tue Oct 22 03:29:26 2013 +0100
@@ -3,7 +3,7 @@
"{ NameSpace: SmallSense }"
Object subclass:#EditSupport
- instanceVariableNames:'service textView backspaceIsUndo completionController'
+ instanceVariableNames:'service textView backspaceIsUndo completionController snippets'
classVariableNames:''
poolDictionaries:''
category:'SmallSense-Core-Services'
@@ -52,11 +52,25 @@
^ nil
"Created: / 03-10-2013 / 17:43:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+scannerClass
+ "Returns a class to use for scanning lines. If nil, scanning is
+ not supported and scanLine* methods will return an empty array."
+
+ ^ nil
+
+ "Created: / 22-10-2013 / 00:33:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!EditSupport methodsFor:'editing'!
insertDo: aBlock
+ textView completionSupport notNil ifTrue:[
+ textView completionSupport
+ stopCompletionProcess;
+ closeCompletionView.
+ ].
textView hasSelection ifTrue:[
textView undoableDo:[
textView deleteSelection
@@ -68,11 +82,18 @@
backspaceIsUndo := true.
"Created: / 17-09-2013 / 23:15:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-10-2013 / 03:15:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
insertElectricBlockOpenedBy: openText closedBy: closeText
| line col indent |
+ textView completionSupport notNil ifTrue:[
+ textView completionSupport
+ stopCompletionProcess;
+ closeCompletionView.
+ ].
+
indent := self indentAtCursorLine.
textView undoableDo:[
@@ -83,7 +104,13 @@
].
"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>"
+ "Modified: / 22-10-2013 / 03:16:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+insertElectricSnippet
+ ^ false
+
+ "Created: / 22-10-2013 / 01:54:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!EditSupport methodsFor:'event handling'!
@@ -93,11 +120,20 @@
If the method returns true, the event will not be processed
by the view."
+ key == Character space ifTrue:[
+ ^ self insertElectricSnippet
+ ].
^false
"Created: / 24-07-2013 / 23:31:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 27-09-2013 / 23:53:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-10-2013 / 01:56:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+keyPressSpace
+ ^ self insertElectricSnippet
+
+ "Created: / 22-10-2013 / 01:43:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!EditSupport methodsFor:'initialization'!
@@ -185,6 +221,68 @@
"Modified: / 02-10-2013 / 13:31:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!EditSupport methodsFor:'private-scanning'!
+
+scanLineAt: lineNumber
+ "Scans line at given line number.
+
+ Returns and array of tokens, **excluding** EOF. Each token is represented
+ by four subsequent items in the array: token type, token value, start position, end position.
+ Thus, returned array size is always multiple of 4."
+
+ ^ self scanLineAt: lineNumber using: self scannerClass
+
+ "Created: / 22-10-2013 / 00:34:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+scanLineAt: lineNumber using: scannerClass
+ "Scans line at given line number using given scanner class.
+
+ Returns and array of tokens, **excluding** EOF. Each token is represented
+ by four subsequent items in the array: token type, token value, start position, end position.
+ Thus, returned array size is always multiple of 4."
+
+ | line scanner token tokenLastEndPosition |
+
+ scannerClass isNil ifTrue:[ ^ #() ].
+ line := (service textView listAt: service textView cursorLine).
+ line isNil ifTrue:[ ^ #() ].
+ scanner := scannerClass for: line string.
+ tokenLastEndPosition := 0.
+ ^ OrderedCollection streamContents:[:tokens |
+ [
+ [ token := scanner nextToken.token ~~ #EOF ] whileTrue:[
+ tokens
+ nextPut: token;
+ nextPut: scanner tokenName;
+ nextPut: scanner tokenStartPosition;
+ nextPut: (tokenLastEndPosition := scanner tokenEndPosition).
+ ].
+ ] on: Error do:[
+ tokens
+ nextPut: 'Error';
+ nextPut: (line copyFrom: tokenLastEndPosition + 1 to: line size);
+ nextPut: tokenLastEndPosition + 1;
+ nextPut: line size.
+ ].
+ ].
+
+ "Created: / 22-10-2013 / 00:31:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-10-2013 / 02:16:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+scanLineAtCursor
+ "Scans current cursor line.
+
+ Returns and array of tokens, **excluding** EOF. Each token is represented
+ by four subsequent items in the array: token type, token value, start position, end position.
+ Thus, returned array size is always multiple of 4."
+
+ ^ self scanLineAt: service codeView textView cursorLine using: self scannerClass
+
+ "Created: / 22-10-2013 / 00:34:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!EditSupport class methodsFor:'documentation'!
version_HG