You do not need to remember the index of each jump key because you can count it up after a key is pressed.
Showing the changes to scripts (3 of 3 files). Show all
Unified · Split
| @@ -275,7 +275,6 @@ struct jump_key { · 274 unmodified lines | ||
| 275 | 275 | struct list_head entries; |
| 276 | 276 | size_t offset; |
| 277 | 277 | struct menu *target; |
| 278 | − int index; | |
| 279 | 278 | }; |
| 280 | 279 | |
| 281 | 280 | extern struct file *file_list; |
| @@ -22,8 +22,6 @@ · 21 unmodified lines | ||
| 22 | 22 | #include "lkc.h" |
| 23 | 23 | #include "lxdialog/dialog.h" |
| 24 | 24 | |
| 25 | −#define JUMP_NB 9 | |
| 26 | − | |
| 27 | 25 | static const char mconf_readme[] = |
| 28 | 26 | "Overview\n" |
| 29 | 27 | "--------\n" |
| @@ -402,18 +400,21 @@ static int handle_search_keys(int key, size_t start, size_t end, void *_data) · 372 unmodified lines | ||
| 402 | 400 | { |
| 403 | 401 | struct search_data *data = _data; |
| 404 | 402 | struct jump_key *pos; |
| 403 | + int index = 0; | |
| 405 | 404 | |
| 406 | 405 | if (key < '1' || key > '9') |
| 407 | 406 | return 0; |
| 408 | 407 | |
| 409 | 408 | list_for_each_entry(pos, data->head, entries) { |
| 409 | + index = next_jump_key(index); | |
| 410 | + | |
| 410 | 411 | if (pos->offset < start) |
| 411 | 412 | continue; |
| 412 | 413 | |
| 413 | 414 | if (pos->offset >= end) |
| 414 | 415 | break; |
| 415 | 416 | |
| 416 | − if (key == '1' + (pos->index % JUMP_NB)) { | |
| 417 | + if (key == index) { | |
| 417 | 418 | data->target = pos->target; |
| 418 | 419 | return 1; |
| 419 | 420 | } |
| @@ -735,15 +735,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop, · 734 unmodified lines | ||
| 735 | 735 | } |
| 736 | 736 | if (head && location) { |
| 737 | 737 | jump = xmalloc(sizeof(struct jump_key)); |
| 738 | − | |
| 739 | 738 | jump->target = location; |
| 740 | − | |
| 741 | − if (list_empty(head)) | |
| 742 | − jump->index = 0; | |
| 743 | − else | |
| 744 | − jump->index = list_entry(head->prev, struct jump_key, | |
| 745 | − entries)->index + 1; | |
| 746 | − | |
| 747 | 739 | list_add_tail(&jump->entries, head); |
| 748 | 740 | } |
| 749 | 741 | |