Move tolerance for one past end of line coordinates to highlighter code
The rest of Kakoune's code now requires coord passed to Buffer::iterator_at to be valid.
This commit is contained in:
parent
01a1e92b79
commit
fa4b88c2f8
|
@ -166,10 +166,6 @@ void Buffer::update_display_name()
|
||||||
|
|
||||||
BufferIterator Buffer::iterator_at(BufferCoord coord) const
|
BufferIterator Buffer::iterator_at(BufferCoord coord) const
|
||||||
{
|
{
|
||||||
// Tolerate one past the end of line
|
|
||||||
if (not is_end(coord) and coord.column == m_lines[coord.line].length())
|
|
||||||
coord = coord.line+1;
|
|
||||||
|
|
||||||
kak_assert(is_valid(coord));
|
kak_assert(is_valid(coord));
|
||||||
return {*this, coord};
|
return {*this, coord};
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,15 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
|
BufferIterator get_iterator(const Buffer& buffer, BufferCoord coord)
|
||||||
|
{
|
||||||
|
// Correct one past the end of line as next line
|
||||||
|
if (not buffer.is_end(coord) and coord.column == buffer[coord.line].length())
|
||||||
|
coord = coord.line+1;
|
||||||
|
return buffer.iterator_at(coord);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
std::unique_ptr<Highlighter> make_highlighter(Func func, HighlightPass pass = HighlightPass::Colorize)
|
std::unique_ptr<Highlighter> make_highlighter(Func func, HighlightPass pass = HighlightPass::Colorize)
|
||||||
{
|
{
|
||||||
|
@ -364,8 +373,8 @@ private:
|
||||||
{
|
{
|
||||||
kak_assert(matches.size() % m_faces.size() == 0);
|
kak_assert(matches.size() % m_faces.size() == 0);
|
||||||
using RegexIt = RegexIterator<BufferIterator>;
|
using RegexIt = RegexIterator<BufferIterator>;
|
||||||
RegexIt re_it{buffer.iterator_at(range.begin),
|
RegexIt re_it{get_iterator(buffer, range.begin),
|
||||||
buffer.iterator_at(range.end), m_regex,
|
get_iterator(buffer, range.end), m_regex,
|
||||||
match_flags(is_bol(range.begin),
|
match_flags(is_bol(range.begin),
|
||||||
is_eol(buffer, range.end),
|
is_eol(buffer, range.end),
|
||||||
is_bow(buffer, range.begin),
|
is_bow(buffer, range.begin),
|
||||||
|
@ -871,8 +880,8 @@ struct TabulationHighlighter : Highlighter
|
||||||
if (atom_it->type() != DisplayAtom::Range)
|
if (atom_it->type() != DisplayAtom::Range)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto begin = buffer.iterator_at(atom_it->begin());
|
auto begin = get_iterator(buffer, atom_it->begin());
|
||||||
auto end = buffer.iterator_at(atom_it->end());
|
auto end = get_iterator(buffer, atom_it->end());
|
||||||
for (BufferIterator it = begin; it != end; ++it)
|
for (BufferIterator it = begin; it != end; ++it)
|
||||||
{
|
{
|
||||||
if (*it == '\t')
|
if (*it == '\t')
|
||||||
|
@ -926,8 +935,8 @@ void show_whitespaces(const Context& context, HighlightPass, DisplayBuffer& disp
|
||||||
if (atom_it->type() != DisplayAtom::Range)
|
if (atom_it->type() != DisplayAtom::Range)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto begin = buffer.iterator_at(atom_it->begin());
|
auto begin = get_iterator(buffer, atom_it->begin());
|
||||||
auto end = buffer.iterator_at(atom_it->end());
|
auto end = get_iterator(buffer, atom_it->end());
|
||||||
for (BufferIterator it = begin; it != end; )
|
for (BufferIterator it = begin; it != end; )
|
||||||
{
|
{
|
||||||
auto coord = it.coord();
|
auto coord = it.coord();
|
||||||
|
@ -1080,8 +1089,8 @@ void show_matching_char(const Context& context, HighlightPass, DisplayBuffer& di
|
||||||
int level = 1;
|
int level = 1;
|
||||||
if (c == pair.first)
|
if (c == pair.first)
|
||||||
{
|
{
|
||||||
for (auto it = buffer.iterator_at(pos)+1,
|
for (auto it = get_iterator(buffer, pos)+1,
|
||||||
end = buffer.iterator_at(range.end); it != end; ++it)
|
end = get_iterator(buffer, range.end); it != end; ++it)
|
||||||
{
|
{
|
||||||
char c = *it;
|
char c = *it;
|
||||||
if (c == pair.first)
|
if (c == pair.first)
|
||||||
|
@ -1096,8 +1105,8 @@ void show_matching_char(const Context& context, HighlightPass, DisplayBuffer& di
|
||||||
}
|
}
|
||||||
else if (c == pair.second and pos > range.begin)
|
else if (c == pair.second and pos > range.begin)
|
||||||
{
|
{
|
||||||
for (auto it = buffer.iterator_at(pos)-1,
|
for (auto it = get_iterator(buffer, pos)-1,
|
||||||
end = buffer.iterator_at(range.begin); true; --it)
|
end = get_iterator(buffer, range.begin); true; --it)
|
||||||
{
|
{
|
||||||
char c = *it;
|
char c = *it;
|
||||||
if (c == pair.second)
|
if (c == pair.second)
|
||||||
|
@ -1159,8 +1168,8 @@ void expand_unprintable(const Context& context, HighlightPass, DisplayBuffer& di
|
||||||
{
|
{
|
||||||
if (atom_it->type() == DisplayAtom::Range)
|
if (atom_it->type() == DisplayAtom::Range)
|
||||||
{
|
{
|
||||||
for (auto it = buffer.iterator_at(atom_it->begin()),
|
for (auto it = get_iterator(buffer, atom_it->begin()),
|
||||||
end = buffer.iterator_at(atom_it->end()); it < end;)
|
end = get_iterator(buffer, atom_it->end()); it < end;)
|
||||||
{
|
{
|
||||||
auto coord = it.coord();
|
auto coord = it.coord();
|
||||||
Codepoint cp = utf8::read_codepoint<utf8::InvalidPolicy::Pass>(it, end);
|
Codepoint cp = utf8::read_codepoint<utf8::InvalidPolicy::Pass>(it, end);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user