The correct tab is shown on undo - redo

This commit is contained in:
2025-08-02 15:27:11 +02:00
parent 6949bb2814
commit c694f42c07
3 changed files with 27 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ logger = logging.getLogger("UndoRedoApp")
@dataclass
class CommandHistory:
attrs: UndoRedoAttrs
tab_key: str | None
digest: str | None # digest to remember
entry: str # digest to remember
key: str # key
@@ -35,11 +36,13 @@ class UndoRedo(BaseComponentSingleton):
def snapshot(self, undo_redo_attrs: UndoRedoAttrs, entry, key, path=None):
digest = self._settings_manager.get_digest(self._session, entry) # get the current digest (the last one)
active_tab_key = self.tabs_manager.get_active_tab_key()
# init the history if this is the first call
if len(self.history) == 0:
digest_history = self._settings_manager.history(self._session, entry, digest, 2)
command = CommandHistory(undo_redo_attrs,
active_tab_key,
digest_history[1] if len(digest_history) > 1 else None,
entry,
key,
@@ -47,7 +50,7 @@ class UndoRedo(BaseComponentSingleton):
self.history.append(command)
self.index = 0
command = CommandHistory(undo_redo_attrs, digest, entry, key, path)
command = CommandHistory(undo_redo_attrs, active_tab_key, digest, entry, key, path)
self.history = self.history[:self.index + 1] #
self.history.append(command)
@@ -76,7 +79,9 @@ class UndoRedo(BaseComponentSingleton):
if current.attrs.on_undo is not None:
ret = current.attrs.on_undo()
if isinstance(ret, FT) and 'id' in ret.attrs:
if current.attrs.update_tab and current.tab_key is not None and current.tab_key != self.tabs_manager.get_active_tab_key():
ret = self.tabs_manager.show_tab(current.tab_key)
elif isinstance(ret, FT) and 'id' in ret.attrs:
ret.attrs["hx-swap-oob"] = "true"
return self, ret
else:
@@ -98,14 +103,16 @@ class UndoRedo(BaseComponentSingleton):
if current_state is not NoDefault:
current_state[current.key] = next_state[current.key]
else:
current_state = {current.key : next_state[current.key]}
current_state = {current.key: next_state[current.key]}
self._settings_manager.save(self._session, current.entry, current_state)
self.index += 1
if current.attrs.on_redo is not None:
ret = current.attrs.on_undo()
if isinstance(ret, FT) and 'id' in ret.attrs:
if current.attrs.update_tab and current.tab_key is not None and current.tab_key != self.tabs_manager.get_active_tab_key():
ret = self.tabs_manager.show_tab(current.tab_key)
elif isinstance(ret, FT) and 'id' in ret.attrs:
ret.attrs["hx-swap-oob"] = "true"
return self, ret
else:

View File

@@ -15,6 +15,7 @@ class Routes:
class UndoRedoAttrs:
name: str
desc: str = None
update_tab: bool = True
on_undo: Callable = None
on_redo: Callable = None