From 22bfbd06af1d0257419a9c9e0f2e3b0ebff30ddb Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 28 Dec 2019 11:27:04 +1100 Subject: [PATCH] Redraw relevant clients after adding/removing highlighters --- src/client.cc | 9 +++++---- src/commands.cc | 29 +++++++++++++++++++++++------ src/context.cc | 4 +++- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/client.cc b/src/client.cc index 2c84de6b..da178623 100644 --- a/src/client.cc +++ b/src/client.cc @@ -171,20 +171,21 @@ void Client::change_buffer(Buffer& buffer) close_buffer_reload_dialog(); auto& client_manager = ClientManager::instance(); + WindowAndSelections ws = client_manager.get_free_window(buffer); + m_window->options().unregister_watcher(*this); m_window->set_client(nullptr); - - WindowAndSelections ws = client_manager.get_free_window(buffer); client_manager.add_free_window(std::move(m_window), std::move(context().selections())); + m_window = std::move(ws.window); m_window->set_client(this); m_window->options().register_watcher(*this); - m_ui->set_ui_options(m_window->options()["ui_options"].get()); - context().selections_write_only() = std::move(ws.selections); context().set_window(*m_window); + m_window->set_dimensions(m_ui->dimensions()); + m_ui->set_ui_options(m_window->options()["ui_options"].get()); m_window->hooks().run_hook(Hook::WinDisplay, buffer.name(), context()); force_redraw(); diff --git a/src/commands.cc b/src/commands.cc index a0ac6777..21ee4d0b 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -900,6 +900,27 @@ Highlighter& get_highlighter(const Context& context, StringView path) return *root; } +static void redraw_relevant_clients(Context& context, StringView highlighter_path) +{ + StringView scope{highlighter_path.begin(), find(highlighter_path, '/')}; + if (scope == "window") + context.window().force_redraw(); + else if (scope == "buffer" or prefix_match(scope, "buffer=")) + { + auto& buffer = scope == "buffer" ? context.buffer() : BufferManager::instance().get_buffer(scope.substr(7_byte)); + for (auto&& client : ClientManager::instance()) + { + if (&client->context().buffer() == &buffer) + client->context().window().force_redraw(); + } + } + else + { + for (auto&& client : ClientManager::instance()) + client->context().window().force_redraw(); + } +} + const CommandDesc add_highlighter_cmd = { "add-highlighter", "addhl", @@ -948,9 +969,7 @@ const CommandDesc add_highlighter_cmd = { parent.add_child(name.empty() ? auto_name(parser.positionals_from(1)) : std::move(name), it->value.factory(highlighter_params, &parent)); - // TODO: better, this will fail if we touch scopes highlighters that impact multiple windows - if (context.has_window()) - context.window().force_redraw(); + redraw_relevant_clients(context, path); } }; @@ -973,9 +992,7 @@ const CommandDesc remove_highlighter_cmd = { if (sep_it == rev_path.end()) return; get_highlighter(context, {path.begin(), sep_it.base()}).remove_child({sep_it.base(), path.end()}); - - if (context.has_window()) - context.window().force_redraw(); + redraw_relevant_clients(context, path); } }; diff --git a/src/context.cc b/src/context.cc index 2a0822ec..07259c97 100644 --- a/src/context.cc +++ b/src/context.cc @@ -178,7 +178,6 @@ void Context::change_buffer(Buffer& buffer) m_last_buffer = contains(BufferManager::instance(), current) ? current : nullptr; } - m_window.reset(); if (has_client()) { client().info_hide(); @@ -186,7 +185,10 @@ void Context::change_buffer(Buffer& buffer) client().change_buffer(buffer); } else + { + m_window.reset(); m_selections = SelectionList{buffer, Selection{}}; + } if (has_input_handler()) input_handler().reset_normal_mode();