EditTextView.st
changeset 2505 9204d5313979
parent 2491 f3e207ae5156
child 2506 5568d67dbddd
--- a/EditTextView.st	Fri Dec 14 11:57:30 2001 +0100
+++ b/EditTextView.st	Fri Dec 21 12:54:25 2001 +0100
@@ -2330,6 +2330,35 @@
     self makeCursorVisibleAndShowCursor:wasOn.
 !
 
+parenthizeSelection
+    |newSelectionEnd|
+
+    self hasSelection ifFalse:[^ self].
+
+    newSelectionEnd := selectionEndCol.
+
+    (self characterAtLine:selectionStartLine col:selectionStartCol) == $( ifTrue:[
+        (self characterAtLine:selectionEndLine col:selectionEndCol) == $) ifTrue:[
+            self deleteCharAtLine:selectionEndLine col:selectionEndCol.
+            newSelectionEnd := newSelectionEnd-1.
+        ].
+        self deleteCharAtLine:selectionStartLine col:selectionStartCol.
+        selectionStartLine == selectionEndLine ifTrue:[
+            newSelectionEnd := newSelectionEnd-1.
+        ]
+    ] ifFalse:[
+        self insertString:')' atLine:selectionEndLine col:selectionEndCol+1.
+        newSelectionEnd := newSelectionEnd+1.
+        self insertString:'(' atLine:selectionStartLine col:selectionStartCol.
+        selectionStartLine == selectionEndLine ifTrue:[
+            newSelectionEnd := newSelectionEnd+1.
+        ]
+    ].
+    self 
+        selectFromLine:selectionStartLine col:selectionStartCol
+        toLine:selectionEndLine col:newSelectionEnd.
+!
+
 removeTrailingBlankLines
     "remove all blank lines at end of text"
 
@@ -3337,10 +3366,11 @@
      or:[key == #BasicBackspace]) ifTrue:[
         selectionStartLine notNil ifTrue:[
             (key == #BasicBackspace) ifTrue:[
-                ^ self deleteSelection.
-            ] ifFalse:[
-                ^ self copyAndDeleteSelection.
+                self deleteSelection.
+            ] ifFalse: [
+                self copyAndDeleteSelection.
             ].
+            ^ self
         ].
 
         self makeCursorVisible.
@@ -3490,6 +3520,11 @@
         ].
     ].
 
