From 42fae293917e2b64c9d7dcb87f2acfd07f42268e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 19 Mar 2013 14:04:24 +0100 Subject: [PATCH] Add an 'insert_hide_sel' option, which hides selection when inserting --- src/highlighters.cc | 18 +++++++++++------- src/option_manager.cc | 1 + src/window.cc | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index c02255fb..7c9de93d 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -259,20 +259,24 @@ void show_line_numbers(DisplayBuffer& display_buffer) } } -void highlight_selections(const Editor& editor, DisplayBuffer& display_buffer) +void highlight_selections(const Window& window, DisplayBuffer& display_buffer) { - for (size_t i = 0; i < editor.selections().size(); ++i) + const bool only_cursor = window.is_editing() and window.options()["insert_hide_sel"].get(); + for (size_t i = 0; i < window.selections().size(); ++i) { - auto& sel = editor.selections()[i]; + auto& sel = window.selections()[i]; const bool forward = sel.first() <= sel.last(); BufferIterator begin = forward ? sel.first() : utf8::next(sel.last()); BufferIterator end = forward ? sel.last() : utf8::next(sel.first()); - const bool primary = (i == editor.main_selection_index()); - ColorPair sel_colors = ColorRegistry::instance()[primary ? "PrimarySelection" : "SecondarySelection"]; + const bool primary = (i == window.main_selection_index()); + if (not only_cursor) + { + ColorPair sel_colors = ColorRegistry::instance()[primary ? "PrimarySelection" : "SecondarySelection"]; + highlight_range(display_buffer, begin, end, false, + [&](DisplayAtom& atom) { atom.colors = sel_colors; }); + } ColorPair cur_colors = ColorRegistry::instance()[primary ? "PrimaryCursor" : "SecondaryCursor"]; - highlight_range(display_buffer, begin, end, false, - [&](DisplayAtom& atom) { atom.colors = sel_colors; }); highlight_range(display_buffer, sel.last(), utf8::next(sel.last()), false, [&](DisplayAtom& atom) { atom.colors = cur_colors; }); } diff --git a/src/option_manager.cc b/src/option_manager.cc index f561d685..e866b6f5 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -260,6 +260,7 @@ GlobalOptions::GlobalOptions() declare_option("filetype", ""); declare_option>("completions", {}); declare_option>("path", { "./", "/usr/include" }); + declare_option("insert_hide_sel", false); } template diff --git a/src/window.cc b/src/window.cc index 56ac12f3..4abcab75 100644 --- a/src/window.cc +++ b/src/window.cc @@ -12,7 +12,7 @@ namespace Kakoune { // Implementation in highlighters.cc -void highlight_selections(const Editor& editor, DisplayBuffer& display_buffer); +void highlight_selections(const Window& window, DisplayBuffer& display_buffer); void expand_tabulations(const OptionManager& options, DisplayBuffer& display_buffer); void expand_unprintable(DisplayBuffer& display_buffer);