Skip to content

Commit 72395d9

Browse files
committed
Improving logic
1 parent a317a60 commit 72395d9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/textual/widgets/_text_area.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,12 +1838,12 @@ def action_cursor_left(self, select: bool = False) -> None:
18381838
Args:
18391839
select: If True, select the text while moving.
18401840
"""
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)
1841+
target = (
1842+
self.get_cursor_left_location()
1843+
if select or self.selection.is_empty
1844+
else min(*self.selection)
1845+
)
1846+
self.move_cursor(target, select=select)
18471847

18481848
def get_cursor_left_location(self) -> Location:
18491849
"""Get the location the cursor will move to if it moves left.
@@ -1861,12 +1861,12 @@ def action_cursor_right(self, select: bool = False) -> None:
18611861
Args:
18621862
select: If True, select the text while moving.
18631863
"""
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)
1864+
target = (
1865+
self.get_cursor_right_location()
1866+
if select or self.selection.is_empty
1867+
else max(*self.selection)
1868+
)
1869+
self.move_cursor(target, select=select)
18701870

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

0 commit comments

Comments
 (0)