Skip to content

Commit e6d2866

Browse files
committed
Merge remote-tracking branch 'lenormf/focus-modified-on-quit'
Closes #5391
2 parents f36be3c + 9ef4396 commit e6d2866

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/commands.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ const CommandDesc write_all_cmd = {
704704
}
705705
};
706706

707-
static void ensure_all_buffers_are_saved()
707+
static void ensure_all_buffers_are_saved(Context& context)
708708
{
709709
auto is_modified = [](const UniquePtr<Buffer>& buf) {
710710
return (buf->flags() & Buffer::Flags::File) and buf->is_modified();
@@ -715,6 +715,12 @@ static void ensure_all_buffers_are_saved()
715715
if (it == end)
716716
return;
717717

718+
if (not context.buffer().is_modified())
719+
{
720+
context.push_jump();
721+
context.change_buffer(**it);
722+
}
723+
718724
String message = format("{} modified buffers remaining: [",
719725
std::count_if(it, end, is_modified));
720726
while (it != end)
@@ -732,7 +738,7 @@ void kill(const ParametersParser& parser, Context& context, const ShellContext&)
732738
auto& client_manager = ClientManager::instance();
733739

734740
if (not force)
735-
ensure_all_buffers_are_saved();
741+
ensure_all_buffers_are_saved(context);
736742

737743
const int status = parser.positional_count() > 0 ? str_to_int(parser[0]) : 0;
738744
while (not client_manager.empty())
@@ -781,7 +787,7 @@ template<bool force>
781787
void quit(const ParametersParser& parser, Context& context, const ShellContext&)
782788
{
783789
if (not force and ClientManager::instance().count() == 1 and not Server::instance().is_daemon())
784-
ensure_all_buffers_are_saved();
790+
ensure_all_buffers_are_saved(context);
785791

786792
const int status = parser.positional_count() > 0 ? str_to_int(parser[0]) : 0;
787793
ClientManager::instance().remove_client(context.client(), true, status);

0 commit comments

Comments
 (0)