From da13b5f8143a3809bb938c020b957e1c5ff8dae7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 15 Oct 2018 21:20:00 +1100 Subject: [PATCH] Fix handling of capture matching in region highlighter Also extend the highlight/regions test to validate that. Thanks to lenormf for reviewing my change and finding this bug. --- src/highlighters.cc | 2 +- test/highlight/regions/in | 2 +- test/highlight/regions/rc | 1 + test/highlight/regions/ui-out | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 8ae36b799..2a67375c1 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1660,7 +1660,7 @@ void append_matches(const Buffer& buffer, LineCount line, RegexMatchList& matche { auto& m = *it; const bool with_capture = capture and m[1].matched and - m[0].second - m[0].first > std::numeric_limits::max(); + m[0].second - m[0].first < std::numeric_limits::max(); matches.push_back({ line, (int)(m[0].first - l.begin()), diff --git a/test/highlight/regions/in b/test/highlight/regions/in index 8b76db011..95ddb75b0 100644 --- a/test/highlight/regions/in +++ b/test/highlight/regions/in @@ -1 +1 @@ -"abcdefgh" hehe ${ youhou{hihi} } +"abcdefgh" hehe ${ youhou{hihi} } hehe diff --git a/test/highlight/regions/rc b/test/highlight/regions/rc index dccc2a89a..b92dfb372 100644 --- a/test/highlight/regions/rc +++ b/test/highlight/regions/rc @@ -2,3 +2,4 @@ add-highlighter window/regions_test regions add-highlighter window/regions_test/code default-region fill yellow add-highlighter window/regions_test/string region %{"} %{(?' '' fill blue diff --git a/test/highlight/regions/ui-out b/test/highlight/regions/ui-out index dfbf32059..48e7b3e9e 100644 --- a/test/highlight/regions/ui-out +++ b/test/highlight/regions/ui-out @@ -1,5 +1,5 @@ { "jsonrpc": "2.0", "method": "set_ui_options", "params": [{}] } -{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "attributes": [] }, "contents": "\"" }, { "face": { "fg": "green", "bg": "default", "attributes": [] }, "contents": "abcdefgh\"" }, { "face": { "fg": "yellow", "bg": "default", "attributes": [] }, "contents": " hehe " }, { "face": { "fg": "red", "bg": "default", "attributes": [] }, "contents": "${ youhou{hihi} }" }, { "face": { "fg": "yellow", "bg": "default", "attributes": [] }, "contents": "\u000a" }]], { "fg": "default", "bg": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "attributes": [] }] } +{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "attributes": [] }, "contents": "\"" }, { "face": { "fg": "green", "bg": "default", "attributes": [] }, "contents": "abcdefgh\"" }, { "face": { "fg": "yellow", "bg": "default", "attributes": [] }, "contents": " hehe " }, { "face": { "fg": "red", "bg": "default", "attributes": [] }, "contents": "${ youhou{hihi} }" }, { "face": { "fg": "yellow", "bg": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "attributes": [] }, "contents": "" }, { "face": { "fg": "yellow", "bg": "default", "attributes": [] }, "contents": " hehe\u000a" }]], { "fg": "default", "bg": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "attributes": [] }] } { "jsonrpc": "2.0", "method": "menu_hide", "params": [] } { "jsonrpc": "2.0", "method": "info_hide", "params": [] } { "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "out 1:1 " }, { "face": { "fg": "black", "bg": "yellow", "attributes": [] }, "contents": "" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "attributes": [] }] }