EditTextView.st
changeset 2954 65a518fe6eb6
parent 2952 08d18f507e05
child 2955 82be53febfae
--- a/EditTextView.st	Thu Apr 01 23:24:23 2004 +0200
+++ b/EditTextView.st	Thu Apr 01 23:46:57 2004 +0200
@@ -2209,6 +2209,75 @@
     self deleteFromLine:line1 col:col1 toLine:line2 col:col2.
 !
 
+deleteFromLine:startLine col:startCol toLine:endLine col:endCol
+    "delete all text from startLine/startCol to endLine/endCol -
+     joining lines if nescessary"
+
+    |line newLine lineSize nMore|
+
+    self checkModificationsAllowed ifFalse:[ ^ self].
+    list isNil ifTrue:[^ self].
+    startLine > list size ifTrue:[ ^ self]. "/ deleted space below text
+
+    (startLine == endLine) ifTrue:[
+        "/ delete chars within a line
+        self deleteCharsAtLine:startLine fromCol:startCol toCol:endCol.
+        ^ self
+    ].
+
+    ((startCol == 1) and:[endCol == 0]) ifTrue:[
+        "/ delete full lines only
+        endLine > startLine ifTrue:[
+            self deleteFromLine:startLine toLine:(endLine - 1)
+        ].
+        ^ self
+    ].
+
+    "/ delete right rest of 1st line
+    self deleteCharsAtLine:startLine fromCol:startCol.
+
+    "/ delete the inner lines ...
+    endLine > (startLine + 1) ifTrue:[
+        self deleteFromLine:(startLine + 1) toLine:(endLine - 1)
+    ].
+
+    (endCol ~~ 0) ifTrue:[
+        "/ delete the left rest of the last line
+
+        self deleteCharsAtLine:(startLine + 1) toCol:endCol.
+
+        "/ must add blanks, if startCol lies beyond end of startLine
+
+        line := list at:startLine.
+        lineSize := line size.
+        (startCol > lineSize) ifTrue:[
+            newLine := line.
+            line isNil ifTrue:[
+                newLine := String new:(startCol - 1)
+            ] ifFalse:[
+                nMore := startCol - 1 - lineSize.
+                nMore > 0 ifTrue:[
+                    newLine := line , (line species new:nMore)
+                ]
+            ].
+            newLine ~~ line ifTrue:[
+                list at:startLine put:newLine.
+            ].
+            "/ TODO: remember old maxwidth of linerange,
+            "/ only clear widthOfWidestLine, if this max
+            "/ length was (one of) the longest.
+            "/ avoids slow delete with huge texts.
+            widthOfWidestLine := nil. "/ i.e. unknown
+            self textChanged.
+        ]
+    ].
+
+    "/ merge the left rest of 1st line with right rest of last line into one
+    self mergeLine:startLine removeBlanks:false
+
+    "Modified: / 10.11.1998 / 23:52:59 / cg"
+!
+
 deleteLine:lineNr
     "delete line"
 
@@ -2946,85 +3015,6 @@
     "Modified: / 20.6.1998 / 18:19:22 / cg"
 !
 
