Update DataTable cursor position handling when moving entries
This commit is contained in:
		
							parent
							
								
									82bfed7ce4
								
							
						
					
					
						commit
						8c1cd2047e
					
				
					 1 changed files with 12 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -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}")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue