File tree Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010### Fixed
1111
1212- Fixed type hint aliasing for App under TYPE_CHECKING https://github.com/Textualize/textual/pull/6152
13+ - Fixed for text selection with double width characters https://github.com/Textualize/textual/pull/6186
1314
1415### Changed
1516
Original file line number Diff line number Diff line change @@ -1738,7 +1738,6 @@ def _watch__select_end(
17381738 Args:
17391739 select_end: The end selection.
17401740 """
1741-
17421741 if select_end is None or self ._select_start is None :
17431742 # Nothing to select
17441743 return
Original file line number Diff line number Diff line change @@ -56,12 +56,12 @@ def extract(self, text: str) -> str:
5656 return lines [start_line ][start_offset :end_offset ]
5757
5858 selection : list [str ] = []
59- selected_lines = lines [start_line : end_line ]
59+ selected_lines = lines [start_line : end_line + 1 ]
6060 if len (selected_lines ) >= 2 :
6161 first_line , * mid_lines , last_line = selected_lines
6262 selection .append (first_line [start_offset :])
6363 selection .extend (mid_lines )
64- selection .append (last_line [: end_offset + 1 ])
64+ selection .append (last_line [:end_offset ])
6565 else :
6666 return lines [start_line ][start_offset :end_offset ]
6767 return "\n " .join (selection )
Original file line number Diff line number Diff line change 11import pytest
22
3+ from textual .app import App , ComposeResult
34from textual .geometry import Offset
45from textual .selection import Selection
6+ from textual .widgets import Static
57
68
79@pytest .mark .parametrize (
2022def test_extract (text : str , selection : Selection , expected : str ) -> None :
2123 """Test Selection.extract"""
2224 assert selection .extract (text ) == expected
25+
26+
27+ async def test_double_width ():
28+ """Test that selection works with double width characters."""
29+
30+ TEXT = """😂❤️👍Select😊🙏😍\n me🔥💯😭😂❤️👍"""
31+
32+ class TextSelectApp (App ):
33+ def compose (self ) -> ComposeResult :
34+ yield Static (TEXT )
35+
36+ app = TextSelectApp ()
37+ async with app .run_test () as pilot :
38+ await pilot .pause ()
39+ assert await pilot .mouse_down (offset = (2 , 0 ))
40+ await pilot .pause ()
41+ assert await pilot .mouse_up (offset = (7 , 1 ))
42+ selected_text = app .screen .get_selected_text ()
43+ expected = "❤️👍Select😊🙏😍\n me🔥💯😭"
44+
45+ assert selected_text == expected
You can’t perform that action at this time.
0 commit comments