mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
selection fix
This commit is contained in:
@@ -46,8 +46,8 @@ class Selection(NamedTuple):
|
||||
start_line, start_offset = self.start.transpose
|
||||
|
||||
if self.end is None:
|
||||
end_line = len(lines) - 1
|
||||
end_offset = len(lines[end_line])
|
||||
end_line = len(lines)
|
||||
end_offset = len(lines[-1])
|
||||
else:
|
||||
end_line, end_offset = self.end.transpose
|
||||
end_line = min(len(lines), end_line)
|
||||
|
||||
22
tests/test_selection.py
Normal file
22
tests/test_selection.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
|
||||
from textual.geometry import Offset
|
||||
from textual.selection import Selection
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"text,selection,expected",
|
||||
[
|
||||
("Hello", Selection(None, None), "Hello"),
|
||||
("Hello\nWorld", Selection(None, None), "Hello\nWorld"),
|
||||
("Hello\nWorld", Selection(Offset(0, 1), None), "World"),
|
||||
("Hello\nWorld", Selection(None, Offset(5, 0)), "Hello"),
|
||||
("Foo", Selection(Offset(0, 0), Offset(1, 0)), "F"),
|
||||
("Foo", Selection(Offset(1, 0), Offset(2, 0)), "o"),
|
||||
("Foo", Selection(Offset(0, 0), Offset(2, 0)), "Fo"),
|
||||
("Foo", Selection(Offset(0, 0), None), "Foo"),
|
||||
],
|
||||
)
|
||||
def test_extract(text: str, selection: Selection, expected: str) -> None:
|
||||
"""Test Selection.extract"""
|
||||
assert selection.extract(text) == expected
|
||||
Reference in New Issue
Block a user