-basicInsertLines:someText from:start to:end before:lineNr
-    "insert a bunch of lines before line lineNr"
-
-    |text indent visLine w nLines "{ Class: SmallInteger }"
-     srcY "{ Class: SmallInteger }"
-     dstY "{ Class: SmallInteger }" |
-
-    self isReadOnly ifTrue:[
-        ^ self
-    ].
-
-    autoIndent ifTrue:[
-        indent := self leftIndentForLine:lineNr.
-
-        text := someText collect:[:ln||line|
-            ln notNil ifTrue:[
-                line := ln withoutLeadingSeparators.
-                (line isEmpty or:[indent == 0]) ifFalse:[
-                    line := (String new:indent), line
-                ].
-                line
-            ] ifFalse:[
-                nil
-            ]
-        ].
-    ] ifFalse:[
-        text := someText
-    ].
-
-    visLine := self listLineToVisibleLine:lineNr.
-    (shown not or:[visLine isNil]) ifTrue:[
-        self withoutRedrawInsertLines:text
-                                 from:start to:end
-                               before:lineNr.
-    ] ifFalse:[
-        nLines := end - start + 1.
-        ((visLine + nLines) >= nLinesShown) ifTrue:[
-            self withoutRedrawInsertLines:text
-                                     from:start to:end
-                                   before:lineNr.
-            self redrawFromVisibleLine:visLine to:nLinesShown
-        ] ifFalse:[
-            w := self widthForScrollBetween:(lineNr + nLines)
-                                        and:(firstLineShown + nLines + nLinesShown).
-            srcY := topMargin + ((visLine - 1) * fontHeight).
-            dstY := srcY + (nLines * fontHeight).
-
-            "/
-            "/ scroll ...
-            "/
-            "
-             stupid: must catchExpose before inserting new
-             stuff - since catchExpose may perform redraws
-            "
-            self catchExpose.
-            self withoutRedrawInsertLines:text
-                                     from:start to:end
-                                   before:lineNr.
-            self 
-                copyFrom:self 
-                x:textStartLeft y:srcY
-                toX:textStartLeft y:dstY
-                width:w
-                height:(height - dstY)
-                async:true.
-            self redrawFromVisibleLine:visLine to:(visLine + nLines - 1).
-            self waitForExpose
-        ].
-    ].
-    widthOfWidestLine notNil ifTrue:[
-        text do:[:line |
-            widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:line).
-        ]
-    ].
-    self textChanged.
-
-    "Modified: 29.1.1997 / 13:02:39 / cg"
-!
-
 basicMergeLine:lineNr removeBlanks:removeBlanks
     "merge line lineNr with line lineNr+1"
 
@@ -3227,6 +3217,123 @@
     "Modified: / 10.6.1998 / 19:00:56 / cg"
 !
 
+basicWithoutRedrawInsertLines:lines from:start to:end before:lineNr
+    "insert a bunch of lines before line lineNr; the view is not redrawn"
+
+    |newLine newLines nLines|
+
+    self checkModificationsAllowed ifFalse:[ ^ self].
+
+    nLines := end - start + 1.
+    newLines := Array new:(lines size).
+    start to:end do:[:index |
+        newLine := lines at:index.
+        newLine notNil ifTrue:[
+            newLine isString ifTrue:[
+                newLine isBlank ifTrue:[
+                    newLine := nil
+                ] ifFalse:[
+                    (newLine includes:(Character tab)) ifTrue:[
+                        newLine := self withTabsExpanded:newLine
+                    ]
+                ]
+            ]
+        ].
+        newLines at:index put:newLine
+    ].
+    list isNil ifTrue: [
+        list := StringCollection new:(lineNr + nLines + 1)
+    ] ifFalse: [
+        list grow:((list size + nLines) max:(lineNr + nLines - 1))
+    ].
+
+    "I have changed 'replaceFrom:to:with:startingAt:' to correctly handle 
+     overlapping copy - if it didn't, we had to use:"
+"
+    index := list size.
+    [index > lineNr] whileTrue: [
+        pIndex := index - 1.
+        list at:index put:(list at:pIndex).
+        index := pIndex
+    ].
+"
+    list replaceFrom:(lineNr + nLines) to:(list size) with:list startingAt:lineNr.
+    list replaceFrom:lineNr to:(lineNr + nLines - 1) with:newLines startingAt:start.
+    self contentsChanged
+
+    "Modified: / 10.6.1998 / 19:01:16 / cg"
+!
+
+basicWithoutRedrawInsertStringWithoutCRs:aString atLine:lineNr col:colNr
+    "insert aString (which has no crs) at lineNr/colNr"
+
+    |isText strLen line lineSize newLine stringType sz|
+
+    (aString notNil) ifFalse:[ ^ self].
+
+    strLen := aString size.
+    self checkForExistingLine:lineNr.
+
+    stringType := aString string species.
+    isText     := aString isText.
+    line       := list at:lineNr.
+
+    line notNil ifTrue:[
+        lineSize := line size.
+        line isString ifFalse:[
+            stringType := line species
+        ] ifTrue:[
+            line bitsPerCharacter > aString bitsPerCharacter ifTrue:[
+                stringType := line string species
+            ].
+            line isText ifTrue:[ isText := true ]
+        ].
+    ] ifFalse:[
+        lineSize := 0
+    ].
+
+    ((colNr == 1) and:[lineSize == 0]) ifTrue: [
+        newLine := aString
+    ] ifFalse:[
+        (lineSize == 0 or:[colNr > lineSize]) ifTrue: [
+            sz := colNr + strLen - 1
+        ] ifFalse:[
+            sz := lineSize + strLen
+        ].
+
+        isText ifFalse:[
+            newLine := stringType new:sz
+        ] ifTrue:[
+            newLine := Text string:(stringType new:sz)
+        ].
+
+        (lineSize ~~ 0) ifTrue: [
+            (colNr > lineSize) ifTrue: [
+                newLine replaceFrom:1 to:lineSize
+                               with:line startingAt:1
+            ] ifFalse: [
+                newLine replaceFrom:1 to:(colNr - 1)
+                               with:line startingAt:1.
+                newLine replaceFrom:(colNr + strLen) to:(lineSize + strLen)
+                               with:line startingAt:colNr
+            ]
+        ].
+        newLine replaceFrom:colNr to:(colNr + strLen - 1) with:aString startingAt:1
+    ].
+
+    (aString includes:(Character tab)) ifTrue:[
+        newLine := self withTabsExpanded:newLine
+    ].
+
+    list at:lineNr put:newLine.
+    widthOfWidestLine notNil ifTrue:[
+        widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:newLine).
+    ].
+    self textChanged.
+
+    "Modified: / 10.6.1998 / 19:01:52 / cg"
+!
+
 deleteCharsAtLine:lineNr fromCol:startCol toCol:endCol
     "delete characters from startCol to endCol in line lineNr
     "
