diff options
| author | hachem <im@hachem.wtf> | 2026-09-29 16:46:58 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-29 16:46:58 +0200 |
| commit | a90c210784ec9e3b4115b9f46c1fc3664340f0ae (patch) | |
| tree | 6960a61baee75385c9fb7d70427b6c8ddab7eb07 | |
| parent | e715956c729e30f34ab03ce9f2baee2d50cdbb44 (diff) | |
feat: add more keybindings
| -rw-r--r-- | todo.c | 91 |
1 files changed, 91 insertions, 0 deletions
@@ -164,6 +164,11 @@ static void delete_item(struct List* list, int index) list->count--; } +static int is_separator(const struct Item* item) +{ + return item->text[0] == '\0'; +} + static struct termios saved_termios; static void restore_terminal(void) @@ -366,6 +371,92 @@ static int normal_key(struct List* list, const char* path, int* cursor, enum Mod break; + case 'g': + { + char next; + + if (read(STDIN_FILENO, &next, 1) == 1 && next == 'g') + *cursor = 0; + + break; + } + + case 'G': + *cursor = list->count - 1; + break; + + case '}': + { + int next = *cursor + 1; + + while (next < list->count && !is_separator(&list->items[next])) + next++; + + *cursor = next < list->count ? next : list->count - 1; + break; + } + + case '{': + { + int previous = *cursor - 1; + + while (previous >= 0 && !is_separator(&list->items[previous])) + previous--; + + *cursor = previous >= 0 ? previous : 0; + break; + } + + case 'd': + { + char next; + + if (read(STDIN_FILENO, &next, 1) == 1 && next == 'd') + { + delete_item(list, *cursor); + save(list, path); + } + + break; + } + + case 'J': + if (*cursor >= 0 && *cursor + 1 < list->count) + { + struct Item moved = list->items[*cursor]; + list->items[*cursor] = list->items[*cursor + 1]; + list->items[*cursor + 1] = moved; + (*cursor)++; + save(list, path); + } + + break; + + case 'K': + if (*cursor > 0 && *cursor < list->count) + { + struct Item moved = list->items[*cursor]; + list->items[*cursor] = list->items[*cursor - 1]; + list->items[*cursor - 1] = moved; + (*cursor)--; + save(list, path); + } + + break; + + case 'D': + { + int kept = 0; + + for (int i = 0; i < list->count; i++) + if (list->items[i].state != STATE_DONE) + list->items[kept++] = list->items[i]; + + list->count = kept; + save(list, path); + break; + } + default: break; } |
