adding history feature to manual (duplicates current entry on missing pages)
This commit is contained in:
parent
21491514b3
commit
e9376ea26d
1 changed files with 37 additions and 2 deletions
|
@ -21,6 +21,8 @@
|
|||
|
||||
struct file *cur_file = 0;
|
||||
|
||||
char *name_backup = 0;
|
||||
|
||||
uint32_t *line_offsets = 0;
|
||||
uint32_t n_lines;
|
||||
|
||||
|
@ -122,6 +124,10 @@ void load_file(const char *name) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (name_backup)
|
||||
free_block(name_backup);
|
||||
name_backup = strdup(name);
|
||||
|
||||
if (cur_file)
|
||||
close_file(cur_file);
|
||||
cur_file = new_file;
|
||||
|
@ -182,6 +188,32 @@ void load_file(const char *name) {
|
|||
scroll_to(0);
|
||||
}
|
||||
|
||||
struct stack_entry {
|
||||
struct stack_entry *down;
|
||||
char *name;
|
||||
uint32_t line;
|
||||
};
|
||||
|
||||
struct stack_entry *stack_top = 0;
|
||||
|
||||
void push() {
|
||||
struct stack_entry *new_entry = get_block(sizeof(struct stack_entry));
|
||||
new_entry->down = stack_top;
|
||||
new_entry->name = strdup(name_backup);
|
||||
new_entry->line = line_on;
|
||||
stack_top = new_entry;
|
||||
}
|
||||
|
||||
void pop() {
|
||||
if (stack_top) {
|
||||
load_file(stack_top->name);
|
||||
scroll_to(stack_top->line);
|
||||
free_block(stack_top->name);
|
||||
free_block(stack_top);
|
||||
stack_top = stack_top->down;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
_set_color(UI_COLOR);
|
||||
_print_at(24, 79, " ");
|
||||
|
@ -255,11 +287,14 @@ void main() {
|
|||
case ' ':
|
||||
case '\n':
|
||||
case _KEY_NENTER:
|
||||
if (cur_link)
|
||||
if (cur_link) {
|
||||
push();
|
||||
load_file(cur_link->lto);
|
||||
}
|
||||
break;
|
||||
case _KEY_ESC:
|
||||
//TODO
|
||||
if (stack_top)
|
||||
pop();
|
||||
break;
|
||||
case 'q':
|
||||
return;
|
||||
|
|
Reference in a new issue