fixed cut to not compress multiple blanks.
authorClaus Gittinger <cg@exept.de>
Wed, 24 Mar 1999 21:06:11 +0100
changeset 1818 aa16d9b96e40
parent 1817 1a9e22f755c8
child 1819 963883688bc7
fixed cut to not compress multiple blanks. preps for undo.
ETxtView.st
EditTextView.st
--- a/ETxtView.st	Tue Mar 23 13:45:43 1999 +0100
+++ b/ETxtView.st	Wed Mar 24 21:06:11 1999 +0100
@@ -2261,7 +2261,7 @@
     "delete all text from startLine/startCol to endLine/endCol -
      joining lines if nescessary"
 
-    |line lineSize|
+    |line newLine lineSize nMore|
 
     self checkModificationsAllowed ifFalse:[ ^ self].
     list isNil ifTrue:[^ self].
@@ -2299,12 +2299,18 @@
         line := list at:startLine.
         lineSize := line size.
         (startCol > lineSize) ifTrue:[
+            newLine := line.
             line isNil ifTrue:[
-                line := String new:(startCol - 1)
+                newLine := String new:(startCol - 1)
             ] ifFalse:[
-                line := line , (line species new:(startCol - 1 - lineSize))
+                nMore := startCol - 1 - lineSize.
+                nMore > 0 ifTrue:[
+                    newLine := line , (line species new:nMore)
+                ]
             ].
-            list at:startLine put:line.
+            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.
@@ -2315,7 +2321,7 @@
     ].
 
     "/ merge the left rest of 1st line with right rest of last line into one
-    self mergeLine:startLine
+    self mergeLine:startLine removeBlanks:false
 
     "Modified: / 10.11.1998 / 23:52:59 / cg"
 !
@@ -3592,7 +3598,7 @@
 cut
     "cut selection into copybuffer"
 
-    |line col history sel|
+    |line col history sel s|
 
     (self checkModificationsAllowed) ifFalse:[
         self flash.
@@ -3601,10 +3607,12 @@
 
     sel := self selection.
     sel notNil ifTrue:[
-        lastString := sel asStringWithCRs.
+        lastString := s := sel asStringWithCRs.
         line := selectionStartLine.
         col := selectionStartCol.
-        undoAction := [self insertString:lastString atLine:line col:col].
+        undoAction := [ self cursorLine:line col:col.
+                        self insertLines:(Array with:s) withCR:false.
+                      ].
 
         "
          remember in CopyBuffer
@@ -3660,7 +3668,7 @@
                   ).
     ] ifFalse:[
         items := #(
-"/                       ('undo'     undo                   )
+                        ('undo'     undo                   )
                         ('again'   again            Again  )
                         ('-'                               )
                         ('copy'    copySelection    Copy   )
@@ -3704,6 +3712,9 @@
     (self hasSelection not or:[self isReadOnly]) ifTrue:[
         m disable:#cut.
     ].
+    (undoAction isNil) ifTrue:[
+        m disable:#undo.
+    ].
     acceptEnabled == false ifTrue:[
         m disable:#accept
     ].
@@ -3735,7 +3746,7 @@
 paste:someText
     "paste someText at cursor"
 
-    |s nLines startLine startCol|
+    |s nLines startLine startCol l1 l2 c1 c2|
 
     self checkModificationsAllowed ifFalse:[^ self].
 
@@ -3752,13 +3763,17 @@
         (nLines := s size) == 0 ifTrue:[^ self].
         (nLines == 1 and:[(s at:1) size == 0]) ifTrue:[^ self].
 
-        startLine := cursorLine.
-        startCol := cursorCol.
+        startLine := l1 := cursorLine.
+        startCol := c1 := cursorCol.
         self insertLines:(s withTabsExpanded) withCR:false.
-        self selectFromLine:startLine col:startCol
-                     toLine:cursorLine col:(cursorCol - 1).
+        l2 := cursorLine.
+        c2 := (cursorCol - 1).
+        self selectFromLine:l1 col:c1 toLine:l2 col:c2.
         typeOfSelection := #paste.
-        undoAction := [self cut].
+        undoAction := [ self unselect.
+                        self deleteFromLine:l1 col:c1 toLine:l2 col:c2.
+                        self cursorLine:l1 col:c1.
+                      ].
     ]
 
     "Modified: / 14.2.1996 / 11:14:14 / stefan"
