Buffer: add a timestamp

This commit is contained in:
Maxime Coste 2012-08-15 17:07:53 +02:00
parent 14475e91cb
commit 5393e9e78b
2 changed files with 6 additions and 0 deletions

View File

@ -26,6 +26,7 @@ Buffer::Buffer(String name, Type type,
: m_name(std::move(name)), m_type(type),
m_history(1), m_history_cursor(m_history.begin()),
m_last_save_undo_index(0),
m_timestamp(0),
m_hook_manager(GlobalHookManager::instance()),
m_option_manager(GlobalOptionManager::instance())
{
@ -233,6 +234,7 @@ void Buffer::check_invariant() const
void Buffer::do_insert(const BufferIterator& pos, const String& content)
{
++m_timestamp;
BufferSize offset = pos.offset();
// all following lines advanced by length
@ -307,6 +309,7 @@ void Buffer::do_insert(const BufferIterator& pos, const String& content)
void Buffer::do_erase(const BufferIterator& pos, BufferSize length)
{
++m_timestamp;
BufferIterator end = pos + length;
assert(end.is_valid());
String prefix = m_lines[pos.line()].content.substr(0, pos.column());

View File

@ -114,6 +114,8 @@ public:
void insert(BufferIterator pos, const String& content);
void erase(BufferIterator begin, BufferIterator end);
size_t timestamp() const { return m_timestamp; }
void begin_undo_group();
void end_undo_group();
bool undo();
@ -201,6 +203,7 @@ private:
std::list<std::unique_ptr<Window>> m_windows;
size_t m_last_save_undo_index;
size_t m_timestamp;
std::vector<BufferChangeListener*> m_change_listeners;