From 886a5ed603df862a26f0d6d78d6c8dd161623738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 23 Jan 2020 14:01:41 +0100 Subject: text: fix spurious regex anchor matches The regex anchors ^ and $ must not match at the start/end of the search range unless it is preceded/succeeded by a new line. This is implemented at the text-motion layer by passing the appropriate REG_NOT{B,E}OL flags to the search backend, meaning the caller can influence the anchor behavior depending on the context. This is important as for example in the command language the anchors apply to existing selections, not line boundaries. --- text-regex.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'text-regex.c') diff --git a/text-regex.c b/text-regex.c index b0549b6..56ecafc 100644 --- a/text-regex.c +++ b/text-regex.c @@ -101,6 +101,10 @@ int text_search_range_backward(Text *txt, size_t pos, size_t len, Regex *r, size } junk = next - cur; cur = next; + if (cur[-1] == '\n') + eflags &= ~REG_NOTBOL; + else + eflags |= REG_NOTBOL; } free(buf); return ret; -- cgit v1.2.3