Bugfix for FindPrev (Alt+B) operation. text-view-selection-refactoring
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 27 Mar 2014 12:57:01 +0000
branchtext-view-selection-refactoring
changeset 4974 def8e296a561
parent 4973 e78f1243d4ef
child 4975 bee454945bf7
Bugfix for FindPrev (Alt+B) operation.
EditTextView.st
--- a/EditTextView.st	Thu Mar 27 10:08:47 2014 +0000
+++ b/EditTextView.st	Thu Mar 27 12:57:01 2014 +0000
@@ -7641,7 +7641,9 @@
         ]
     ].
 
-    ^ startCol @ cursorLine
+    ^ startCol @ startLine
+
+    "Modified: / 27-03-2014 / 11:57:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 startPositionForSearchForward
@@ -7932,18 +7934,29 @@
 !
 
 selectFromLine:startLine col:startCol toLine:endLine col:endCol
+    | cursorAtTheBeginning cursorAtTheEnd |
 
     super selectFromLine:startLine col:startCol toLine:endLine col:endCol.
-    "JV: That's atctuall rubbish as then you loose the original positon
-     and if user wants to extend/shring the selection further, you don't know
-     from which end to do it!!"
-"/    (selectionEndLine notNil and:[self autoMoveCursorToEndOfSelection]) ifTrue:[
-"/        self cursorLine:selectionEndLine col:(selectionEndCol + 1).
-"/    ].
+    "/ Do not clobber cursor position if it is already either at begging
+    "/ or end (so we don't loose cursor's 'logical' position. If it is not,
+    "/ then move it - selection moved by some command (i.e., selection was not
+    "/ extended by user
+
+    cursorAtTheBeginning := (startLine == cursorLine) and:[startCol == cursorCol].    
+    cursorAtTheBeginning ifFalse:[
+        cursorAtTheEnd := (endLine == cursorLine) and:[endCol == (cursorCol - 1)].          
+        cursorAtTheEnd ifFalse:[
+            (selectionEndLine notNil and:[self autoMoveCursorToEndOfSelection]) ifTrue:[
+                self cursorLine:selectionEndLine col:(selectionEndCol + 1).
+            ] ifFalse:[ 
+                self cursorLine:selectionStartLine col:(selectionStartCol).
+            ].
+        ]
+    ].
+
     typeOfSelection := nil
 
-    "Modified: / 27-08-2013 / 13:28:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (comment): / 27-08-2013 / 15:58:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 27-03-2014 / 12:48:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 selectToEndOfLine