Fix some other uses of invalid buffer coordinates in display code
This commit is contained in:
parent
fa4b88c2f8
commit
4ed790632d
|
@ -10,6 +10,14 @@
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
StringView DisplayAtom::content() const
|
StringView DisplayAtom::content() const
|
||||||
{
|
{
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
|
@ -36,7 +44,8 @@ ColumnCount DisplayAtom::length() const
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
{
|
{
|
||||||
case Range:
|
case Range:
|
||||||
return column_length(*m_buffer, m_range.begin, m_range.end);
|
return utf8::column_distance(get_iterator(*m_buffer, m_range.begin),
|
||||||
|
get_iterator(*m_buffer, m_range.end));
|
||||||
case Text:
|
case Text:
|
||||||
case ReplacedRange:
|
case ReplacedRange:
|
||||||
return m_text.column_length();
|
return m_text.column_length();
|
||||||
|
@ -48,8 +57,8 @@ ColumnCount DisplayAtom::length() const
|
||||||
void DisplayAtom::trim_begin(ColumnCount count)
|
void DisplayAtom::trim_begin(ColumnCount count)
|
||||||
{
|
{
|
||||||
if (m_type == Range)
|
if (m_type == Range)
|
||||||
m_range.begin = utf8::advance(m_buffer->iterator_at(m_range.begin),
|
m_range.begin = utf8::advance(get_iterator(*m_buffer, m_range.begin),
|
||||||
m_buffer->iterator_at(m_range.end),
|
get_iterator(*m_buffer, m_range.end),
|
||||||
count).coord();
|
count).coord();
|
||||||
else
|
else
|
||||||
m_text = m_text.substr(count).str();
|
m_text = m_text.substr(count).str();
|
||||||
|
@ -58,8 +67,8 @@ void DisplayAtom::trim_begin(ColumnCount count)
|
||||||
void DisplayAtom::trim_end(ColumnCount count)
|
void DisplayAtom::trim_end(ColumnCount count)
|
||||||
{
|
{
|
||||||
if (m_type == Range)
|
if (m_type == Range)
|
||||||
m_range.end = utf8::advance(m_buffer->iterator_at(m_range.end),
|
m_range.end = utf8::advance(get_iterator(*m_buffer, m_range.end),
|
||||||
m_buffer->iterator_at(m_range.begin),
|
get_iterator(*m_buffer, m_range.begin),
|
||||||
-count).coord();
|
-count).coord();
|
||||||
else
|
else
|
||||||
m_text = m_text.substr(0, m_text.column_length() - count).str();
|
m_text = m_text.substr(0, m_text.column_length() - count).str();
|
||||||
|
|
|
@ -25,6 +25,10 @@ size_t hash_value(const BufferRange& range)
|
||||||
return hash_values(range.begin, range.end);
|
return hash_values(range.begin, range.end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BufferIterator;
|
||||||
|
// Return a buffer iterator to the coord, tolerating one past end of line coords
|
||||||
|
BufferIterator get_iterator(const Buffer& buffer, BufferCoord coord);
|
||||||
|
|
||||||
struct DisplayAtom : public UseMemoryDomain<MemoryDomain::Display>
|
struct DisplayAtom : public UseMemoryDomain<MemoryDomain::Display>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -25,15 +25,6 @@
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user