From a981d41cdefe113876780e4da9718a33a8080393 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 15 Mar 2013 18:20:35 +0100 Subject: [PATCH] Editor: replace selections().back() with main_selection() --- src/client_manager.cc | 2 +- src/commands.cc | 2 +- src/editor.cc | 2 +- src/editor.hh | 3 ++- src/input_handler.cc | 2 +- src/main.cc | 8 ++++---- src/unit_tests.cc | 2 +- src/window.cc | 6 +++--- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/client_manager.cc b/src/client_manager.cc index 519cd00a..a864ef93 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -190,7 +190,7 @@ Context& ClientManager::get_client_context(const String& name) static String generate_status_line(const Context& context) { - BufferCoord cursor = context.editor().selections().back().last().coord(); + BufferCoord cursor = context.editor().main_selection().last().coord(); std::ostringstream oss; oss << context.buffer().name() << " " << (int)cursor.line+1 << "," << (int)cursor.column+1; diff --git a/src/commands.cc b/src/commands.cc index 5f1c1cf3..b56de71e 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -662,7 +662,7 @@ void info(const CommandParameters& params, Context& context) if (parser.has_option("anchor")) { style = MenuStyle::Inline; - const auto& sel = context.editor().selections().back(); + const auto& sel = context.editor().main_selection(); auto it = sel.last(); String anchor = parser.option_value("anchor"); if (anchor == "left") diff --git a/src/editor.cc b/src/editor.cc index 0f8e3a2c..b08a00ea 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -261,7 +261,7 @@ void Editor::select(const Selector& selector, SelectMode mode) res.captures() = sel.captures(); m_selections.push_back(res); } - else if (mode == SelectMode::ReplaceLast) + else if (mode == SelectMode::ReplaceMain) { auto& sel = m_selections.back(); auto res = selector(sel); diff --git a/src/editor.hh b/src/editor.hh index 8df5f55a..a1f27265 100644 --- a/src/editor.hh +++ b/src/editor.hh @@ -18,7 +18,7 @@ enum class SelectMode Replace, Extend, Append, - ReplaceLast, + ReplaceMain, }; enum class InsertMode : unsigned @@ -74,6 +74,7 @@ public: void multi_select(const MultiSelector& selector); const SelectionList& selections() const { return m_selections; } + const Selection& main_selection() const { return m_selections.back(); } std::vector selections_content() const; bool undo(); diff --git a/src/input_handler.cc b/src/input_handler.cc index b54b790f..658b0d56 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -549,7 +549,7 @@ private: { if (not m_position.is_valid()) { - BufferIterator cursor = m_context.editor().selections().back().last(); + BufferIterator cursor = m_context.editor().main_selection().last(); auto completions = complete_opt(cursor, m_context.options()); if (completions.first.empty()) completions = complete_word(cursor); diff --git a/src/main.cc b/src/main.cc index 8ae6735f..19168bf8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -89,7 +89,7 @@ void do_go(Context& context) } case 'f': { - String filename = context.editor().selections().back().content(); + String filename = context.editor().main_selection().content(); static char forbidden[] = { '\'', '\\', '\0' }; for (auto c : forbidden) if (contains(filename, c)) @@ -646,7 +646,7 @@ std::unordered_map> keymap = { { Key::Modifiers::Alt, '/' }, do_search }, { { Key::Modifiers::Alt, '?' }, do_search }, { { Key::Modifiers::None, 'n' }, do_search_next }, - { { Key::Modifiers::Alt, 'n' }, do_search_next }, + { { Key::Modifiers::Alt, 'n' }, do_search_next }, { { Key::Modifiers::None, 'N' }, do_search_next }, { { Key::Modifiers::None, '*' }, use_selection_as_search_pattern }, @@ -711,10 +711,10 @@ void register_env_vars() { return ClientManager::instance().get_client_name(context); }); shell_manager.register_env_var("cursor_line", [](const String& name, const Context& context) - { return int_to_str((int)context.editor().selections().back().last().line() + 1); }); + { return int_to_str((int)context.editor().main_selection().last().line() + 1); }); shell_manager.register_env_var("cursor_column", [](const String& name, const Context& context) - { return int_to_str((int)context.editor().selections().back().last().column() + 1); }); + { return int_to_str((int)context.editor().main_selection().last().column() + 1); }); } void register_registers() diff --git a/src/unit_tests.cc b/src/unit_tests.cc index 09ad7f4e..913693f2 100644 --- a/src/unit_tests.cc +++ b/src/unit_tests.cc @@ -70,7 +70,7 @@ void test_editor() Selection sel{ buffer.iterator_at_line_begin(2_line), buffer.end() }; editor.select(sel, SelectMode::Replace); editor.insert("",InsertMode::Replace); - assert(not editor.selections().back().first().is_end()); + assert(not editor.main_selection().first().is_end()); } void test_incremental_inserter() diff --git a/src/window.cc b/src/window.cc index 473fa5f5..f5fba1f9 100644 --- a/src/window.cc +++ b/src/window.cc @@ -40,7 +40,7 @@ Window::~Window() void Window::center_selection() { - BufferIterator cursor = selections().back().last(); + BufferIterator cursor = main_selection().last(); m_position.line = std::max(0_line, cursor.line() - m_dimensions.line/2_line); } @@ -87,8 +87,8 @@ void Window::set_dimensions(const DisplayCoord& dimensions) void Window::scroll_to_keep_cursor_visible_ifn() { - const BufferIterator first = selections().back().first(); - const BufferIterator last = selections().back().last(); + const BufferIterator first = main_selection().first(); + const BufferIterator last = main_selection().last(); // scroll lines if needed if (first.line() < m_position.line)