From ea95632709a6ae3df76772e83e1497a9fcfee52d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 15 Dec 2013 20:37:07 +0000 Subject: [PATCH] Move Editor::selections_content to Context --- src/context.cc | 8 ++++++++ src/context.hh | 1 + src/editor.cc | 8 -------- src/editor.hh | 1 - src/main.cc | 4 ++-- src/normal.cc | 14 ++++++-------- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/context.cc b/src/context.cc index 6e94b174..163beb16 100644 --- a/src/context.cc +++ b/src/context.cc @@ -187,6 +187,14 @@ const SelectionList& Context::selections() const return editor().selections(); } +std::vector Context::selections_content() const +{ + std::vector contents; + for (auto& sel : selections()) + contents.push_back(buffer().string(sel.min(), buffer().char_next(sel.max()))); + return contents; +} + void Context::begin_edition() { ++m_edition_level; diff --git a/src/context.hh b/src/context.hh index 58e7380c..fd82b8f9 100644 --- a/src/context.hh +++ b/src/context.hh @@ -51,6 +51,7 @@ public: SelectionList& selections(); const SelectionList& selections() const; + std::vector selections_content() const; void change_editor(Editor& editor); diff --git a/src/editor.cc b/src/editor.cc index 13b4511f..8f6bbcf5 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -16,12 +16,4 @@ Editor::Editor(Buffer& buffer) m_selections(buffer, {BufferCoord{}}) {} -std::vector Editor::selections_content() const -{ - std::vector contents; - for (auto& sel : m_selections) - contents.push_back(m_buffer->string(sel.min(), m_buffer->char_next(sel.max()))); - return contents; -} - } diff --git a/src/editor.hh b/src/editor.hh index c425da84..0e068f90 100644 --- a/src/editor.hh +++ b/src/editor.hh @@ -28,7 +28,6 @@ public: const SelectionList& selections() const { return m_selections; } SelectionList& selections() { return m_selections; } - std::vector selections_content() const; private: safe_ptr m_buffer; diff --git a/src/main.cc b/src/main.cc index af5ffbf3..3cf6b926 100644 --- a/src/main.cc +++ b/src/main.cc @@ -74,7 +74,7 @@ void register_env_vars() }, { "selections", [](const String& name, const Context& context) - { auto sels = context.editor().selections_content(); + { auto sels = context.selections_content(); String res; for (size_t i = 0; i < sels.size(); ++i) { @@ -144,7 +144,7 @@ void register_registers() struct DynRegDesc { char name; StringList (*func)(const Context&); }; static const DynRegDesc dyn_regs[] = { { '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } }, - { '.', [](const Context& context) { return context.editor().selections_content(); } }, + { '.', [](const Context& context) { return context.selections_content(); } }, { '#', [](const Context& context) { return StringList{{to_string((int)context.selections().size())}}; } }, }; diff --git a/src/normal.cc b/src/normal.cc index 52ca9694..6bdab3c1 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -393,8 +393,7 @@ template void for_each_char(Context& context, int) { ScopedEdition edition(context); - Editor& editor = context.editor(); - std::vector sels = editor.selections_content(); + std::vector sels = context.selections_content(); for (auto& sel : sels) { for (auto& c : sel) @@ -572,14 +571,14 @@ void use_selection_as_search_pattern(Context& context, int) void yank(Context& context, int) { - RegisterManager::instance()['"'] = context.editor().selections_content(); + RegisterManager::instance()['"'] = context.selections_content(); context.print_status({ "yanked " + to_string(context.selections().size()) + " selections", get_color("Information") }); } void cat_yank(Context& context, int) { - auto sels = context.editor().selections_content(); + auto sels = context.selections_content(); String str; for (auto& sel : sels) str += sel; @@ -590,14 +589,14 @@ void cat_yank(Context& context, int) void erase_selections(Context& context, int) { - RegisterManager::instance()['"'] = context.editor().selections_content(); + RegisterManager::instance()['"'] = context.selections_content(); ScopedEdition edition(context); erase(context.buffer(), context.selections()); } void change(Context& context, int param) { - RegisterManager::instance()['"'] = context.editor().selections_content(); + RegisterManager::instance()['"'] = context.selections_content(); enter_insert_mode(context, param); } @@ -902,8 +901,7 @@ void rotate_selections_content(Context& context, int count) { if (count == 0) count = 1; - Editor& editor = context.editor(); - auto strings = editor.selections_content(); + auto strings = context.selections_content(); count = count % strings.size(); std::rotate(strings.begin(), strings.end()-count, strings.end()); context.selections().rotate_main(count);