The Trunk: Morphic-mt.1383.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-mt.1383.mcz

commits-2
Marcel Taeumel uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-mt.1383.mcz

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

Name: Morphic-mt.1383
Author: mt
Time: 21 December 2017, 9:28:24.688535 pm
UUID: fb18b808-6654-884a-a1cf-d00df8f2755d
Ancestors: Morphic-mt.1382

Fixes a rare bug in text selections. NewParagraph >> #selectionRectsFrom:to: did not honor the contract as of NewParagraph >> #lineIndexOfCharacterIndex:, which is never use a line index < 1.

=============== Diff against Morphic-mt.1382 ===============

Item was changed:
  ----- Method: NewParagraph>>selectionRectsFrom:to: (in category 'selection') -----
  selectionRectsFrom: characterBlock1 to: characterBlock2
  "Return an array of rectangles representing the area between the two character blocks given as arguments."
  | line1 line2 rects cb1 cb2 w |
  characterBlock1 <= characterBlock2
  ifTrue: [cb1 := characterBlock1.  cb2 := characterBlock2]
  ifFalse: [cb2 := characterBlock1.  cb1 := characterBlock2].
  cb1 = cb2 ifTrue:
  [w := self caretWidth.
  ^ Array with: (cb1 topLeft - (w@0) corner: cb1 bottomLeft + ((w+1)@0))].
  line1 := self lineIndexOfCharacterIndex: cb1 stringIndex.
  line2 := self lineIndexOfCharacterIndex: cb2 stringIndex.
  cb1 top = (lines at: line1) top
  ifFalse:
  ["a word did not fit on prev line - start selection on prev line"
+ line1 := line1 - 1 max: 1].
- line1 := line1 - 1].
  line1 = line2 ifTrue:
  [^ Array with: (cb1 topLeft corner: cb2 bottomRight)].
  rects := OrderedCollection new.
  rects addLast: (cb1 topLeft corner: (lines at: line1) bottomRight).
  line1+1 to: line2-1 do: [ :i |
  | line |
  line := lines at: i.
  (line left = rects last left and: [ line right = rects last right ])
  ifTrue: [ "new line has same margins as old one -- merge them, so that the caller gets as few rectangles as possible"
  | lastRect |
  lastRect := rects removeLast.
  rects add: (lastRect bottom: line bottom) ]
  ifFalse: [ "differing margins; cannot merge"
  rects add: line rectangle ] ].
 
  rects addLast: ((lines at: line2) topLeft corner: cb2 bottomLeft).
  ^ rects!