Rework show_matching highlighter implementation

This commit is contained in:
Maxime Coste 2015-03-27 13:18:06 +00:00
parent 94bd32572d
commit c2150dd163

View File

@ -664,36 +664,38 @@ void show_matching_char(const Context& context, HighlightFlags flags, DisplayBuf
int level = 1; int level = 1;
if (c == pair.first) if (c == pair.first)
{ {
auto it = buffer.iterator_at(pos)+1; for (auto it = buffer.iterator_at(pos)+1,
auto end = buffer.iterator_at(range.second); end = buffer.iterator_at(range.second); it != end; ++it)
skip_while(it, end, [&](char c) { {
char c = *it;
if (c == pair.first) if (c == pair.first)
++level; ++level;
else if (c == pair.second and --level == 0) else if (c == pair.second and --level == 0)
return false; {
return true;
});
if (it != end)
highlight_range(display_buffer, it.coord(), (it+1).coord(), false, highlight_range(display_buffer, it.coord(), (it+1).coord(), false,
apply_face(face)); apply_face(face));
break; break;
} }
}
}
else if (c == pair.second and pos > range.first) else if (c == pair.second and pos > range.first)
{ {
auto it = buffer.iterator_at(pos)-1; for (auto it = buffer.iterator_at(pos)-1,
auto end = buffer.iterator_at(range.first); end = buffer.iterator_at(range.first); true; --it)
skip_while_reverse(it, end, [&](char c) { {
char c = *it;
if (c == pair.second) if (c == pair.second)
++level; ++level;
else if (c == pair.first and --level == 0) else if (c == pair.first and --level == 0)
return false; {
return true;
});
if (it != end or (*end == pair.first and level == 1))
highlight_range(display_buffer, it.coord(), (it+1).coord(), false, highlight_range(display_buffer, it.coord(), (it+1).coord(), false,
apply_face(face)); apply_face(face));
break; break;
} }
if (it == end)
break;
}
}
} }
} }
} }