diff options
| -rw-r--r-- | src/context.cc | 34 | ||||
| -rw-r--r-- | src/context.hh | 45 |
2 files changed, 51 insertions, 28 deletions
diff --git a/src/context.cc b/src/context.cc index 46d9cd58..048da784 100644 --- a/src/context.cc +++ b/src/context.cc @@ -1,10 +1,8 @@ #include "context.hh" -#include "alias_registry.hh" #include "client.hh" -#include "face_registry.hh" +#include "scope.hh" #include "buffer_manager.hh" -#include "hook_manager.hh" #include "register_manager.hh" #include "window.hh" @@ -62,6 +60,12 @@ Scope& Context::scope(bool allow_local) const return GlobalScope::instance(); } +OptionManager& Context::options() const { return scope().options(); } +HookManager& Context::hooks() const { return scope().hooks(); } +KeymapManager& Context::keymaps() const { return scope().keymaps(); } +AliasRegistry& Context::aliases() const { return scope().aliases(); } +FaceRegistry& Context::faces(bool allow_local) const { return scope(allow_local).faces(); } + void Context::set_client(Client& client) { kak_assert(not has_client()); @@ -82,6 +86,12 @@ void Context::print_status(DisplayLine status) const client().print_status(std::move(status)); } +void Context::push_jump(bool force) +{ + if (force or not (m_flags & Flags::Draft)) + m_jump_list.push(selections()); +} + void JumpList::push(SelectionList jump, Optional<size_t> index) { if (index) @@ -428,4 +438,22 @@ void Context::set_name(String name) { String old_name = std::exchange(m_name, std::move(name)); hooks().run_hook(Hook::ClientRenamed, format("{}:{}", old_name, m_name), *this); } + +ScopedEdition::ScopedEdition(Context& context) + : m_context{context}, + m_buffer{context.has_buffer() ? &context.buffer() : nullptr} +{ if (m_buffer) m_context.begin_edition(); } + +ScopedEdition::~ScopedEdition() { if (m_buffer) m_context.end_edition(); } + +ScopedSelectionEdition::ScopedSelectionEdition(Context& context) + : m_context{context}, + m_buffer{not (m_context.flags() & Context::Flags::Draft) and context.has_buffer() ? &context.buffer() : nullptr} +{ if (m_buffer) m_context.m_selection_history.begin_edition(); } + +ScopedSelectionEdition::ScopedSelectionEdition(ScopedSelectionEdition&& other) : m_context{other.m_context}, m_buffer{other.m_buffer} +{ other.m_buffer = nullptr; } + +ScopedSelectionEdition::~ScopedSelectionEdition() { if (m_buffer) m_context.m_selection_history.end_edition(); } + } diff --git a/src/context.hh b/src/context.hh index fb45fc2d..e1c0f657 100644 --- a/src/context.hh +++ b/src/context.hh @@ -4,20 +4,26 @@ #include "selection.hh" #include "optional.hh" #include "utils.hh" +#include "flags.hh" #include <functional> namespace Kakoune { +class Context; class Window; class Buffer; class Client; class Scope; class InputHandler; class DisplayLine; -class KeymapManager; + class AliasRegistry; +class FaceRegistry; +class OptionManager; +class KeymapManager; +class HookManager; enum Direction { Backward = -1, Forward = 1 }; @@ -104,11 +110,11 @@ public: Scope& scope(bool allow_local = true) const; Scope* local_scope() const { return m_local_scopes.empty() ? nullptr : m_local_scopes.back(); } - OptionManager& options() const { return scope().options(); } - HookManager& hooks() const { return scope().hooks(); } - KeymapManager& keymaps() const { return scope().keymaps(); } - AliasRegistry& aliases() const { return scope().aliases(); } - FaceRegistry& faces(bool allow_local = true) const { return scope(allow_local).faces(); } + OptionManager& options() const; + HookManager& hooks() const; + KeymapManager& keymaps() const; + AliasRegistry& aliases() const; + FaceRegistry& faces(bool allow_local = true) const; void print_status(DisplayLine status) const; @@ -132,11 +138,7 @@ public: Flags flags() const { return m_flags; } JumpList& jump_list() { return m_jump_list; } - void push_jump(bool force = false) - { - if (force or not (m_flags & Flags::Draft)) - m_jump_list.push(selections()); - } + void push_jump(bool force = false); template<typename Func> void set_last_select(Func&& last_select) { m_last_select = std::forward<Func>(last_select); } @@ -215,12 +217,9 @@ private: struct ScopedEdition { - ScopedEdition(Context& context) - : m_context{context}, - m_buffer{context.has_buffer() ? &context.buffer() : nullptr} - { if (m_buffer) m_context.begin_edition(); } - - ~ScopedEdition() { if (m_buffer) m_context.end_edition(); } + ScopedEdition(Context& context); + ~ScopedEdition(); + ScopedEdition(const ScopedEdition&) = delete; Context& context() const { return m_context; } private: @@ -230,14 +229,10 @@ private: struct ScopedSelectionEdition { - ScopedSelectionEdition(Context& context) - : m_context{context}, - m_buffer{not (m_context.flags() & Context::Flags::Draft) and context.has_buffer() ? &context.buffer() : nullptr} - { if (m_buffer) m_context.m_selection_history.begin_edition(); } - ScopedSelectionEdition(ScopedSelectionEdition&& other) : m_context{other.m_context}, m_buffer{other.m_buffer} - { other.m_buffer = nullptr; } - - ~ScopedSelectionEdition() { if (m_buffer) m_context.m_selection_history.end_edition(); } + ScopedSelectionEdition(Context& context); + ScopedSelectionEdition(ScopedSelectionEdition&& other); + ~ScopedSelectionEdition(); + private: Context& m_context; SafePtr<Buffer> m_buffer; |
