Buffer: iterator_at prevents getting iterators on end of line

This commit is contained in:
Maxime Coste 2011-10-19 14:25:13 +00:00
parent 7e2f7f6715
commit d7f934b7ca

View File

@ -58,7 +58,8 @@ BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column) const
return begin(); return begin();
BufferPos line = Kakoune::clamp<int>(0, m_lines.size() - 1, line_and_column.line); BufferPos line = Kakoune::clamp<int>(0, m_lines.size() - 1, line_and_column.line);
BufferPos column = Kakoune::clamp<int>(0, line_length(line), line_and_column.column); int col_max = std::max(0, line_length(line) - 1);
BufferPos column = Kakoune::clamp<int>(0, col_max, line_and_column.column);
return BufferIterator(*this, m_lines[line] + column); return BufferIterator(*this, m_lines[line] + column);
} }