@@ -3237,75 +3344,6 @@
     self addUndo:(PasteString line:lineNr col:startCol string:deleted ).
 !
 
-deleteFromLine:startLine col:startCol toLine:endLine col:endCol
-    "delete all text from startLine/startCol to endLine/endCol -
-     joining lines if nescessary"
-
-    |line newLine lineSize nMore|
-
-    self checkModificationsAllowed ifFalse:[ ^ self].
-    list isNil ifTrue:[^ self].
-    startLine > list size ifTrue:[ ^ self]. "/ deleted space below text
-
-    (startLine == endLine) ifTrue:[
-        "/ delete chars within a line
-        self deleteCharsAtLine:startLine fromCol:startCol toCol:endCol.
-        ^ self
-    ].
-
-    ((startCol == 1) and:[endCol == 0]) ifTrue:[
-        "/ delete full lines only
-        endLine > startLine ifTrue:[
-            self deleteFromLine:startLine toLine:(endLine - 1)
-        ].
-        ^ self
-    ].
-
-    "/ delete right rest of 1st line
-    self deleteCharsAtLine:startLine fromCol:startCol.
-
-    "/ delete the inner lines ...
-    endLine > (startLine + 1) ifTrue:[
-        self deleteFromLine:(startLine + 1) toLine:(endLine - 1)
-    ].
-
-    (endCol ~~ 0) ifTrue:[
-        "/ delete the left rest of the last line
-
-        self deleteCharsAtLine:(startLine + 1) toCol:endCol.
-
-        "/ must add blanks, if startCol lies beyond end of startLine
-
-        line := list at:startLine.
-        lineSize := line size.
-        (startCol > lineSize) ifTrue:[
-            newLine := line.
-            line isNil ifTrue:[
-                newLine := String new:(startCol - 1)
-            ] ifFalse:[
-                nMore := startCol - 1 - lineSize.
-                nMore > 0 ifTrue:[
-                    newLine := line , (line species new:nMore)
-                ]
-            ].
-            newLine ~~ line ifTrue:[
-                list at:startLine put:newLine.
-            ].
-            "/ TODO: remember old maxwidth of linerange,
-            "/ only clear widthOfWidestLine, if this max
-            "/ length was (one of) the longest.
-            "/ avoids slow delete with huge texts.
-            widthOfWidestLine := nil. "/ i.e. unknown
-            self textChanged.
-        ]
-    ].
-
-    "/ merge the left rest of 1st line with right rest of last line into one
-    self mergeLine:startLine removeBlanks:false
-
-    "Modified: / 10.11.1998 / 23:52:59 / cg"
-!
-
 deleteFromLine:startLineNr toLine:endLineNr
     "delete some lines"
 
