[ENH] another try at ParenBlinking
Avi Bryant
avi at beta4.com
Mon Jan 7 12:26:20 UTC 2002
Some people were asking for paren blinking a little while ago - here's
a quick attempt. It uses bold instead of selection, so doesn't have the
annoying type-over danger of the previous changesets.
Avi
-------------- next part --------------
'From Squeak3.2alpha of 1 November 2001 [latest update: #4599] on 7 January 2002 at 3:59:06 am'!
"Change Set: ParenBlinking
Date: 7 January 2002
Author: Avi Bryant
Adds simple paren blinking to ParagaphEditor - open parentheses are bolded when a close paren is typed, and stay bold until the next keystroke"!
ScrollController subclass: #ParagraphEditor
instanceVariableNames: 'paragraph startBlock stopBlock beginTypeInBlock emphasisHere initialText selectionShowing otherInterval lastParenLocation '
classVariableNames: 'ChangeText CmdActions FindText Keyboard ShiftCmdActions TextEditorYellowButtonMenu UndoInterval UndoMessage UndoParagraph UndoSelection Undone '
poolDictionaries: 'TextConstants '
category: 'Kernel-ST80 Remnants'!
!ParagraphEditor methodsFor: 'paren blinking' stamp: 'AB 1/7/2002 03:51'!
blinkParenAt: parenLocation
self text
addAttribute: TextEmphasis bold
from: parenLocation
to: parenLocation.
lastParenLocation _ parenLocation.! !
!ParagraphEditor methodsFor: 'paren blinking' stamp: 'AB 1/7/2002 03:51'!
blinkPrevParen
| openDelimiter closeDelimiter level string here hereChar |
string _ paragraph text string.
here _ startBlock stringIndex.
openDelimiter _ sensor keyboardPeek.
closeDelimiter _ '([{' at: (')]}' indexOf: openDelimiter).
level _ 1.
[level > 0 and: [here > 2]]
whileTrue:
[hereChar _ string at: (here _ here - 1).
hereChar = closeDelimiter
ifTrue:
[level _ level - 1.
level = 0
ifTrue: [^ self blinkParenAt: here]]
ifFalse:
[hereChar = openDelimiter
ifTrue: [level _ level + 1]]].! !
!ParagraphEditor methodsFor: 'paren blinking' stamp: 'AB 1/7/2002 03:37'!
clearParens
lastParenLocation ifNotNil:
[self text
removeAttribute: TextEmphasis bold
from: lastParenLocation
to: lastParenLocation].
! !
!ParagraphEditor methodsFor: 'paren blinking' stamp: 'AB 1/7/2002 03:50'!
dispatchOnCharacter: char with: typeAheadStream
"Carry out the action associated with this character, if any.
Type-ahead is passed so some routines can flush or use it."
| honorCommandKeys |
((honorCommandKeys _ Preferences cmdKeysInText) and: [char = Character enter])
ifTrue: [^ self dispatchOnEnterWith: typeAheadStream].
"Special keys overwrite crtl+key combinations - at least on Windows. To resolve this
conflict, assume that keys other than cursor keys aren't used together with Crtl."
((self class specialShiftCmdKeys includes: char asciiValue) and: [char asciiValue < 27])
ifTrue: [^ sensor controlKeyPressed
ifTrue: [self perform: (ShiftCmdActions at: char asciiValue + 1) with: typeAheadStream]
ifFalse: [self perform: (CmdActions at: char asciiValue + 1) with: typeAheadStream]].
"backspace, and escape keys (ascii 8 and 27) are command keys"
((honorCommandKeys and: [sensor commandKeyPressed]) or: [self class specialShiftCmdKeys includes: char asciiValue]) ifTrue:
[^ sensor leftShiftDown
ifTrue:
[self perform: (ShiftCmdActions at: char asciiValue + 1) with: typeAheadStream]
ifFalse:
[self perform: (CmdActions at: char asciiValue + 1) with: typeAheadStream]].
"the control key can be used to invoke shift-cmd shortcuts"
(honorCommandKeys and: [sensor controlKeyPressed])
ifTrue:
[^ self perform: (ShiftCmdActions at: char asciiValue + 1) with: typeAheadStream].
self clearParens.
(')]}' includes: char)
ifTrue: [self blinkPrevParen].
^ self perform: #normalCharacter: with: typeAheadStream! !
More information about the Squeak-dev
mailing list
|