Compare commits

...

2 commits

Author SHA1 Message Date
4ed4aa17d2 Position cursor correctly when returning 2025-03-09 11:07:03 +01:00
ba24b8b5b7 Add history stack 2025-03-09 10:58:01 +01:00

View file

@ -33,6 +33,9 @@ class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
# Directory history stack
self.directory_history: list[str] = []
# For overlay text timeout
self.overlay_hide_time = 0.0
self.last_position_save = 0.0
@ -148,6 +151,8 @@ class MainWindow(Gtk.ApplicationWindow):
file_item = cast(FileItem, selected_item)
if file_item.file_type == FileType.DIRECTORY:
# Save current directory before changing
self.directory_history.append(os.getcwd())
os.chdir(file_item.full_path)
self._populate_file_list()
return
@ -369,6 +374,23 @@ class MainWindow(Gtk.ApplicationWindow):
self._toggle_watched_status()
return True
elif keyval == Gdk.keyval_from_name("BackSpace"):
if self.directory_history:
prev_dir = self.directory_history.pop()
current_dir_name = Path(os.getcwd()).name
os.chdir(prev_dir)
self._populate_file_list()
# Find and select the directory we came from
for i in range(self.list_store.get_n_items()):
item = self.list_store.get_item(i)
if item and cast(FileItem, item).name == current_dir_name:
self.list_view.scroll_to(
i, Gtk.ListScrollFlags.SELECT | Gtk.ListScrollFlags.FOCUS, None
)
break
return True
return False
def _on_key_pressed(