Redraw relevant clients after adding/removing highlighters
This commit is contained in:
parent
7c1d4f5bd6
commit
22bfbd06af
|
@ -171,20 +171,21 @@ void Client::change_buffer(Buffer& buffer)
|
||||||
close_buffer_reload_dialog();
|
close_buffer_reload_dialog();
|
||||||
|
|
||||||
auto& client_manager = ClientManager::instance();
|
auto& client_manager = ClientManager::instance();
|
||||||
|
WindowAndSelections ws = client_manager.get_free_window(buffer);
|
||||||
|
|
||||||
m_window->options().unregister_watcher(*this);
|
m_window->options().unregister_watcher(*this);
|
||||||
m_window->set_client(nullptr);
|
m_window->set_client(nullptr);
|
||||||
|
|
||||||
WindowAndSelections ws = client_manager.get_free_window(buffer);
|
|
||||||
client_manager.add_free_window(std::move(m_window),
|
client_manager.add_free_window(std::move(m_window),
|
||||||
std::move(context().selections()));
|
std::move(context().selections()));
|
||||||
|
|
||||||
m_window = std::move(ws.window);
|
m_window = std::move(ws.window);
|
||||||
m_window->set_client(this);
|
m_window->set_client(this);
|
||||||
m_window->options().register_watcher(*this);
|
m_window->options().register_watcher(*this);
|
||||||
m_ui->set_ui_options(m_window->options()["ui_options"].get<UserInterface::Options>());
|
|
||||||
|
|
||||||
context().selections_write_only() = std::move(ws.selections);
|
context().selections_write_only() = std::move(ws.selections);
|
||||||
context().set_window(*m_window);
|
context().set_window(*m_window);
|
||||||
|
|
||||||
m_window->set_dimensions(m_ui->dimensions());
|
m_window->set_dimensions(m_ui->dimensions());
|
||||||
|
m_ui->set_ui_options(m_window->options()["ui_options"].get<UserInterface::Options>());
|
||||||
|
|
||||||
m_window->hooks().run_hook(Hook::WinDisplay, buffer.name(), context());
|
m_window->hooks().run_hook(Hook::WinDisplay, buffer.name(), context());
|
||||||
force_redraw();
|
force_redraw();
|
||||||
|
|
|
@ -900,6 +900,27 @@ Highlighter& get_highlighter(const Context& context, StringView path)
|
||||||
return *root;
|
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 = {
|
const CommandDesc add_highlighter_cmd = {
|
||||||
"add-highlighter",
|
"add-highlighter",
|
||||||
"addhl",
|
"addhl",
|
||||||
|
@ -948,9 +969,7 @@ const CommandDesc add_highlighter_cmd = {
|
||||||
parent.add_child(name.empty() ? auto_name(parser.positionals_from(1)) : std::move(name),
|
parent.add_child(name.empty() ? auto_name(parser.positionals_from(1)) : std::move(name),
|
||||||
it->value.factory(highlighter_params, &parent));
|
it->value.factory(highlighter_params, &parent));
|
||||||
|
|
||||||
// TODO: better, this will fail if we touch scopes highlighters that impact multiple windows
|
redraw_relevant_clients(context, path);
|
||||||
if (context.has_window())
|
|
||||||
context.window().force_redraw();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -973,9 +992,7 @@ const CommandDesc remove_highlighter_cmd = {
|
||||||
if (sep_it == rev_path.end())
|
if (sep_it == rev_path.end())
|
||||||
return;
|
return;
|
||||||
get_highlighter(context, {path.begin(), sep_it.base()}).remove_child({sep_it.base(), path.end()});
|
get_highlighter(context, {path.begin(), sep_it.base()}).remove_child({sep_it.base(), path.end()});
|
||||||
|
redraw_relevant_clients(context, path);
|
||||||
if (context.has_window())
|
|
||||||
context.window().force_redraw();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,6 @@ void Context::change_buffer(Buffer& buffer)
|
||||||
m_last_buffer = contains(BufferManager::instance(), current) ? current : nullptr;
|
m_last_buffer = contains(BufferManager::instance(), current) ? current : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_window.reset();
|
|
||||||
if (has_client())
|
if (has_client())
|
||||||
{
|
{
|
||||||
client().info_hide();
|
client().info_hide();
|
||||||
|
@ -186,7 +185,10 @@ void Context::change_buffer(Buffer& buffer)
|
||||||
client().change_buffer(buffer);
|
client().change_buffer(buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
m_window.reset();
|
||||||
m_selections = SelectionList{buffer, Selection{}};
|
m_selections = SelectionList{buffer, Selection{}};
|
||||||
|
}
|
||||||
|
|
||||||
if (has_input_handler())
|
if (has_input_handler())
|
||||||
input_handler().reset_normal_mode();
|
input_handler().reset_normal_mode();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user