From 9be5ee5ddfee30dcff39040cef9c8ba580f5eaf8 Mon Sep 17 00:00:00 2001 From: Jakob Zahn Date: Thu, 9 May 2024 00:50:26 +0200 Subject: [PATCH] Apply row offsets conditionally --- src/textual/document/_edit.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/textual/document/_edit.py b/src/textual/document/_edit.py index d0bd5ad83d..dc9c04aeba 100644 --- a/src/textual/document/_edit.py +++ b/src/textual/document/_edit.py @@ -81,8 +81,16 @@ def do(self, text_area: TextArea, record_selection: bool = True) -> EditResult: ) row_offset = new_edit_to_row - edit_bottom_row - target_selection_start_row = selection_start_row + row_offset - target_selection_end_row = selection_end_row + row_offset + target_selection_start_row = ( + selection_start_row + row_offset + if edit_bottom_row <= selection_start_row + else selection_start_row + ) + target_selection_end_row = ( + selection_end_row + row_offset + if edit_bottom_row <= selection_end_row + else selection_end_row + ) if self.maintain_selection_offset: self._updated_selection = Selection(