diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-01-01 19:35:15 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-01-01 23:19:58 +0100 |
| commit | acd54f11b21ebcc3eadfbf7d4be14639fac82ca8 (patch) | |
| tree | e1f972e312108d4f08b7f723862b6c49d4b29d47 /editor.c | |
| parent | 819ca3927f6f156d12eeddae4ed84d04d28b7e1b (diff) | |
| download | vis-acd54f11b21ebcc3eadfbf7d4be14639fac82ca8.tar.gz vis-acd54f11b21ebcc3eadfbf7d4be14639fac82ca8.tar.xz | |
Add rudimentary support for jump list (CTRL+{O,I})
Diffstat (limited to 'editor.c')
| -rw-r--r-- | editor.c | 40 |
1 files changed, 39 insertions, 1 deletions
@@ -136,6 +136,42 @@ bool editor_window_split(EditorWin *original) { return true; } +void editor_window_jumplist_add(EditorWin *win, size_t pos) { + Mark mark = text_mark_set(win->text, pos); + if (mark) + ringbuf_add(win->jumplist, mark); +} + +size_t editor_window_jumplist_prev(EditorWin *win) { + size_t cur = window_cursor_get(win->win); + for (;;) { + Mark mark = ringbuf_prev(win->jumplist); + if (!mark) + return cur; + size_t pos = text_mark_get(win->text, mark); + if (pos != EPOS && pos != cur) + return pos; + } + return cur; +} + +size_t editor_window_jumplist_next(EditorWin *win) { + size_t cur = window_cursor_get(win->win); + for (;;) { + Mark mark = ringbuf_next(win->jumplist); + if (!mark) + return cur; + size_t pos = text_mark_get(win->text, mark); + if (pos != EPOS && pos != cur) + return pos; + } + return cur; +} + +void editor_window_jumplist_invalidate(EditorWin *win) { + ringbuf_invalidate(win->jumplist); +} + void editor_resize(Editor *ed, int width, int height) { ed->width = width; ed->height = height; @@ -281,6 +317,7 @@ static void editor_window_free(Editor *ed, EditorWin *win) { window_free(win->win); if (win->statuswin) delwin(win->statuswin); + ringbuf_free(win->jumplist); bool needed = false; for (EditorWin *w = ed ? ed->windows : NULL; w; w = w->next) { if (w->text == win->text) { @@ -301,7 +338,8 @@ static EditorWin *editor_window_new_text(Editor *ed, Text *text) { win->text = text; win->win = window_new(win->text); win->statuswin = newwin(1, ed->width, 0, 0); - if (!win->win || !win->statuswin) { + win->jumplist = ringbuf_alloc(31); + if (!win->win || !win->statuswin || !win->jumplist) { editor_window_free(ed, win); return NULL; } |
