Fixed unit tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
|
||||
from fastcore.xml import FT
|
||||
from fasthtml.components import *
|
||||
|
||||
from components.BaseComponent import BaseComponentSingleton
|
||||
@@ -8,6 +9,7 @@ from components.undo_redo.assets.icons import icon_redo, icon_undo
|
||||
from components.undo_redo.commands import UndoRedoCommandManager
|
||||
from components.undo_redo.constants import UNDO_REDO_INSTANCE_ID, UndoRedoAttrs
|
||||
from components_helpers import mk_icon, mk_tooltip
|
||||
from core.settings_management import NoDefault
|
||||
|
||||
logger = logging.getLogger("UndoRedoApp")
|
||||
|
||||
@@ -64,13 +66,19 @@ class UndoRedo(BaseComponentSingleton):
|
||||
previous_state = self._settings_manager.load(self._session, None, digest=previous.digest)
|
||||
|
||||
# reapply the state
|
||||
current_state[current.key] = previous_state[current.key]
|
||||
if previous_state is not NoDefault:
|
||||
current_state[current.key] = previous_state[current.key]
|
||||
else:
|
||||
del current_state[current.key]
|
||||
self._settings_manager.save(self._session, current.entry, current_state)
|
||||
|
||||
self.index -= 1
|
||||
|
||||
if current.attrs.on_undo is not None:
|
||||
return self, current.attrs.on_undo()
|
||||
ret = current.attrs.on_undo()
|
||||
if isinstance(ret, FT) and 'id' in ret.attrs:
|
||||
ret.attrs["hx-swap-oob"] = "true"
|
||||
return self, ret
|
||||
else:
|
||||
return self
|
||||
|
||||
@@ -87,13 +95,19 @@ class UndoRedo(BaseComponentSingleton):
|
||||
next_state = self._settings_manager.load(self._session, None, digest=next_.digest)
|
||||
|
||||
# reapply the state
|
||||
current_state[current.key] = next_state[current.key]
|
||||
if current_state is not NoDefault:
|
||||
current_state[current.key] = next_state[current.key]
|
||||
else:
|
||||
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_undo is not None:
|
||||
return self, current.attrs.on_redo()
|
||||
if current.attrs.on_redo is not None:
|
||||
ret = current.attrs.on_undo()
|
||||
if isinstance(ret, FT) and 'id' in ret.attrs:
|
||||
ret.attrs["hx-swap-oob"] = "true"
|
||||
return self, ret
|
||||
else:
|
||||
return self
|
||||
|
||||
@@ -125,7 +139,7 @@ class UndoRedo(BaseComponentSingleton):
|
||||
|
||||
def _mk_redo(self):
|
||||
if self._can_redo():
|
||||
command = self.history[self.index]
|
||||
command = self.history[self.index + 1]
|
||||
return mk_tooltip(mk_icon(icon_redo,
|
||||
size=24,
|
||||
**self._commands.redo()),
|
||||
|
||||
Reference in New Issue
Block a user