code cleanups in buffer
This commit is contained in:
parent
d1c4a655b9
commit
ccec35f88c
|
@ -69,7 +69,7 @@ BufferSize Buffer::line_length(BufferPos line) const
|
||||||
{
|
{
|
||||||
assert(line < line_count());
|
assert(line < line_count());
|
||||||
BufferPos end = (line < m_lines.size() - 1) ?
|
BufferPos end = (line < m_lines.size() - 1) ?
|
||||||
m_lines[line + 1].start : length();
|
m_lines[line + 1].start : character_count();
|
||||||
return end - m_lines[line].start;
|
return end - m_lines[line].start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ BufferIterator Buffer::end() const
|
||||||
return BufferIterator(*this, { (int)line_count()-1, (int)m_lines.back().length() });
|
return BufferIterator(*this, { (int)line_count()-1, (int)m_lines.back().length() });
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferSize Buffer::length() const
|
BufferSize Buffer::character_count() const
|
||||||
{
|
{
|
||||||
if (m_lines.empty())
|
if (m_lines.empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -123,11 +123,13 @@ public:
|
||||||
Buffer& operator= (const Buffer&) = delete;
|
Buffer& operator= (const Buffer&) = delete;
|
||||||
~Buffer();
|
~Buffer();
|
||||||
|
|
||||||
void begin_undo_group();
|
Type type() const { return m_type; }
|
||||||
void end_undo_group();
|
|
||||||
|
|
||||||
|
// apply given modification to buffer.
|
||||||
void modify(Modification&& modification);
|
void modify(Modification&& modification);
|
||||||
|
|
||||||
|
void begin_undo_group();
|
||||||
|
void end_undo_group();
|
||||||
bool undo();
|
bool undo();
|
||||||
bool redo();
|
bool redo();
|
||||||
|
|
||||||
|
@ -136,7 +138,7 @@ public:
|
||||||
|
|
||||||
BufferIterator begin() const;
|
BufferIterator begin() const;
|
||||||
BufferIterator end() const;
|
BufferIterator end() const;
|
||||||
BufferSize length() const;
|
BufferSize character_count() const;
|
||||||
BufferSize line_count() const;
|
BufferSize line_count() const;
|
||||||
|
|
||||||
BufferIterator iterator_at(const BufferCoord& line_and_column) const;
|
BufferIterator iterator_at(const BufferCoord& line_and_column) const;
|
||||||
|
@ -150,8 +152,11 @@ public:
|
||||||
Window* get_or_create_window();
|
Window* get_or_create_window();
|
||||||
void delete_window(Window* window);
|
void delete_window(Window* window);
|
||||||
|
|
||||||
|
// returns true if the buffer is in a different state than
|
||||||
|
// the last time it was saved
|
||||||
bool is_modified() const;
|
bool is_modified() const;
|
||||||
Type type() const { return m_type; }
|
|
||||||
|
// notify the buffer that it was saved in the current state
|
||||||
void notify_saved();
|
void notify_saved();
|
||||||
|
|
||||||
void add_iterator_to_update(BufferIterator& iterator);
|
void add_iterator_to_update(BufferIterator& iterator);
|
||||||
|
|
|
@ -133,7 +133,7 @@ inline BufferIterator BufferIterator::operator+(BufferSize size) const
|
||||||
assert(m_buffer);
|
assert(m_buffer);
|
||||||
if (size >= 0)
|
if (size >= 0)
|
||||||
{
|
{
|
||||||
BufferSize o = std::min(m_buffer->length(), offset() + size);
|
BufferSize o = std::min(m_buffer->character_count(), offset() + size);
|
||||||
for (int i = line() + 1; i < m_buffer->line_count(); ++i)
|
for (int i = line() + 1; i < m_buffer->line_count(); ++i)
|
||||||
{
|
{
|
||||||
if (m_buffer->m_lines[i].start > o)
|
if (m_buffer->m_lines[i].start > o)
|
||||||
|
@ -209,7 +209,7 @@ inline bool BufferIterator::is_begin() const
|
||||||
inline bool BufferIterator::is_end() const
|
inline bool BufferIterator::is_end() const
|
||||||
{
|
{
|
||||||
assert(m_buffer);
|
assert(m_buffer);
|
||||||
return offset() == m_buffer->length();
|
return offset() == m_buffer->character_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user