--- a/Workspace.st Mon Oct 12 12:22:50 2009 +0200
+++ b/Workspace.st Mon Oct 12 13:39:01 2009 +0200
@@ -1146,74 +1146,7 @@
"Created: / 9.11.1997 / 01:05:46 / cg"
! !
-!Workspace methodsFor:'events'!
-
-expandAbbreviation
- |expandedString abortExpandAction oldSelectionStartLine oldSelectionStartCol oldSelectionEndLine oldSelectionEndCol oldCursorLine oldCursorCol
- newCursorPos replStartCol|
-
- oldCursorLine := self cursorLine.
- oldCursorCol := self cursorCol.
- oldSelectionStartLine := self selectionStartLine.
- oldSelectionStartCol := self selectionStartCol.
- oldSelectionEndLine := self selectionEndLine.
- oldSelectionEndCol := self selectionEndCol.
-
- abortExpandAction := [
- self selectFromLine:oldSelectionStartLine
- col:oldSelectionStartCol
- toLine:oldSelectionEndLine
- col:oldSelectionEndCol.
- self cursorLine: oldCursorLine col: oldCursorCol.
- ].
-
- expandedString := self findAbbreviationKeyBeforeCursor.
- expandedString isNil ifTrue:[
- abortExpandAction value.
- ^ self
- ].
- newCursorPos := expandedString indexOf:$!!.
- newCursorPos ~~ 0 ifTrue:[
- expandedString := expandedString copyWithout:$!!.
- ].
- replStartCol := self selectionStartCol.
- self
- undoableDo:[
- self replaceSelectionWith: expandedString]
- info:'Replace'.
-
- newCursorPos == 0 ifTrue:[
- "/ cursor already fine (at the end)
- ] ifFalse:[
- self cursorCol:replStartCol+newCursorPos-1
- ]
-!
-
-findAbbreviationKeyBeforeCursor
- |sniplets keys minMax maxKeyLen minKeyLen line stringBeforeCursor|
-
- sniplets := self class sniplets.
- keys := sniplets keys.
- minMax := (keys collect:[:k | k size]) minMax.
- minKeyLen := minMax first.
- maxKeyLen := minMax second.
- line := (self at:cursorLine) ? ''.
- stringBeforeCursor := line string copyTo:((cursorCol-1) min:line size).
-
- maxKeyLen := maxKeyLen min:stringBeforeCursor size.
-
- (maxKeyLen to:minKeyLen by:-1) do:[:l |
- |lCharactersBeforeCursor expandedString|
-
- lCharactersBeforeCursor := stringBeforeCursor last:l.
- expandedString := sniplets at:lCharactersBeforeCursor ifAbsent:nil.
- expandedString notNil ifTrue:[
- self selectFromLine:cursorLine col:cursorCol-l toLine:cursorLine col:cursorCol-1.
- ^ expandedString
- ].
- ].
- ^ nil.
-!
+!Workspace methodsFor:'event handling'!
keyPress:key x:x y:y
<resource: #keyboard (#DoIt #InspectIt #PrintIt #ReplaceIt #BrowseIt #ExpandIt)>
@@ -1760,6 +1693,81 @@
"Modified: / 22.4.1998 / 22:03:51 / ca"
! !
+!Workspace methodsFor:'misc'!
+
+expandAbbreviation
+ "after receiving an Alt-shift key-event, look for the string before the
+ cursor, find an abbrev for it and expand."
+
+ |expandedString abortExpandAction oldSelectionStartLine oldSelectionStartCol oldSelectionEndLine oldSelectionEndCol oldCursorLine oldCursorCol
+ newCursorPos replStartCol|
+
+ oldCursorLine := self cursorLine.
+ oldCursorCol := self cursorCol.
+ oldSelectionStartLine := self selectionStartLine.
+ oldSelectionStartCol := self selectionStartCol.
+ oldSelectionEndLine := self selectionEndLine.
+ oldSelectionEndCol := self selectionEndCol.
+
+ abortExpandAction := [
+ self selectFromLine:oldSelectionStartLine
+ col:oldSelectionStartCol
+ toLine:oldSelectionEndLine
+ col:oldSelectionEndCol.
+ self cursorLine: oldCursorLine col: oldCursorCol.
+ ].
+
+ expandedString := self findAbbreviationKeyBeforeCursor.
+ expandedString isNil ifTrue:[
+ abortExpandAction value.
+ ^ self
+ ].
+ newCursorPos := expandedString indexOf:$!!.
+ newCursorPos ~~ 0 ifTrue:[
+ expandedString := expandedString copyWithout:$!!.
+ ].
+ replStartCol := self selectionStartCol.
+ self
+ undoableDo:[
+ self replaceSelectionWith: expandedString]
+ info:'Replace'.
+
+ newCursorPos == 0 ifTrue:[
+ "/ cursor already fine (at the end)
+ ] ifFalse:[
+ self cursorCol:replStartCol+newCursorPos-1
+ ]
+!
+
+findAbbreviationKeyBeforeCursor
+ "after receiving an Alt-shift key-event, look for the string before the
+ cursor, find an abbrev for it and expand."
+
+ |sniplets keys minMax maxKeyLen minKeyLen line stringBeforeCursor|
+
+ sniplets := self class sniplets.
+ keys := sniplets keys.
+ minMax := (keys collect:[:k | k size]) minMax.
+ minKeyLen := minMax first.
+ maxKeyLen := minMax second.
+ line := (self at:cursorLine) ? ''.
+ stringBeforeCursor := line string copyTo:((cursorCol-1) min:line size).
+
+ maxKeyLen := maxKeyLen min:stringBeforeCursor size.
+
+ (maxKeyLen to:minKeyLen by:-1) do:[:l |
+ |lCharactersBeforeCursor expandedString|
+
+ lCharactersBeforeCursor := stringBeforeCursor last:l.
+ expandedString := sniplets at:lCharactersBeforeCursor ifAbsent:nil.
+ expandedString notNil ifTrue:[
+ self selectFromLine:cursorLine col:cursorCol-l toLine:cursorLine col:cursorCol-1.
+ ^ expandedString
+ ].
+ ].
+ ^ nil.
+! !
+
!Workspace methodsFor:'queries'!
isWorkspace
@@ -1769,9 +1777,9 @@
!Workspace class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.208 2009-10-05 23:40:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.209 2009-10-12 11:39:01 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.208 2009-10-05 23:40:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.209 2009-10-12 11:39:01 cg Exp $'
! !