From 560fa2bcaf2debdb5f12555efd5aa30c3b32467b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 9 Dec 2025 17:22:20 +0100 Subject: introduce search_common... ... and make search_{forward,backward} wrapper to that function. --- vis-motions.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/vis-motions.c b/vis-motions.c index 241bf37..5957c7b 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -45,20 +45,22 @@ static size_t search_word_backward(Vis *vis, Text *txt, size_t pos) { return pos; } -static size_t search_forward(Vis *vis, Text *txt, size_t pos) { +static size_t search_common(Vis *vis, Text *txt, size_t pos, bool backward) { Regex *regex = vis_regex(vis, NULL); if (regex) - pos = text_search_forward(txt, pos, regex); + pos = backward ? + text_search_backward(txt, pos, regex) : + text_search_forward(txt, pos, regex); text_regex_free(regex); return pos; } +static size_t search_forward(Vis *vis, Text *txt, size_t pos) { + return search_common(vis, txt, pos, false); +} + static size_t search_backward(Vis *vis, Text *txt, size_t pos) { - Regex *regex = vis_regex(vis, NULL); - if (regex) - pos = text_search_backward(txt, pos, regex); - text_regex_free(regex); - return pos; + return search_common(vis, txt, pos, true); } static size_t common_word_next(Vis *vis, Text *txt, size_t pos, -- cgit v1.2.3