From 1e624838d3be69b48fa03a5e9b3cceb359e9abc8 Mon Sep 17 00:00:00 2001 From: mecaneer23 Date: Tue, 30 Apr 2024 10:22:22 -0500 Subject: [PATCH] refactor: remove unnecessary extra function (_handle_delete_todo) --- todo.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/todo.py b/todo.py index 9719c86..cb557a9 100755 --- a/todo.py +++ b/todo.py @@ -160,15 +160,21 @@ def new_todo_current(stdscr: curses.window, todos: Todos, selected: int) -> Todo return todos -def delete_todo(stdscr: curses.window, todos: Todos, selected: Cursor) -> TodoList: +def delete_todo( + stdscr: curses.window, + todos: Todos, + selected: Cursor, + copied_todo: Todo, +) -> Todos: """Remove each Todo in `selected` from the list""" - positions = selected.get_deletable() - for pos in positions: + if len(todos) > 0 and CLIPBOARD_EXISTS: + copy_todo(stdscr, todos, selected, copied_todo) + for pos in selected.get_deletable(): todos = remove_todo(todos, pos) selected.set_to(clamp(int(selected), 0, len(todos))) stdscr.clear() update_file(FILENAME, todos) - return TodoList(todos, int(selected)) + return todos def color_todo(stdscr: curses.window, todos: Todos, selected: Cursor) -> Todos: @@ -268,17 +274,6 @@ def _toggle_todo_note(todos: Todos, selected: Cursor) -> None: update_file(FILENAME, todos) -def _handle_delete_todo( - stdscr: curses.window, - todos: Todos, - selected: Cursor, - copied_todo: Todo, -) -> Todos: - if len(todos) > 0 and CLIPBOARD_EXISTS: - copy_todo(stdscr, todos, selected, copied_todo) - return selected.set_to_passthrough(delete_todo(stdscr, todos, selected)) - - def _handle_undo(selected: Cursor, history: UndoRedo) -> Todos: todos = selected.set_to_passthrough(history.undo()) update_file(FILENAME, todos) @@ -605,7 +600,7 @@ def main(stdscr: curses.window) -> int: Key.a: (_handle_alert, "stdscr, todos, int(selected)"), Key.b: (magnify_menu, "stdscr, todos, selected"), Key.c: (color_todo, "stdscr, todos, selected"), - Key.d: (_handle_delete_todo, "stdscr, todos, selected, copied_todo"), + Key.d: (delete_todo, "stdscr, todos, selected, copied_todo"), Key.g: (selected.to_top, "None"), Key.h: (help_menu, "stdscr"), Key.i: (_handle_edit, "stdscr, todos, selected, single_line_state"),