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:
parent
07113e7ee5
commit
9c85d9b389
|
@ -294,14 +294,28 @@ void Client::on_buffer_reload_key(Key key)
|
||||||
{
|
{
|
||||||
auto& buffer = context().buffer();
|
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();
|
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
|
// reread timestamp in case the file was modified again
|
||||||
buffer.set_fs_timestamp(get_fs_timestamp(buffer.name()));
|
buffer.set_fs_timestamp(get_fs_timestamp(buffer.name()));
|
||||||
print_status({ format("'{}' kept", buffer.display_name()),
|
print_status({ format("'{}' kept", buffer.display_name()),
|
||||||
get_face("Information") });
|
get_face("Information") });
|
||||||
|
if (key == 'N')
|
||||||
|
set_autoreload(Autoreload::No);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -347,7 +361,8 @@ void Client::check_if_buffer_needs_reloading()
|
||||||
StringView bufname = buffer.display_name();
|
StringView bufname = buffer.display_name();
|
||||||
info_show(format("reload '{}' ?", bufname),
|
info_show(format("reload '{}' ?", bufname),
|
||||||
format("'{}' was modified externally\n"
|
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);
|
bufname), {}, InfoStyle::Modal);
|
||||||
|
|
||||||
m_buffer_reload_dialog_opened = true;
|
m_buffer_reload_dialog_opened = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user