Workspace.st
changeset 6016 3362754911e4
parent 5990 31f05a6924f2
child 6020 79c1a6bb497a
--- a/Workspace.st	Fri Dec 23 10:04:14 2016 +0100
+++ b/Workspace.st	Fri Dec 23 10:04:46 2016 +0100
@@ -1304,31 +1304,7 @@
      in the first col
      (if no eol comment is available, a bracketing comment is used)."
 
-    |eolComment opening closing|
-
-    eolComment := commentStrings at:1.
-    eolComment isNil ifTrue:[
-	opening := (commentStrings at:2) at:1.
-	closing := (commentStrings at:2) at:2.
-	(opening isNil or:[closing isNil]) ifTrue:[^ self].
-    ].
-
-    line1 to:line2 do:[:lineNr |
-	|l|
-
-	l := self listAt:lineNr.
-	l isNil ifTrue:[l := ''].
-	eolComment notNil ifTrue:[
-	    l := eolComment , l
-	] ifFalse:[
-	    l := opening , l , closing
-	].
-	self replaceLine:lineNr with:l.
-	widthOfWidestLine notNil ifTrue:[
-	    widthOfWidestLine := widthOfWidestLine max:(self widthOfLineString:l).
-	].
-    ].
-    self textChanged.
+    self commentFrom:line1 to:line2 commentStrings:commentStrings.
 
     "Created: / 09-11-1997 / 01:05:35 / cg"
     "Modified: / 09-10-2006 / 10:46:44 / cg"
@@ -1339,44 +1315,7 @@
      All lines from line1 to line2 get an end-of-line comment
      in the first col."
 
-    |e commentPair opening closing|
-
-    (self checkModificationsAllowed) ifFalse:[ ^ self].
-    commentStrings isNil ifTrue:[ self beep. ^ self].
-
-    selectionStartLine isNil ifTrue:[
-	self
-	    undoableDo:[ self commentFrom:cursorLine to:cursorLine ]
-	    info:'Comment'.
-	^ self
-    ].
-
-    self
-	undoableDo:
-	    [
-		(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[
-		    self commentFrom:selectionStartLine to:selectionEndLine-1
-		] ifFalse:[
-		    commentPair := commentStrings at:2 ifAbsent:nil.
-		    commentPair isNil ifTrue:[
-			self beep.
-		    ] ifFalse:[
-			opening := commentPair at:1.
-			closing := commentPair at:2.
-			(opening isNil or:[closing isNil]) ifTrue:[^ self].
-
-			e := selectionEndCol.
-
-			self insertString:closing atLine:selectionEndLine col:e+1.
-			self insertString:opening atLine:selectionStartLine col:selectionStartCol.
-
-			selectionStartLine == selectionEndLine ifTrue:[e := e + opening size].
-			self selectFromLine:selectionStartLine col:selectionStartCol
-				     toLine:selectionEndLine col:e+closing size.
-		    ]
-		]
-	    ]
-	info:'comment'
+    self commentSelection:commentStrings
 
     "Created: / 9.11.1997 / 01:05:40 / cg"
     "Modified: / 5.4.1998 / 16:52:23 / cg"
@@ -1388,38 +1327,7 @@
      in the first col.
      (if no eol comment is available, a bracketing comment is removed)"
 
-    |eolComment opening closing rest|
-
-    eolComment := commentStrings at:1.
-    eolComment isNil ifTrue:[
-	opening := (commentStrings at:2) at:1.
-	closing := (commentStrings at:2) at:2.
-	(opening isNil or:[closing isNil]) ifTrue:[^ self].
-    ] ifFalse:[
-	rest := eolComment size + 1.
-    ].
-
-    line1 to:line2 do:[:lineNr |
-	|l|
-
-	l := self listAt:lineNr.
-	l notNil ifTrue:[
-	    eolComment notNil ifTrue:[
-		(l startsWith:eolComment) ifTrue:[
-		    l := l copyFrom:rest
-		]
-	    ] ifFalse:[
-		((l startsWith:opening)
-		and:[l endsWith:closing]) ifTrue:[
-		    l := l copyFrom:opening size + 1.
-		    l := l copyButLast:closing size.
-		]
-	    ].
-	    self replaceLine:lineNr with:l.
-	]
-    ].
-    widthOfWidestLine := nil.
-    self textChanged.
+    self uncommentFrom:line1 to:line2 commentStrings:commentStrings.
 
     "Created: / 09-11-1997 / 01:05:43 / cg"
     "Modified: / 09-10-2006 / 10:46:59 / cg"
@@ -1430,53 +1338,7 @@
      All lines from line1 to line2 get an end-of-line comment
      in the first col."
 
-    |e commentPair opening closing sz1 sz2 l1 l2 c1 c2|
-
-    (self checkModificationsAllowed) ifFalse:[ ^ self].
-    selectionStartLine isNil ifTrue:[
-	self
-	    undoableDo:[
-		self uncommentFrom:cursorLine to:cursorLine
-	    ]
-	    info:'Uncomment'.
-	^ self
-    ].
-
-    self
-	undoableDo:
-	    [
-		(selectionStartCol == 1 and:[selectionEndCol == 0]) ifTrue:[
-		    self uncommentFrom:selectionStartLine to:selectionEndLine-1
-		] ifFalse:[
-		    commentPair := commentStrings at:2.
-		    opening := commentPair at:1.
-		    closing := commentPair at:2.
-		    (opening isNil or:[closing isNil]) ifTrue:[^ self].
-
-		    sz1 := opening size.
-		    sz2 := closing size.
-
-		    ((self
-			stringAtLine:selectionStartLine
-			from:selectionStartCol
-			to:selectionStartCol+sz1 - 1) = opening
-		    and:[(self
-			stringAtLine:selectionEndLine
-			from:selectionEndCol - sz2 + 1
-			to:selectionEndCol) = closing ]) ifTrue:[
-
-			l2 := selectionEndLine.   c2 := selectionEndCol.
-			l1 := selectionStartLine. c1 := selectionStartCol.
-			self deleteCharsAtLine:l2 fromCol:c2-sz2+1 toCol:c2.
-			self deleteCharsAtLine:l1 fromCol:c1 toCol:c1+sz1-1.
-
-			e := c2 - sz2.
-			l1 == l2 ifTrue:[e := e - sz1].
-			self selectFromLine:l1 col:c1 toLine:l2 col:e.
-		    ]
-		]
-	    ]
-	info:'uncomment'
+    self uncommentSelection:commentStrings
 
     "Modified: / 7.1.1997 / 20:13:32 / cg"
     "Created: / 9.11.1997 / 01:05:46 / cg"