As promised in an earlier e-mail, I figured out how to get "selection
surrounding" working. I'm not completely happy with parts of the implementation or the choice of accelerator keys, but it works and is better than nothing. If anyone wants to clean it up or enhance it, I'd appreciate it. Blair/Andy: If you want to include this (or a better variation of it) in the base image, please feel free. 10-second user's manual: - in any workspace, select the text you want to "surround" and press an accelerator key combination. The selection will be surrounded by the corresponding characters. Press the same key combination again, and the surrounding characters will be removed. In both cases, the original selection remains selected. Key combinations: - Ctrl-P surrounds with ( and ) - Ctrl-K surrounds with [ and ] - Ctrl-Q surrounds with ' and ' - Ctrl-Shift-Q surrounds with " and " What I'd really like is Ctrl-(/Ctrl-), Ctrl-[/Ctrl-], Ctrl-', and Ctrl-", but I couldn't get them all to work. Plus, Ctrl-[ is a shortcut for "Move to Inner Scope". I can get Ctrl-(/Ctrl-) to work by using 'Ctrl+Shift+9'/'Ctrl+Shift+0' as the accelerator key string. I couldn't get the rest to work. The code is below. SmalltalkWorkspace>>additionalAccelerators is an override; the rest of it is new code. Randy --------------- !MultilineTextEdit methodsFor! expandSelectionRange | range | range := self selectionRange. range start = 1 ifTrue: [^self]. range stop = self text size ifTrue: [^self]. self selectionStart: range start - 1 end: range stop + 1! toggleBrackets self toggleSurroundingSelectionWith: $[ and: $]! toggleDoubleQuotes self toggleSurroundingSelectionWith: $"! toggleParentheses self toggleSurroundingSelectionWith: $( and: $)! toggleSingleQuotes self toggleSurroundingSelectionWith: $'! toggleSurroundingSelectionWith: aCharacter self toggleSurroundingSelectionWith: aCharacter and: aCharacter! toggleSurroundingSelectionWith: startCharacter and: endCharacter | originalText newText range expandedRange | originalText := self selection. newText := startCharacter asString , self selection , endCharacter asString. range := self selectionRange. self expandSelectionRange. self selection = newText ifTrue: [self replaceSelection: originalText. self selectionRange: range - 1] ifFalse: [self selectionRange: range. self replaceSelection: newText. self selectionRange: range + 1]! ! !MultilineTextEdit categoriesFor: #expandSelectionRange!private!selection! ! !MultilineTextEdit categoriesFor: #toggleBrackets!commands!public! ! !MultilineTextEdit categoriesFor: #toggleDoubleQuotes!commands!public! ! !MultilineTextEdit categoriesFor: #toggleParentheses!commands!public! ! !MultilineTextEdit categoriesFor: #toggleSingleQuotes!commands!public! ! !MultilineTextEdit categoriesFor: #toggleSurroundingSelectionWith:!commands!private! ! !MultilineTextEdit categoriesFor: #toggleSurroundingSelectionWith:and:!commands!private! ! !SmalltalkWorkspace methodsFor! additionalAccelerators "Answer a collection of additional accelerator definitions for commands not on the menu bar of the receiver's view(s). Each element of the collection should be a two element <Array>, the first element of which is the command symbol and the second the accelerator key string." ^#(#(#cutLine 'Ctrl+L') #(#deleteLine 'Ctrl+Shift+L') #(#toggleWordWrap 'Ctrl+R') #(#toggleParentheses 'Ctrl+P') #(#toggleBrackets 'Ctrl+K') #(#toggleSingleQuotes 'Ctrl+Q') #(#toggleDoubleQuotes 'Ctrl+Shift+Q'))! ! !SmalltalkWorkspace categoriesFor: #additionalAccelerators!constants!public! ! -- Randy Coulman NOTE: Reply-to: address is spam-guarded. Reassemble the following to reply directly: rvcoulman at acm dot org |
Randy
Thanks for the code. Using it, I should be able to port my Abbreviations code (which I implemented as part of VA Assist) to Dolphin. I'll post it as soon as I'm finished with the port. Cheers Joseph Randy Coulman wrote: > As promised in an earlier e-mail, I figured out how to get "selection > surrounding" working. I'm not completely happy with parts of the > implementation or the choice of accelerator keys, but it works and is > better than nothing. If anyone wants to clean it up or enhance it, I'd > appreciate it. > > Blair/Andy: If you want to include this (or a better variation of it) in > the base image, please feel free. > > 10-second user's manual: > - in any workspace, select the text you want to "surround" and press an > accelerator key combination. The selection will be surrounded by the > corresponding characters. Press the same key combination again, and the > surrounding characters will be removed. In both cases, the original > selection remains selected. > > Key combinations: > - Ctrl-P surrounds with ( and ) > - Ctrl-K surrounds with [ and ] > - Ctrl-Q surrounds with ' and ' > - Ctrl-Shift-Q surrounds with " and " > > What I'd really like is Ctrl-(/Ctrl-), Ctrl-[/Ctrl-], Ctrl-', and > Ctrl-", but I couldn't get them all to work. Plus, Ctrl-[ is a shortcut > for "Move to Inner Scope". I can get Ctrl-(/Ctrl-) to work by using > 'Ctrl+Shift+9'/'Ctrl+Shift+0' as the accelerator key string. I couldn't > get the rest to work. > > The code is below. SmalltalkWorkspace>>additionalAccelerators is an > override; the rest of it is new code. > > Randy > --------------- > !MultilineTextEdit methodsFor! > > expandSelectionRange > | range | > range := self selectionRange. > range start = 1 ifTrue: [^self]. > range stop = self text size ifTrue: [^self]. > self selectionStart: range start - 1 end: range stop + 1! > > toggleBrackets > self toggleSurroundingSelectionWith: $[ and: $]! > > toggleDoubleQuotes > self toggleSurroundingSelectionWith: $"! > > toggleParentheses > self toggleSurroundingSelectionWith: $( and: $)! > > toggleSingleQuotes > self toggleSurroundingSelectionWith: $'! > > toggleSurroundingSelectionWith: aCharacter > self toggleSurroundingSelectionWith: aCharacter and: aCharacter! > > toggleSurroundingSelectionWith: startCharacter and: endCharacter > | originalText newText range expandedRange | > originalText := self selection. > newText := startCharacter asString , self selection , endCharacter > asString. > range := self selectionRange. > self expandSelectionRange. > self selection = newText > ifTrue: > [self replaceSelection: originalText. > self selectionRange: range - 1] > ifFalse: > [self selectionRange: range. > self replaceSelection: newText. > self selectionRange: range + 1]! ! > !MultilineTextEdit categoriesFor: > #expandSelectionRange!private!selection! ! > !MultilineTextEdit categoriesFor: #toggleBrackets!commands!public! ! > !MultilineTextEdit categoriesFor: #toggleDoubleQuotes!commands!public! ! > !MultilineTextEdit categoriesFor: #toggleParentheses!commands!public! ! > !MultilineTextEdit categoriesFor: #toggleSingleQuotes!commands!public! ! > !MultilineTextEdit categoriesFor: > #toggleSurroundingSelectionWith:!commands!private! ! > !MultilineTextEdit categoriesFor: > #toggleSurroundingSelectionWith:and:!commands!private! ! > > !SmalltalkWorkspace methodsFor! > > additionalAccelerators > "Answer a collection of additional accelerator definitions for > commands > not on the menu bar of the receiver's view(s). > Each element of the collection should be a two element <Array>, the > first element of which is the command symbol > and the second the accelerator key string." > > ^#(#(#cutLine 'Ctrl+L') #(#deleteLine 'Ctrl+Shift+L') > #(#toggleWordWrap > 'Ctrl+R') #(#toggleParentheses 'Ctrl+P') #(#toggleBrackets 'Ctrl+K') > #(#toggleSingleQuotes 'Ctrl+Q') #(#toggleDoubleQuotes 'Ctrl+Shift+Q'))! ! > !SmalltalkWorkspace categoriesFor: > #additionalAccelerators!constants!public! ! > -- -- Joseph Pelrine [ | ] MetaProg GmbH Email: [hidden email] Web: http://www.metaprog.com "If you don't live on the edge, you're taking up too much space" - Doug Robinson |
Free forum by Nabble | Edit this page |