From 8c1cd2047ee2deb0f8a8233bdb5e1bd2c72fed75 Mon Sep 17 00:00:00 2001 From: phg Date: Tue, 29 Jul 2025 22:55:38 +0200 Subject: [PATCH] Update DataTable cursor position handling when moving entries --- src/hosts/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hosts/main.py b/src/hosts/main.py index 9f8ae8a..a0069bb 100644 --- a/src/hosts/main.py +++ b/src/hosts/main.py @@ -486,7 +486,12 @@ class HostsManagerApp(App): if self.selected_entry_index > 0: self.selected_entry_index -= 1 self.populate_entries_table() - self.restore_cursor_position(None) + # Update the DataTable cursor position to follow the moved entry + table = self.query_one("#entries-table", DataTable) + display_index = self.actual_index_to_display_index(self.selected_entry_index) + if table.row_count > 0 and display_index < table.row_count: + table.move_cursor(row=display_index) + self.update_entry_details() self.update_status(message) else: self.update_status(f"Error moving entry: {message}") @@ -507,7 +512,12 @@ class HostsManagerApp(App): if self.selected_entry_index < len(self.hosts_file.entries) - 1: self.selected_entry_index += 1 self.populate_entries_table() - self.restore_cursor_position(None) + # Update the DataTable cursor position to follow the moved entry + table = self.query_one("#entries-table", DataTable) + display_index = self.actual_index_to_display_index(self.selected_entry_index) + if table.row_count > 0 and display_index < table.row_count: + table.move_cursor(row=display_index) + self.update_entry_details() self.update_status(message) else: self.update_status(f"Error moving entry: {message}")