The Trunk: Morphic-cmm.453.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Morphic-cmm.453.mcz

commits-2
Chris Muller uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-cmm.453.mcz

==================== Summary ====================

Name: Morphic-cmm.453
Author: cmm
Time: 3 July 2010, 4:20:46.206 pm
UUID: ad89ffef-f10d-4ab5-853f-c2a12140ccd6
Ancestors: Morphic-cmm.452

Added "Auto Enclose" preference.  When true, typing an opening parenthesis, bracket or square-bracket will also add its corresponding closing character in front of the cursor.

=============== Diff against Morphic-cmm.452 ===============

Item was added:
+ ----- Method: Editor>>moveCursor:forward:specialBlock:select: (in category 'private') -----
+ moveCursor: directionBlock forward: forward specialBlock: specialBlock select: shouldSelect
+ "Private - Move cursor.
+ directionBlock is a one argument Block that computes the new Position from a given one.
+ specialBlock is a one argumentBlock that computes the new position from a given one under the alternate semantics.
+ Note that directionBlock always is evaluated first."
+ | indices newPosition |
+ indices := self setIndices: shouldSelect forward: forward.
+ newPosition := directionBlock value: (indices at: #moving).
+ (sensor commandKeyPressed or:[sensor controlKeyPressed])
+ ifTrue: [newPosition := specialBlock value: newPosition].
+ sensor keyboard.
+ shouldSelect
+ ifTrue: [self selectMark: (indices at: #fixed) point: newPosition - 1]
+ ifFalse: [self selectAt: newPosition]!

Item was changed:
  ----- Method: Editor>>moveCursor:forward:specialBlock: (in category 'private') -----
+ moveCursor: directionBlock forward: forward specialBlock: specialBlock
- moveCursor: directionBlock forward: forward specialBlock: specialBlock
  "Private - Move cursor.
  directionBlock is a one argument Block that computes the new Position from a given one.
  specialBlock is a one argumentBlock that computes the new position from a given one under the alternate semantics.
  Note that directionBlock always is evaluated first."
+ ^ self
+ moveCursor: directionBlock
+ forward: forward
+ specialBlock: specialBlock
+ select: sensor leftShiftDown!
- | shift indices newPosition |
- shift := sensor leftShiftDown.
- indices := self setIndices: shift forward: forward.
- newPosition := directionBlock value: (indices at: #moving).
- (sensor commandKeyPressed or:[sensor controlKeyPressed])
- ifTrue: [newPosition := specialBlock value: newPosition].
- sensor keyboard.
- shift
- ifTrue: [self selectMark: (indices at: #fixed) point: newPosition - 1]
- ifFalse: [self selectAt: newPosition]!

Item was changed:
  ----- Method: TextEditor>>dispatchOnCharacter:with: (in category 'typing support') -----
  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 openers closers result |
- | honorCommandKeys |
  ((char == Character cr) and: [morph acceptOnCR])
  ifTrue: [
  sensor keyboard.  "Gobble cr -- probably unnecessary."
  self closeTypeIn.
  ^ true].
 
  self clearParens.
   
  char asciiValue = 13 ifTrue: [
  sensor controlKeyPressed ifTrue: [
  ^ self normalCharacter: typeAheadStream ].
  sensor leftShiftDown ifTrue: [
  ^ self lf: typeAheadStream ].
  sensor commandKeyPressed ifTrue: [
  ^ self crlf: typeAheadStream ].
  ^ self crWithIndent: typeAheadStream ].
 
  ((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: (self class shiftCmdActions at: char asciiValue + 1) with: typeAheadStream]
  ifFalse: [self perform: (self class 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: (self class shiftCmdActions at: char asciiValue + 1) with: typeAheadStream]
  ifFalse: [
  self perform: (self class 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: (self class shiftCmdActions at: char asciiValue + 1) with: typeAheadStream].
 
+ openers := '([{'.  closers := ')]}'.
+ (closers includes: char) ifTrue: [self blinkPrevParen].
- (')]}' includes: char)
- ifTrue: [self blinkPrevParen].
 
+ result := self normalCharacter: typeAheadStream.
+
+ (self class autoEnclose and: [ openers includes: char ])
+ ifTrue:
+ [ typeAheadStream nextPut: (closers at: (openers indexOf: char)).
+ self insertTypeAhead: typeAheadStream.
+ self moveCursor: [ : position | position-1 ] forward: false specialBlock: [ : pos | "no special behavior" ] select: false ].
+
+ ^ result!
- ^ self normalCharacter: typeAheadStream!

Item was added:
+ ----- Method: TextEditor class>>autoEnclose: (in category 'accessing') -----
+ autoEnclose: aBoolean
+ AutoEnclose := aBoolean!

Item was changed:
  Editor subclass: #TextEditor
  instanceVariableNames: 'model paragraph pointBlock markBlock beginTypeInBlock emphasisHere otherInterval lastParenLocation oldInterval'
+ classVariableNames: 'AutoEnclose AutoIndent ChangeText FindText UndoInterval UndoMessage UndoParagraph UndoSelection Undone'
- classVariableNames: 'AutoIndent ChangeText FindText UndoInterval UndoMessage UndoParagraph UndoSelection Undone'
  poolDictionaries: ''
  category: 'Morphic-Text Support'!
  TextEditor class
  instanceVariableNames: 'cmdActions shiftCmdActions yellowButtonMenu shiftedYellowButtonMenu'!
 
  !TextEditor commentStamp: '<historical>' prior: 0!
  See comment in Editor.
 
  My instances edit Text, this is, they support multiple lines and TextAttributes.
  They have no specific facilities for editing Smalltalk code. Those are found in SmalltalkEditor.!
  TextEditor class
  instanceVariableNames: 'cmdActions shiftCmdActions yellowButtonMenu shiftedYellowButtonMenu'!

Item was added:
+ ----- Method: TextEditor class>>autoEnclose (in category 'accessing') -----
+ autoEnclose
+ <preference: 'Auto Enclose'
+ category: 'Morphic'
+ description: 'When true, typing an opening parenthesis, bracket or square-bracket will also add its corresponding closing character in front of the cursor.'
+ type: #Boolean>
+ ^ AutoEnclose ifNil: [ false ]!