@@ -3341,8 +3379,80 @@
 insertLines:someText from:start to:end before:lineNr
     "insert a bunch of lines before line lineNr"
 
-    self basicInsertLines:someText from:start to:end before:lineNr.
-    self addUndo:(DeleteRange line1:lineNr col1:1 line2:(lineNr+(end-start)+1) col2:0).
+    |text indent visLine w nLines "{ Class: SmallInteger }"
+     srcY "{ Class: SmallInteger }"
+     dstY "{ Class: SmallInteger }" |
+
+    self isReadOnly ifTrue:[
+        ^ self
+    ].
+
+    autoIndent ifTrue:[
+        indent := self leftIndentForLine:lineNr.
+
+        text := someText collect:[:ln||line|
+            ln notNil ifTrue:[
+                line := ln withoutLeadingSeparators.
+                (line isEmpty or:[indent == 0]) ifFalse:[
+                    line := (String new:indent), line
+                ].
+                line
+            ] ifFalse:[
+                nil
+            ]
+        ].
+    ] ifFalse:[
+        text := someText
+    ].
+
+    visLine := self listLineToVisibleLine:lineNr.
+    (shown not or:[visLine isNil]) ifTrue:[
+        self withoutRedrawInsertLines:text
+             from:start to:end
+             before:lineNr.
+    ] ifFalse:[
+        nLines := end - start + 1.
+        ((visLine + nLines) >= nLinesShown) ifTrue:[
+            self withoutRedrawInsertLines:text
+                 from:start to:end
+                 before:lineNr.
+            self redrawFromVisibleLine:visLine to:nLinesShown
+        ] ifFalse:[
+            w := self widthForScrollBetween:(lineNr + nLines)
+                                        and:(firstLineShown + nLines + nLinesShown).
+            srcY := topMargin + ((visLine - 1) * fontHeight).
+            dstY := srcY + (nLines * fontHeight).
+
+            "/
+            "/ scroll ...
+            "/
+            "
+             stupid: must catchExpose before inserting new
+             stuff - since catchExpose may perform redraws
+            "
+            self catchExpose.
+            self withoutRedrawInsertLines:text
+                 from:start to:end
+                 before:lineNr.
+            self 
+                copyFrom:self 
+                x:textStartLeft y:srcY
+                toX:textStartLeft y:dstY
+                width:w
+                height:(height - dstY)
+                async:true.
+            self redrawFromVisibleLine:visLine to:(visLine + nLines - 1).
+            self waitForExpose
+        ].
+    ].
+    widthOfWidestLine notNil ifTrue:[
+        text do:[:line |
+            widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:line).
+        ]
+    ].
+    self textChanged.
+
+    "Modified: 29.1.1997 / 13:02:39 / cg"
 !
 
 mergeLine:lineNr removeBlanks:removeBlanks
@@ -3427,7 +3537,7 @@
 
 withoutRedrawInsertLine:aString before:lineNr
     "insert the argument, aString before line lineNr; the string
-     becomes line nileNr; everything else is moved down; the view
+     becomes line lineNr; everything else is moved down; the view
      is not redrawn"
 
     self basicWithoutRedrawInsertLine:aString before:lineNr.
@@ -3437,118 +3547,15 @@
 withoutRedrawInsertLines:lines from:start to:end before:lineNr
     "insert a bunch of lines before line lineNr; the view is not redrawn"
 
