[Pkg] The Trunk: Morphic-nice.572.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Sep 2 18:38:01 UTC 2011


Nicolas Cellier uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-nice.572.mcz

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

Name: Morphic-nice.572
Author: nice
Time: 2 September 2011, 8:36:00.946 pm
UUID: 61bf030f-3bd4-416a-9e51-e8b7dba0eaec
Ancestors: Morphic-cmm.571

1) Restore ancient behaviour of selecting whole text when clicking twice before first, or twice after last character.

2) avoid mutating the class of an instVar gratuitously in MouseOverHandler>>processMouseOver: 
	enteredMorphs := enteredMorphs contents.
The enteredMorphs inst var should be either a Stream or a Collection, but not sometimes a Stream, sometimes a Collection,.
The finite state machine coded in MouseOverHandler is already complex enough IMHO.
Such tricks are traps on future programmers track and are contributing to the fragility of construction.
Unless Stream and Collection become polymorphic of course, but in this case, mutating the class would be quite useless...

=============== Diff against Morphic-cmm.571 ===============

Item was changed:
  ----- Method: Editor>>selectWordLeftDelimiters:rightDelimiters: (in category 'new selection') -----
  selectWordLeftDelimiters: leftDelimiters rightDelimiters: rightDelimiters
  	"Select delimited text or word--the result of double-clicking."
  
  	| openDelimiter closeDelimiter direction match level
  	string here hereChar start stop |
  	string := self string.
  	string size < 2 ifTrue: [^self].
+ 	here := self pointIndex.
+ 	"Select the whole text when clicking before first or after last character"
+ 	(here > string size or: [here < 2]) ifTrue: [^self selectFrom: 1 to: string size].
- 	here := self pointIndex min: string size max: 2.
  	openDelimiter := string at: here - 1.
  	match := leftDelimiters indexOf: openDelimiter.
  	match > 0
  		ifTrue: [
  			"delimiter is on left -- match to the right"
  			start := here.
  			direction := 1.
  			here := here - 1.
  			closeDelimiter := rightDelimiters at: match]
  		ifFalse: [
  			openDelimiter := string at: here.
  			match := rightDelimiters indexOf: openDelimiter.
  			match > 0
  				ifTrue: [
  					"delimiter is on right -- match to the left"
  					stop := here - 1.
  					direction := -1.
  					closeDelimiter := leftDelimiters at: match]
  				ifFalse: [
  					"no delimiters -- select a token"
  					direction := -1]].
  	level := 1.
  	[level > 0 and: [direction > 0
  			ifTrue: [here < string size]
  			ifFalse: [here > 1]]]
  		whileTrue: [
  			hereChar := string at: (here := here + direction).
  			match = 0
  				ifTrue: ["token scan goes left, then right"
  					hereChar tokenish
  						ifTrue: [here = 1
  								ifTrue: [
  									start := 1.
  									"go right if hit string start"
  									direction := 1]]
  						ifFalse: [
  							direction < 0
  								ifTrue: [
  									start := here + 1.
  									"go right if hit non-token"
  									direction := 1]
  								ifFalse: [level := 0]]]
  				ifFalse: ["bracket match just counts nesting level"
  					hereChar = closeDelimiter
  						ifTrue: [level := level - 1"leaving nest"]
  						ifFalse: [hereChar = openDelimiter 
  									ifTrue: [level := level + 1"entering deeper nest"]]]].
  
  	level > 0 ifTrue: ["in case ran off string end"	here := here + direction].
+ 	^direction > 0
- 	direction > 0
  		ifTrue: [self selectFrom: start to: here - 1]
  		ifFalse: [self selectFrom: here + 1 to: stop]!

Item was changed:
  ----- Method: MouseOverHandler>>processMouseOver: (in category 'event handling') -----
  processMouseOver: anEvent 
  	"Re-establish the z-order for all morphs wrt the given event"
  
  	| hand localEvt focus evt |
  	hand := anEvent hand.
  	leftMorphs := mouseOverMorphs asIdentitySet.
  	"Assume some coherence for the number of objects in over list"
  	overMorphs := WriteStream on: (Array new: leftMorphs size).
  	enteredMorphs := WriteStream on: #().
  	"Now go looking for eventual mouse overs"
  	hand handleEvent: anEvent asMouseOver.
  	"Get out early if there's no change"
  	(leftMorphs isEmpty and: [ enteredMorphs position = 0 ]) 
  		ifTrue: [ ^self initializeTrackedMorphs ].
  	focus := hand mouseFocus.
  	"Send #mouseLeave as appropriate"
  	evt := anEvent asMouseLeave.
  	"Keep the order of the left morphs by recreating it from the mouseOverMorphs"
  	leftMorphs size > 1 
+ 		ifTrue:
+ 			[leftMorphs := mouseOverMorphs select: [:m | leftMorphs includes: m]].
+ 			leftMorphs do: [ :m | 
+ 			(m == focus or: [m hasOwner: focus])
+ 				ifFalse: [ overMorphs nextPut: m ]
+ 				ifTrue: 
+ 					[ localEvt := evt transformedBy: (m transformedFrom: hand).
+ 					m handleEvent: localEvt ] ].
- 		ifTrue: [leftMorphs := mouseOverMorphs select: [:m | leftMorphs includes: m]].
- 	leftMorphs do: [ :m | 
- 		(m == focus or: [m hasOwner: focus])
- 			ifFalse: [ overMorphs nextPut: m ]
- 			ifTrue: [
- 				localEvt := evt transformedBy: (m transformedFrom: hand).
- 				m handleEvent: localEvt ] ].
  	enteredMorphs ifNil: [ "inform: was called in handleEvent:"
  		^self initializeTrackedMorphs ].
  	"Send #mouseEnter as appropriate"
  	evt := anEvent asMouseEnter.
+ 	enteredMorphs contents reverseDo: [ :m | 
- 	enteredMorphs := enteredMorphs contents.
- 	enteredMorphs reverseDo: [ :m | 
  		(m == focus or: [m hasOwner: focus]) ifTrue: [
  			localEvt := evt transformedBy: (m transformedFrom: hand).
  			m handleEvent: localEvt ] ].
  	"And remember the over list"
+ 	overMorphs ifNotNil: [ mouseOverMorphs := overMorphs contents ].
- 	overMorphs ifNotNil: [
- 		mouseOverMorphs := overMorphs contents ].
  	self initializeTrackedMorphs!



More information about the Packages mailing list