Skip to content

Commit

Permalink
feat: fix shifts cursor placement with fix_highlight deco
Browse files Browse the repository at this point in the history
  • Loading branch information
kraanzu committed Sep 14, 2024
1 parent 5058182 commit cfed18e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
24 changes: 24 additions & 0 deletions dooit/ui/widgets/trees/_decoratos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import Callable, TYPE_CHECKING
from textual.widgets.option_list import OptionDoesNotExist

if TYPE_CHECKING:
from .model_tree import ModelTree
ModelTreeFunc = Callable[[ModelTree], None]


def fix_highlight(func: "ModelTreeFunc") -> "ModelTreeFunc":

def wrapper(self: "ModelTree") -> None:
highlighted_id = self.node.id
highlighted_index = self.highlighted

assert highlighted_id is not None
func(self)

try:
if self.get_option(highlighted_id):
self.highlighted = self.get_option_index(highlighted_id)
except OptionDoesNotExist:
self.highlighted = min(highlighted_index or -1, len(self._options) - 1)

return wrapper
5 changes: 4 additions & 1 deletion dooit/ui/widgets/trees/model_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dooit.ui.widgets.renderers.base_renderer import BaseRenderer
from .base_tree import BaseTree
from ._render_dict import RenderDict
from ._decoratos import fix_highlight

ModelType = TypeVar("ModelType", bound=Union[Todo, Workspace])
RenderDictType = TypeVar("RenderDictType", bound=RenderDict)
Expand Down Expand Up @@ -193,10 +194,12 @@ def add_sibling(self):
self.highlighted = self.get_option_index(node.uuid)
self.start_edit("description")

def shift_up(self):
@fix_highlight
def shift_up(self) -> None:
self.current_model.shift_up()
self.force_refresh()

@fix_highlight
def shift_down(self):
self.current_model.shift_down()
self.force_refresh()

0 comments on commit cfed18e

Please sign in to comment.