Skip to content

Commit a317a60

Browse files
committed
Cursor left and right standardisation when theres an active selection
1 parent 8091a73 commit a317a60

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/textual/widgets/_text_area.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,8 +1838,12 @@ def action_cursor_left(self, select: bool = False) -> None:
18381838
Args:
18391839
select: If True, select the text while moving.
18401840
"""
1841-
target = self.get_cursor_left_location()
1842-
self.move_cursor(target, select=select)
1841+
if self.selection.is_empty:
1842+
target = self.get_cursor_left_location()
1843+
self.move_cursor(target, select=select)
1844+
else:
1845+
start, end = self.selection
1846+
self.move_cursor(min(start, end), select=select)
18431847

18441848
def get_cursor_left_location(self) -> Location:
18451849
"""Get the location the cursor will move to if it moves left.
@@ -1857,8 +1861,12 @@ def action_cursor_right(self, select: bool = False) -> None:
18571861
Args:
18581862
select: If True, select the text while moving.
18591863
"""
1860-
target = self.get_cursor_right_location()
1861-
self.move_cursor(target, select=select)
1864+
if self.selection.is_empty:
1865+
target = self.get_cursor_right_location()
1866+
self.move_cursor(target, select=select)
1867+
else:
1868+
start, end = self.selection
1869+
self.move_cursor(max(start, end), select=select)
18621870

18631871
def get_cursor_right_location(self) -> Location:
18641872
"""Get the location the cursor will move to if it moves right.

0 commit comments

Comments
 (0)