1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-18 08:51:46 +03:00

Support changing autoreload option directly from the reload message

Pressing Y or N will set the buffer (or window, if it is set at that
scope) autoreload option to the corresponding value, avoiding infinite
loops where a file getting constantly modified prevents the user from
using Kakoune.
This commit is contained in:
Maxime Coste 2018-03-05 11:17:57 +11:00
parent 07113e7ee5
commit 9c85d9b389

View File

@ -294,14 +294,28 @@ void Client::on_buffer_reload_key(Key key)
{
auto& buffer = context().buffer();
if (key == 'y' or key == Key::Return)
auto set_autoreload = [this](Autoreload autoreload) {
auto* option = &context().options()["autoreload"];
// Do not touch global autoreload, set it at least at buffer level
if (&option->manager() == &GlobalScope::instance().options())
option = &context().buffer().options().get_local_option("autoreload");
option->set(autoreload);
};
if (key == 'y' or key == 'Y' or key == Key::Return)
{
reload_buffer();
else if (key == 'n' or key == Key::Escape)
if (key == 'Y')
set_autoreload(Autoreload::Yes);
}
else if (key == 'n' or key == 'N' or key == Key::Escape)
{
// reread timestamp in case the file was modified again
buffer.set_fs_timestamp(get_fs_timestamp(buffer.name()));
print_status({ format("'{}' kept", buffer.display_name()),
get_face("Information") });
if (key == 'N')
set_autoreload(Autoreload::No);
}
else
{
@ -347,7 +361,8 @@ void Client::check_if_buffer_needs_reloading()
StringView bufname = buffer.display_name();
info_show(format("reload '{}' ?", bufname),
format("'{}' was modified externally\n"
"press <ret> or y to reload, <esc> or n to keep",
" y, <ret>: reload | n, <esc>: keep\n"
" Y: always reload | N: always keep\n",
bufname), {}, InfoStyle::Modal);
m_buffer_reload_dialog_opened = true;