diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2011-12-02 14:28:27 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2011-12-02 14:28:27 +0000 |
| commit | 94d59cc4dd19a0e45b537ac854bf3fdaa6824679 (patch) | |
| tree | 3462c3214123f9fc959700e668a34443bdee245a /src/buffer.cc | |
| parent | 8e06e168d9c699c102bc0ea729a0814411e47660 (diff) | |
Buffer: add filter support
filters are functions called prior to applying a modification
to a buffer. They can manipulate the modification to change
the editor behaviour.
Diffstat (limited to 'src/buffer.cc')
| -rw-r--r-- | src/buffer.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index 0587cf45..2d2e106c 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -227,6 +227,9 @@ void Buffer::apply_modification(const BufferModification& modification) void Buffer::append_modification(BufferModification&& modification) { + for (auto filter : m_filters) + filter.second(*this, modification); + apply_modification(modification); m_current_undo_group.push_back(std::move(modification)); } @@ -277,4 +280,22 @@ void Buffer::unregister_modification_listener(BufferModificationListener* listen m_modification_listeners.erase(it); } +void Buffer::add_filter(FilterAndId&& filter) +{ + if (m_filters.contains(filter.first)) + throw filter_id_not_unique(filter.first); + m_filters.append(filter); +} + +void Buffer::remove_filter(const std::string& id) +{ + m_filters.remove(id); +} + +CandidateList Buffer::complete_filterid(const std::string& prefix, + size_t cursor_pos) +{ + return m_filters.complete_id<str_to_str>(prefix, cursor_pos); +} + } |
