diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2011-11-03 13:44:02 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2011-11-03 13:44:02 +0000 |
| commit | 9cf7cb682c6e472e8906d16a5c8e0488b86ca324 (patch) | |
| tree | 20aa92222aee975f3d832303e5026f3ff7277402 /src | |
| parent | 4982620c4c67a83276dd2b126002178b34f57c5c (diff) | |
Buffer: fix modified handling
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.cc | 12 | ||||
| -rw-r--r-- | src/buffer.hh | 2 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index d5ec4349..f0a396b6 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -22,7 +22,7 @@ Buffer::Buffer(const std::string& name, Type type, const BufferString& initial_content) : m_name(name), m_type(type), m_history(1), m_history_cursor(m_history.begin()), - m_content(initial_content), m_last_save_undo_group(m_history.begin()) + m_content(initial_content), m_last_save_undo_index(0) { BufferManager::instance().register_buffer(this); @@ -154,6 +154,10 @@ void Buffer::begin_undo_group() { assert(m_current_undo_group.empty()); m_history.erase(m_history_cursor, m_history.end()); + + if (m_history.size() < m_last_save_undo_index) + m_last_save_undo_index = -1; + m_history_cursor = m_history.end(); } @@ -245,13 +249,15 @@ void Buffer::delete_window(Window* window) bool Buffer::is_modified() const { - return m_last_save_undo_group != m_history_cursor + size_t history_cursor_index = m_history_cursor - m_history.begin(); + return m_last_save_undo_index != history_cursor_index or not m_current_undo_group.empty(); } void Buffer::notify_saved() { - m_last_save_undo_group = m_history_cursor; + size_t history_cursor_index = m_history_cursor - m_history.begin(); + m_last_save_undo_index = history_cursor_index; } void Buffer::register_modification_listener(BufferModificationListener* listener) const diff --git a/src/buffer.hh b/src/buffer.hh index 31abd55e..1d4455bc 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -184,7 +184,7 @@ private: std::list<std::unique_ptr<Window>> m_windows; - std::vector<UndoGroup>::iterator m_last_save_undo_group; + size_t m_last_save_undo_index; mutable std::vector<BufferModificationListener*> m_modification_listeners; }; |
