Permalink
Browse files

cursorManager: Fix unselecting to the beginning of the line. (#5746)

  • Loading branch information...
jcsteh committed May 3, 2017
1 parent 11b3136 commit 28fe5b8d91e9c020283627a21d20833ceeba2af2
Showing with 24 additions and 5 deletions.
  1. +7 −5 source/cursorManager.py
  2. +17 −0 tests/unit/test_cursorManager.py
View
@@ -324,11 +324,13 @@ def script_selectParagraph_back(self, gesture):
self._selectionMovementScriptHelper(unit=textInfos.UNIT_PARAGRAPH, direction=-1)
def script_selectToBeginningOfLine(self,gesture):
curInfo=self.makeTextInfo(textInfos.POSITION_SELECTION)
curInfo.collapse()
tempInfo=curInfo.copy()
tempInfo.expand(textInfos.UNIT_LINE)
if curInfo.compareEndPoints(tempInfo,"startToStart")>0:
# Make sure the active endpoint of the selection is after the start of the line.
sel=self.makeTextInfo(textInfos.POSITION_SELECTION)
line=sel.copy()
line.collapse()
line.expand(textInfos.UNIT_LINE)
compOp="startToStart" if self._lastSelectionMovedStart else "endToStart"
if sel.compareEndPoints(line,compOp)>0:
self._selectionMovementScriptHelper(unit=textInfos.UNIT_LINE,direction=-1)
def script_selectToEndOfLine(self,gesture):
@@ -124,6 +124,23 @@ def test_selectToBeginningOfLineAtBeginning(self):
cm.script_selectToBeginningOfLine(None)
self.assertEqual(cm.selectionOffsets, (3, 3)) # No selection
def test_unselectToBeginningOfLine(self):
"""Depends on behavior tested by test_selectNextChar.
"""
cm = CursorManager(text="ab\ncd", selection=(3, 3)) # Caret at "c"
cm.script_selectCharacter_forward(None) # "c" selected
cm.script_selectToBeginningOfLine(None) # "c" unselected
self.assertEqual(cm.selectionOffsets, (3, 3)) # Caret at "c", no selection
def test_selectToEndThenBeginningOfLine(self):
"""Test for #5746.
Depends on behavior tested in test_selectToEndOfLine and test_selectToBeginningOfLine.
"""
cm = CursorManager(text="ab") # Caret at "a"
cm.script_selectToEndOfLine(None)
cm.script_selectToBeginningOfLine(None)
self.assertEqual(cm.selectionOffsets, (0, 0)) # Caret at "a", no selection
class TestSelectAll(unittest.TestCase):
"""Tests the select all command starting from different caret positions.
"""

0 comments on commit 28fe5b8

Please sign in to comment.