Fix invalid regions with begin > end being generated

Fixes #3495
This commit is contained in:
Maxime Coste 2020-05-28 20:58:46 +10:00
parent aad20f6576
commit 109abbeed4
4 changed files with 15 additions and 5 deletions

View File

@ -2131,16 +2131,16 @@ private:
auto end_it = matches.find_matching_end(buffer, beg_it->end_coord(), auto end_it = matches.find_matching_end(buffer, beg_it->end_coord(),
region.value->match_capture() ? beg_it->capture(buffer) : Optional<StringView>{}); region.value->match_capture() ? beg_it->capture(buffer) : Optional<StringView>{});
if (end_it == matches.end_matches.end() or end_it->end_coord() >= range.end) if (end_it == matches.end_matches.end() or end_it->end_coord() >= range.end) // region continue past range end
{ {
regions.push_back({ {beg_it->line, beg_it->begin}, auto begin_coord = beg_it->begin_coord();
range.end, if (begin_coord < range.end)
region.key }); regions.push_back({begin_coord, range.end, region.key});
break; break;
} }
auto end_coord = end_it->end_coord(); auto end_coord = end_it->end_coord();
regions.push_back({ beg_it->begin_coord(), end_coord, region.key }); regions.push_back({beg_it->begin_coord(), end_coord, region.key});
// With empty begin and end matches (for example if the regexes // With empty begin and end matches (for example if the regexes
// are /"\K/ and /(?=")/), that case can happen, and would // are /"\K/ and /(?=")/), that case can happen, and would

View File

@ -0,0 +1 @@
{}{<>}

View File

@ -0,0 +1,9 @@
add-highlighter global/rs regions
add-highlighter global/rs/r1 region \{ \} ref sub
add-highlighter shared/sub regions
add-highlighter shared/sub/r2 region < > group
add-highlighter shared/sub/r2/ regex X 0:red
declare-option range-specs replaced_part 1 1.2,1.4|Placeholder
add-highlighter global/ replace-ranges replaced_part