From fb414a7a85c6b8843d18030f07db0b8c80cc0251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 4 Nov 2016 12:21:54 +0100 Subject: sam: y should also loop over empty trailing matches The following x/example/ y/e/ i/-/ should produce `-e-xample-` where before it would wrongly result in `-e-xample`. --- sam.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sam.c b/sam.c index 669fdf9..e238825 100644 --- a/sam.c +++ b/sam.c @@ -895,9 +895,11 @@ static bool cmd_extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu Text *txt = win->file->text; if (cmd->regex) { + bool trailing_match = false; size_t start = range->start, end = range->end, last_start = EPOS; RegexMatch match[1]; - while (start < end) { + while (start < end || trailing_match) { + trailing_match = false; bool found = text_search_range_forward(txt, start, end - start, cmd->regex, 1, match, start > range->start ? REG_NOTBOL : 0) == 0; @@ -921,6 +923,8 @@ static bool cmd_extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu break; } start = match[0].end; + if (start == end) + trailing_match = true; } else { if (argv[0][0] == 'y') r = text_range_new(start, end); -- cgit v1.2.3