@@ -4518,12 +4533,13 @@
     "currently not implemented"
 
     undoAction notNil ifTrue:[
-	undoAction value
+        undoAction value.
+        undoAction := nil.
     ]
 ! !
 
 !EditTextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Attic/ETxtView.st,v 1.195 1999-03-23 12:45:43 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Attic/ETxtView.st,v 1.196 1999-03-24 20:06:11 cg Exp $'
 ! !
--- a/EditTextView.st	Tue Mar 23 13:45:43 1999 +0100
+++ b/EditTextView.st	Wed Mar 24 21:06:11 1999 +0100
@@ -2261,7 +2261,7 @@
     "delete all text from startLine/startCol to endLine/endCol -
      joining lines if nescessary"
 
-    |line lineSize|
+    |line newLine lineSize nMore|
 
     self checkModificationsAllowed ifFalse:[ ^ self].
     list isNil ifTrue:[^ self].
@@ -2299,12 +2299,18 @@
         line := list at:startLine.
         lineSize := line size.
         (startCol > lineSize) ifTrue:[
+            newLine := line.
             line isNil ifTrue:[
-                line := String new:(startCol - 1)
+                newLine := String new:(startCol - 1)
             ] ifFalse:[
-                line := line , (line species new:(startCol - 1 - lineSize))
+                nMore := startCol - 1 - lineSize.
+                nMore > 0 ifTrue:[
+                    newLine := line , (line species new:nMore)
+                ]
             ].
-            list at:startLine put:line.
+            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.
@@ -2315,7 +2321,7 @@
     ].
 
     "/ merge the left rest of 1st line with right rest of last line into one
-    self mergeLine:startLine
+    self mergeLine:startLine removeBlanks:false
 
     "Modified: / 10.11.1998 / 23:52:59 / cg"
 !
@@ -3592,7 +3598,7 @@
 cut
     "cut selection into copybuffer"
 
-    |line col history sel|
+    |line col history sel s|
 
     (self checkModificationsAllowed) ifFalse:[
         self flash.
@@ -3601,10 +3607,12 @@
 
     sel := self selection.
     sel notNil ifTrue:[
-        lastString := sel asStringWithCRs.
+        lastString := s := sel asStringWithCRs.
         line := selectionStartLine.
         col := selectionStartCol.
-        undoAction := [self insertString:lastString atLine:line col:col].
+        undoAction := [ self cursorLine:line col:col.
+                        self insertLines:(Array with:s) withCR:false.
+                      ].
 
         "
          remember in CopyBuffer
@@ -3660,7 +3668,7 @@
                   ).
     ] ifFalse:[
         items := #(
-"/                       ('undo'     undo                   )
+                        ('undo'     undo                   )
                         ('again'   again            Again  )
                         ('-'                               )
                         ('copy'    copySelection    Copy   )
@@ -3704,6 +3712,9 @@
     (self hasSelection not or:[self isReadOnly]) ifTrue:[
         m disable:#cut.
     ].
+    (undoAction isNil) ifTrue:[
+        m disable:#undo.
+    ].
     acceptEnabled == false ifTrue:[
         m disable:#accept
     ].
@@ -3735,7 +3746,7 @@
 paste:someText
     "paste someText at cursor"
 
-    |s nLines startLine startCol|
+    |s nLines startLine startCol l1 l2 c1 c2|
 
     self checkModificationsAllowed ifFalse:[^ self].
 
@@ -3752,13 +3763,17 @@
         (nLines := s size) == 0 ifTrue:[^ self].
         (nLines == 1 and:[(s at:1) size == 0]) ifTrue:[^ self].
 
-        startLine := cursorLine.
-        startCol := cursorCol.
+        startLine := l1 := cursorLine.
+        startCol := c1 := cursorCol.
         self insertLines:(s withTabsExpanded) withCR:false.
-        self selectFromLine:startLine col:startCol
-                     toLine:cursorLine col:(cursorCol - 1).
+        l2 := cursorLine.
+        c2 := (cursorCol - 1).
+        self selectFromLine:l1 col:c1 toLine:l2 col:c2.
         typeOfSelection := #paste.
-        undoAction := [self cut].
+        undoAction := [ self unselect.
+                        self deleteFromLine:l1 col:c1 toLine:l2 col:c2.
+                        self cursorLine:l1 col:c1.
+                      ].
     ]
 
     "Modified: / 14.2.1996 / 11:14:14 / stefan"
@@ -4518,12 +4533,13 @@
     "currently not implemented"
 
     undoAction notNil ifTrue:[
-	undoAction value
+        undoAction value.
+        undoAction := nil.
     ]
 ! !
 
 !EditTextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.195 1999-03-23 12:45:43 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.196 1999-03-24 20:06:11 cg Exp $'
 ! !