-    |newLine newLines nLines|
-
-    self checkModificationsAllowed ifFalse:[ ^ self].
-
-    nLines := end - start + 1.
-    newLines := Array new:(lines size).
-    start to:end do:[:index |
-        newLine := lines at:index.
-        newLine notNil ifTrue:[
-            newLine isString ifTrue:[
-                newLine isBlank ifTrue:[
-                    newLine := nil
-                ] ifFalse:[
-                    (newLine includes:(Character tab)) ifTrue:[
-                        newLine := self withTabsExpanded:newLine
-                    ]
-                ]
-            ]
-        ].
-        newLines at:index put:newLine
-    ].
-    list isNil ifTrue: [
-        list := StringCollection new:(lineNr + nLines + 1)
-    ] ifFalse: [
-        list grow:((list size + nLines) max:(lineNr + nLines - 1))
-    ].
-
-    "I have changed 'replaceFrom:to:with:startingAt:' to correctly handle 
-     overlapping copy - if it didn't, we had to use:"
-"
-    index := list size.
-    [index > lineNr] whileTrue: [
-        pIndex := index - 1.
-        list at:index put:(list at:pIndex).
-        index := pIndex
-    ].
-"
-    list replaceFrom:(lineNr + nLines) to:(list size) with:list startingAt:lineNr.
-    list replaceFrom:lineNr to:(lineNr + nLines - 1) with:newLines startingAt:start.
-    self contentsChanged
-
-    "Modified: / 10.6.1998 / 19:01:16 / cg"
+    self basicWithoutRedrawInsertLines:lines from:start to:end before:lineNr.
+    self addUndo:(DeleteRange line1:lineNr col1:1 line2:lineNr+end-start+1 col2:0).
 !
 
 withoutRedrawInsertStringWithoutCRs:aString atLine:lineNr col:colNr
     "insert aString (which has no crs) at lineNr/colNr"
 
-    |isText strLen line lineSize newLine stringType sz|
-
-    (aString notNil) ifFalse:[ ^ self].
-
-    strLen := aString size.
-    self checkForExistingLine:lineNr.
-
-    stringType := aString string species.
-    isText     := aString isText.
-    line       := list at:lineNr.
-
-    line notNil ifTrue:[
-        lineSize := line size.
-        line isString ifFalse:[
-            stringType := line species
-        ] ifTrue:[
-            line bitsPerCharacter > aString bitsPerCharacter ifTrue:[
-                stringType := line string species
-            ].
-            line isText ifTrue:[ isText := true ]
-        ].
-    ] ifFalse:[
-        lineSize := 0
-    ].
-
-    ((colNr == 1) and:[lineSize == 0]) ifTrue: [
-        newLine := aString
-    ] ifFalse:[
-        (lineSize == 0 or:[colNr > lineSize]) ifTrue: [
-            sz := colNr + strLen - 1
-        ] ifFalse:[
-            sz := lineSize + strLen
-        ].
-
-        isText ifFalse:[
-            newLine := stringType new:sz
-        ] ifTrue:[
-            newLine := Text string:(stringType new:sz)
-        ].
-
-        (lineSize ~~ 0) ifTrue: [
-            (colNr > lineSize) ifTrue: [
-                newLine replaceFrom:1 to:lineSize
-                               with:line startingAt:1
-            ] ifFalse: [
-                newLine replaceFrom:1 to:(colNr - 1)
-                               with:line startingAt:1.
-                newLine replaceFrom:(colNr + strLen) to:(lineSize + strLen)
-                               with:line startingAt:colNr
-            ]
-        ].
-        newLine replaceFrom:colNr to:(colNr + strLen - 1) with:aString startingAt:1
-    ].
-
-    (aString includes:(Character tab)) ifTrue:[
-        newLine := self withTabsExpanded:newLine
-    ].
-
-    list at:lineNr put:newLine.
-    widthOfWidestLine notNil ifTrue:[
-        widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:newLine).
-    ].
-    self textChanged.
-
-    "Modified: / 10.6.1998 / 19:01:52 / cg"
+    self basicWithoutRedrawInsertStringWithoutCRs:aString atLine:lineNr col:colNr.
+    self addUndo:(DeleteRange line1:lineNr col1:colNr line2:lineNr col2:colNr+aString size-1).
 ! !
 
 !EditTextView methodsFor:'event handling'!
@@ -5930,7 +5937,7 @@
 !EditTextView::CompoundAction methodsFor:'execution'!
 
 value:editor
-    actions do:[:each | each value:editor]
+    actions reverseDo:[:each | each value:editor]
 ! !
 
 !EditTextView::InsertCharacter methodsFor:'accessing'!
@@ -6003,5 +6010,5 @@
 !EditTextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.346 2004-04-01 21:24:03 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.347 2004-04-01 21:46:57 cg Exp $'
 ! !