Save current cursor position from table Args: table: DataTable widget display_columns: Current list of display column names Returns: Saved cursor state or None if no position
(self, table, display_columns: List[str])
| 31 | self._column_history: List[str] = [] |
| 32 | |
| 33 | def save_position(self, table, display_columns: List[str]) -> Optional[CursorState]: |
| 34 | """ |
| 35 | Save current cursor position from table |
| 36 | |
| 37 | Args: |
| 38 | table: DataTable widget |
| 39 | display_columns: Current list of display column names |
| 40 | |
| 41 | Returns: |
| 42 | Saved cursor state or None if no position |
| 43 | """ |
| 44 | try: |
| 45 | if not table or not table.cursor_coordinate: |
| 46 | return None |
| 47 | |
| 48 | cursor_coord = table.cursor_coordinate |
| 49 | state = CursorState( |
| 50 | row=cursor_coord.row, |
| 51 | column=cursor_coord.column |
| 52 | ) |
| 53 | |
| 54 | # Try to save column name for better restoration |
| 55 | if display_columns and cursor_coord.column < len(display_columns): |
| 56 | state.column_name = display_columns[cursor_coord.column] |
| 57 | |
| 58 | # Try to save cell value for finding similar row |
| 59 | try: |
| 60 | if cursor_coord.row < table.row_count: |
| 61 | # This is tricky as we'd need the actual data |
| 62 | # For now, just save position |
| 63 | pass |
| 64 | except: |
| 65 | pass |
| 66 | |
| 67 | self._saved_state = state |
| 68 | |
| 69 | if self.logger: |
| 70 | self.logger.debug(f"Saved cursor state: {state}") |
| 71 | |
| 72 | return state |
| 73 | |
| 74 | except Exception as e: |
| 75 | if self.logger: |
| 76 | self.logger.error(f"Failed to save cursor position: {e}") |
| 77 | return None |
| 78 | |
| 79 | def restore_position(self, table, display_columns: List[str], |
| 80 | prefer_state: Optional[CursorState] = None) -> bool: |
nothing calls this directly
no test coverage detected