+    (key == #Ctrl8 or:[key == #Ctrl9]) ifTrue:[
+        self parenthizeSelection.
+        ^ self.
+    ].
+
     (key == #Accept)  ifTrue:[^ self accept].
 
     ((key == #Paste) or:[key == #Insert]) ifTrue:[self pasteOrReplace. ^self].
@@ -3499,13 +3534,14 @@
     (key == #Replace) ifTrue:[self replace. ^self].
     (key == #SelectWord) ifTrue:[
         self makeCursorVisible.
-        ^ self selectWordUnderCursor. 
+        self selectWordUnderCursor.
+        ^ self
     ].
 
-    (key == #SearchMatchingParent) ifTrue:[^ self searchForMatchingParenthesis.].
-    (key == #SelectMatchingParents) ifTrue:[^ self searchForAndSelectMatchingParenthesis.].
-    (key == #SelectToEnd) ifTrue:[^ self selectUpToEnd.].
-    (key == #SelectFromBeginning) ifTrue:[^ self selectFromBeginning.].
+    (key == #SearchMatchingParent) ifTrue:[self searchForMatchingParenthesis. ^ self].
+    (key == #SelectMatchingParents) ifTrue:[self searchForAndSelectMatchingParenthesis. ^ self].
+    (key == #SelectToEnd) ifTrue:[self selectUpToEnd. ^ self].
+    (key == #SelectFromBeginning) ifTrue:[self selectFromBeginning. ^ self].
 
 " disabled - nobody liked it ...
   and if you like it, its better done in the keymap.
@@ -3543,7 +3579,8 @@
             selectionStartLine := selectionEndLine := clickStartLine := cursorLine.
             selectionStartCol := selectionEndCol := clickStartCol := cursorCol.
             expandingTop := false.
-            ^ self redrawLine:selectionStartLine. 
+            self redrawLine:selectionStartLine.
+            ^ self.
         ].
 
         selectionStartLine notNil ifTrue:[
@@ -3564,7 +3601,8 @@
                 cursorCol == 1 ifTrue:[^ self].
             ].
         ].
-        self cursorRight. ^self
+        self cursorRight. 
+        ^ self
     ].
     (key == #CursorDown) ifTrue:[
         (shifted and:[selectionStartLine isNil]) ifTrue:[
@@ -3572,7 +3610,8 @@
             selectionStartCol := clickStartCol := selectionEndCol := cursorCol.
             self redrawLine:selectionStartLine. 
             expandingTop := false.
-            ^ self redrawLine:selectionEndLine. 
+            self redrawLine:selectionEndLine.
+            ^ self 
         ].
 
         selectionStartLine notNil ifTrue:[
@@ -3618,14 +3657,16 @@
                     selectionStartLine := selectionEndLine := clickStartLine := cursorLine.
                     selectionEndCol := clickStartCol := cursorCol-1.
                     selectionStartCol := cursorCol-1.
-                    ^ self redrawLine:selectionStartLine. 
+                    self redrawLine:selectionStartLine.
+                    ^ self 
                 ]
             ] ifFalse:[
                 cursorLine > 1 ifTrue:[
                     selectionEndLine := clickStartLine := cursorLine.
                     selectionEndCol := selectionStartCol := clickStartCol := cursorCol.
                     selectionStartLine := cursorLine - 1.
-                    ^ self redrawFromLine:selectionStartLine to:cursorLine. 
+                    self redrawFromLine:selectionStartLine to:cursorLine.
+                    ^ self 
                 ]
             ]
         ].
@@ -3645,9 +3686,11 @@
                 shifted ifTrue:[
                     (key == #CursorUp) ifTrue:[
                         clickLine := cursorLine.
-                        ^ self expandSelectionUp.
+                        self expandSelectionUp.
+                    ] ifFalse:[
+                        self expandSelectionLeft.
                     ].
-                    ^ self expandSelectionLeft.
+                    ^ self 
                 ].
                 self unselect. 
             ].
@@ -3672,7 +3715,8 @@
 
     (key == #Return)    ifTrue:[
         shifted ifTrue:[
-            self unselect. self cursorReturn. ^self
+            self unselect. self cursorReturn. 
+            ^ self
         ].
         self isReadOnly ifTrue:[
             self unselect; makeCursorVisible.
@@ -3702,7 +3746,7 @@
                 ].
             ].
         ].
-        ^self
+        ^ self
     ].
 
     (key == #Tab) ifTrue:[
@@ -3716,7 +3760,7 @@
             "
             "/ self unselect. self cursorBacktab.
             self unselect. self cursorTab. 
-            ^self
+            ^ self
         ].
 
         "
@@ -3729,20 +3773,22 @@
             self unselect. self cursorTab. ^self
         ].
         self unselect. self insertTabAtCursor. 
-        ^self
+        ^ self
     ].
 
     (key == #Delete
      or:[key == #BasicDelete]) ifTrue:[
         selectionStartLine notNil ifTrue:[
             (key == #BasicDelete) ifTrue:[
-                ^ self deleteSelection.
+                self deleteSelection.
             ] ifFalse:[
-                ^ self copyAndDeleteSelection.
+                self copyAndDeleteSelection.
             ].
+            ^ self
         ].
         self makeCursorVisible.
-        self deleteCharAtCursor. ^self
+        self deleteCharAtCursor. 
+        ^ self
     ].
 
     (key == #BeginOfText) ifTrue:[     "i.e. HOME"
@@ -3761,28 +3807,33 @@
         ] ifFalse:[
             self cursorToLastVisibleLine
         ].
-        ^self
+        ^ self
     ].
     ((key == #Escape)
     or:[key == #SelectLineFromBeginning])    ifTrue:[
         self makeCursorVisible.
-        self unselect. self selectCursorLineFromBeginning. ^ self
+        self unselect. self selectCursorLineFromBeginning. 
+        ^ self
     ].
     (key == #SelectLine)    ifTrue:[
         self makeCursorVisible.
-        self unselect. self selectCursorLine. ^ self
+        self unselect. self selectCursorLine. 
+        ^ self
     ].
     (key == #ExpandSelectionByLine)    ifTrue:[
 "/        self makeCursorVisible.
-        self selectExpandCursorLine. ^ self
+        self selectExpandCursorLine. 
+        ^ self
     ].
     (key == #DeleteLine)    ifTrue:[
         self makeCursorVisible.
-        self unselect. self deleteCursorLine. ^self
+        self unselect. self deleteCursorLine. 
+        ^ self
     ].
     (key == #InsertLine)    ifTrue:[
         self makeCursorVisible.
-        self unselect. self insertLine:nil before:cursorLine. ^self
+        self unselect. self insertLine:nil before:cursorLine. 
+        ^ self
     ].
     super keyPress:key x:x y:y
 
@@ -5047,5 +5098,5 @@
 !EditTextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.263 2001-12-04 09:38:14 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.264 2001-12-21 11:54:25 cg Exp $'
 ! !