1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-24 20:13:00 +03:00

Add an 'insert_hide_sel' option, which hides selection when inserting

This commit is contained in:
Maxime Coste 2013-03-19 14:04:24 +01:00
parent f0baf35117
commit 42fae29391
3 changed files with 13 additions and 8 deletions

View File

@ -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<bool>();
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; });
}

View File

@ -260,6 +260,7 @@ GlobalOptions::GlobalOptions()
declare_option<String>("filetype", "");
declare_option<std::vector<String>>("completions", {});
declare_option<std::vector<String>>("path", { "./", "/usr/include" });
declare_option<bool>("insert_hide_sel", false);
}
template<typename T>

View File

@ -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);