Fix assertion failure in `EditTextView` jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 19 Mar 2019 15:13:59 +0000
branchjv
changeset 6565 e4757590c90c
parent 6519 6777704804e1
child 6607 1da320242101
Fix assertion failure in `EditTextView` ...when: * there's a selection, * then user presses CTRL+Left (or CTRL+Right) and * then user presses CTRL+SHIFT+Left (or CTRL+SHIFT+Right). After pressing CTRL+Left (or CTRL+Right) the selection should go. Instead, it did not, cursor moved internaly as usual but not updating selection. So the cursor is not either at selection start nor at end and thus assertion fails. This commit fixes this by unselecting any text before moving cursor to previous / next word.
EditTextView.st
tests/EditTextViewTests.st
--- a/EditTextView.st	Wed Nov 28 13:16:38 2018 +0000
+++ b/EditTextView.st	Tue Mar 19 15:13:59 2019 +0000
@@ -5758,8 +5758,9 @@
             self addToSelectionAfter:[  
                 self cursorToNextWord. 
             ]
-        ] ifFalse:[ 
-            self cursorToNextWord
+        ] ifFalse:[
+            self hasSelection ifTrue:[ self unselect ].
+            self cursorToNextWord.
         ].
         ^self
     ].
@@ -5769,7 +5770,8 @@
             self addToSelectionAfter:[      
                 self cursorToPreviousWord. 
             ]
-        ] ifFalse:[ 
+        ] ifFalse:[
+            self hasSelection ifTrue:[ self unselect ].
             self cursorToPreviousWord.                                
         ].
         ^self
@@ -5964,7 +5966,7 @@
 
     "Modified: / 06-02-1998 / 11:59:59 / stefan"
     "Modified: / 14-07-2011 / 12:08:28 / cg"
-    "Modified: / 11-10-2017 / 23:08:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-03-2019 / 15:04:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 executeKeyboardMacro:cmdMacro
--- a/tests/EditTextViewTests.st	Wed Nov 28 13:16:38 2018 +0000
+++ b/tests/EditTextViewTests.st	Tue Mar 19 15:13:59 2019 +0000
@@ -91,6 +91,64 @@
     "Created: / 24-02-2015 / 08:21:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+test_02a
+    textView contents: 'Hello, here is Smalltalk X'. 
+    textView setCursorCol: 14.
+
+    textViewInteractor type: #SelectWord.
+    self assert: textView selectionAsString = 'is'.
+
+    textViewInteractor type: #CursorRight.
+    self assert: textView hasSelection not.
+    self assert: textView cursorCol == 15.
+
+    "Created: / 19-03-2019 / 14:58:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_02b
+    textView contents: 'Hello, here is Smalltalk X'. 
+    textView setCursorCol: 14.
+
+    textViewInteractor type: #SelectWord.
+    self assert: textView selectionAsString = 'is'.
+
+    textViewInteractor type: #NextWord.
+    self assert: textView hasSelection not.
+    self assert: textView cursorCol == 16.
+
+    "Created: / 19-03-2019 / 14:59:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-03-2019 / 15:03:48 / jv"
+!
+
+test_02c
+    textView contents: 'Hello, here is Smalltalk X'. 
+    textView setCursorCol: 14.
+
+    textViewInteractor type: #SelectWord.
+    self assert: textView selectionAsString = 'is'.
+
+    textViewInteractor type: #CursorLeft.
+    self assert: textView hasSelection not.
+    self assert: textView cursorCol == 13.
+
+    "Created: / 19-03-2019 / 15:02:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_02d
+    textView contents: 'Hello, here is Smalltalk X'. 
+    textView setCursorCol: 14.
+
+    textViewInteractor type: #SelectWord.
+    self assert: textView selectionAsString = 'is'.
+
+    textViewInteractor type: #PreviousWord.
+    self assert: textView hasSelection not.
+    self assert: textView cursorCol == 13.
+
+    "Created: / 19-03-2019 / 15:02:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-03-2019 / 15:04:56 / jv"
+!
+
 test_issue124_case1_01
     "
     See https://swing.fit.cvut.cz/projects/stx-jv/ticket/124#comment:19