From 4df34b71bad925b8449ecb8da18e13529f0f3380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Tue, 14 Apr 2020 13:33:39 -0300 Subject: [PATCH 1/2] Introduce go_to_anchor --- src/search.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/search.c b/src/search.c index cd0d98b5..be42eec0 100644 --- a/src/search.c +++ b/src/search.c @@ -991,15 +991,21 @@ void put_or_lift_anchor(void) statusbar(_("Removed anchor")); } -/* Make the given line the current line, or report the anchoredness. */ -void go_to_and_confirm(linestruct *line) +/* Jump to the next or previous anchor, if any. */ +void go_to_anchor(bool forward) { - linestruct *was_current = openfile->current; + linestruct *line = openfile->current; + + do { + line = forward ? + ((line->next) ? line->next : openfile->filetop): + ((line->prev) ? line->prev : openfile->filebot); + } while (!line->has_anchor && line != openfile->current); if (line != openfile->current) { openfile->current = line; openfile->current_x = 0; - edit_redraw(was_current, CENTERING); + edit_redraw(openfile->current, CENTERING); statusbar(_("Jumped to anchor")); } else if (openfile->current->has_anchor) statusbar(_("This is the only anchor")); @@ -1010,22 +1016,12 @@ void go_to_and_confirm(linestruct *line) /* Jump to the first anchor before the current line; wrap around at the top. */ void to_prev_anchor(void) { - linestruct *line = openfile->current; - - do { line = (line->prev) ? line->prev : openfile->filebot; - } while (!line->has_anchor && line != openfile->current); - - go_to_and_confirm(line); + go_to_anchor(FALSE); } /* Jump to the first anchor after the current line; wrap around at the bottom. */ void to_next_anchor(void) { - linestruct *line = openfile->current; - - do { line = (line->next) ? line->next : openfile->filetop; - } while (!line->has_anchor && line != openfile->current); - - go_to_and_confirm(line); + go_to_anchor(TRUE); } #endif /* !NANO_TINY */ -- 2.17.1