The Trunk: Morphic-nice.330.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-nice.330.mcz

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

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

Name: Morphic-nice.330
Author: nice
Time: 9 February 2010, 9:41:41.369 am
UUID: b7e3dbbe-ae5e-1844-a09a-dad723adf8c8
Ancestors: Morphic-nice.329

Let indent/outdent work in case of LF

=============== Diff against Morphic-nice.329 ===============

Item was changed:
  ----- Method: TextEditor>>inOutdent:delta: (in category 'editing keys') -----
  inOutdent: characterStream delta: delta
  "Add/remove a tab at the front of every line occupied by the selection. Flushes typeahead.  Derived from work by Larry Tesler back in December 1985.  Now triggered by Cmd-L and Cmd-R.  2/29/96 sw"
 
+ | realStart realStop lines startLine stopLine start stop adjustStart indentation numLines oldString newString newSize |
- | realStart realStop lines startLine stopLine start stop adjustStart indentation size numLines inStream newString outStream |
  sensor keyboard.  "Flush typeahead"
 
  "Operate on entire lines, but remember the real selection for re-highlighting later"
  realStart := self startIndex.
  realStop := self stopIndex - 1.
 
  "Special case a caret on a line of its own, including weird case at end of paragraph"
  (realStart > realStop and:
  [realStart < 2 or: [(paragraph string at: realStart - 1) == Character cr or: [(paragraph string at: realStart - 1) == Character lf]]])
  ifTrue:
  [delta < 0
  ifTrue:
  [morph flash]
  ifFalse:
  [self replaceSelectionWith: Character tab asSymbol asText.
  self selectAt: realStart + 1].
  ^true].
 
  lines := paragraph lines.
  startLine := paragraph lineIndexOfCharacterIndex: realStart.
  "start on a real line, not a wrapped line"
  [startLine = 1 or: [CharacterSet crlf includes: (paragraph string at: (lines at: startLine-1) last)]] whileFalse: [startLine := startLine - 1].
  stopLine := paragraph lineIndexOfCharacterIndex: (realStart max: realStop).
  start := (lines at: startLine) first.
  stop := (lines at: stopLine) last.
 
  "Pin the start of highlighting unless the selection starts a line"
  adjustStart := realStart > start.
 
  "Find the indentation of the least-indented non-blank line; never outdent more"
  indentation := (startLine to: stopLine) inject: 1000 into:
  [:m :l |
  m min: (paragraph indentationOfLineIndex: l ifBlank: [:tabs | 1000])].
  indentation + delta <= 0 ifTrue: ["^false"].
 
- size :=  stop + 1 - start.
  numLines := stopLine + 1 - startLine.
+ oldString := paragraph string copyFrom: start to: stop.
+ newString := oldString species new: oldString size + ((numLines * delta) max: 0).
- inStream := ReadStream on: paragraph string from: start to: stop.
 
+ "Do the actual work"
+ newSize := 0.
+ delta > 0
+ ifTrue: [| tabs |
+ tabs := oldString species new: delta withAll: Character tab.
+ oldString lineIndicesDo: [:startL :endWithoutDelimiters :endL |
+ startL < endWithoutDelimiters ifTrue: [newString replaceFrom: 1 + newSize to: (newSize := newSize + delta) with: tabs startingAt: 1].
+ newString replaceFrom: 1 + newSize to: (newSize := 1 + newSize + endL - startL) with: oldString startingAt: startL]]
+ ifFalse: [| tab |
+ tab := Character tab.
+ oldString lineIndicesDo: [:startL :endWithoutDelimiters :endL |
+ | i |
+ i := 0.
+ [i + delta < 0 and: [ i + startL <= endWithoutDelimiters and: [(oldString at: i + startL) == tab]]] whileTrue: [i := i + 1].
+ newString replaceFrom: 1 + newSize to: (newSize := 1 + newSize + endL - (i + startL)) with: oldString startingAt: i + startL]].
+ newSize < newString size ifTrue: [newString := newString copyFrom: 1 to: newSize].
- newString := String new: size + ((numLines * delta) max: 0).
- outStream := WriteStream on: newString.
 
- "This subroutine does the actual work"
- self indent: delta fromStream: inStream toStream: outStream.
- newString := outStream contents.
-
  "Adjust the range that will be highlighted later"
  adjustStart ifTrue: [realStart := (realStart + delta) max: start].
+ realStop := realStop + newSize - oldString size.
- realStop := realStop + newString size - size.
 
  "Replace selection"
  self selectInvisiblyFrom: start to: stop.
  self replaceSelectionWith: newString asText.
  self selectFrom: realStart to: realStop. "highlight only the original range"
  ^ true!

Item was removed:
- ----- Method: TextEditor>>indent:fromStream:toStream: (in category 'private') -----
- indent: delta fromStream: inStream toStream: outStream
- "Append the contents of inStream to outStream, adding or deleting delta or -delta
- tabs at the beginning, and after every CR except a final CR.  Do not add tabs
- to totally empty lines, and be sure nothing but tabs are removed from lines."
-
- | ch skip cr tab prev atEnd |
- cr := Character cr.
- tab := Character tab.
- delta > 0
- ifTrue: "shift right"
- [prev := cr.
- [ch := (atEnd := inStream atEnd) ifTrue: [cr] ifFalse: [inStream next].
-  (prev == cr and: [ch ~~ cr]) ifTrue:
- [delta timesRepeat: [outStream nextPut: tab]].
-  atEnd]
- whileFalse:
- [outStream nextPut: ch.
- prev := ch]]
- ifFalse: "shift left"
- [skip := delta. "a negative number"
- [inStream atEnd] whileFalse:
- [((ch := inStream next) == tab and: [skip < 0]) ifFalse:
- [outStream nextPut: ch].
- skip := ch == cr ifTrue: [delta] ifFalse: [skip + 1]]]!