Skip to content

Commit

Permalink
feat: make backspace key join current line with previous line
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Mar 7, 2024
1 parent ee1aaf0 commit 775c7fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/class_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def __repr__(self) -> str:


class Todos(list[Todo]):
"""Wrapper around list of Todo objects"""
def __init__(self, iterable: Iterable[Todo]) -> None:
super().__init__(iterable)

Expand Down
20 changes: 20 additions & 0 deletions todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,22 @@ def update_modified_time(prev_time: float, todos: Todos) -> tuple[Todos, float]:
return todos, current_time


def join_lines(todos: Todos, selected: Cursor) -> None:
"""Combine current line with previous line by concatenation."""
if len(selected) > 1:
return

prev_todo = int(selected) - 1
current_todo = int(selected)

todos[prev_todo].set_display_text(
f"{todos[prev_todo].display_text} {todos[current_todo].display_text}"
)
selected.slide_up()
todos.pop(current_todo)
update_file(FILENAME, todos)


def main(stdscr: Any) -> int:
"""
The main function for Ndo. Mainly provides keybindings
Expand Down Expand Up @@ -512,6 +528,9 @@ def main(stdscr: Any) -> int:
# make sure it also calls update_file()
keys: dict[int, tuple[Callable[..., Any], str]] = {
Key.ctrl_a: (selected.multiselect_all, "len(todos)"),
Key.backspace: (join_lines, "todos, selected"),
Key.backspace_: (join_lines, "todos, selected"),
Key.backspace__: (join_lines, "todos, selected"),
Key.tab: (handle_indent, "todos, selected"),
Key.enter: (handle_enter, "stdscr, todos, selected, single_line_mode"),
Key.ctrl_k: (single_line_state.toggle, "None"),
Expand Down Expand Up @@ -634,4 +653,5 @@ def main(stdscr: Any) -> int:
sys_exit()

from src.working_initscr import wrapper # pylint: disable=ungrouped-imports

wrapper(main)

0 comments on commit 775c7fd

Please sign in to comment.