diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index ac30fe20..d7d0f1a3 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -155,7 +155,7 @@ command.add(nil, { core.error("Cannot open folder %q", text) return end - core.confirm_close_all(core.open_folder_project, text) + core.confirm_close_docs(core.docs, core.open_folder_project, text) end, suggest_directory) end, diff --git a/data/core/commands/root.lua b/data/core/commands/root.lua index 7bc13283..1375fe89 100644 --- a/data/core/commands/root.lua +++ b/data/core/commands/root.lua @@ -21,9 +21,15 @@ local t = { end, ["root:close-all"] = function() - core.confirm_close_all(core.root_view.close_all_docviews, core.root_view) + core.confirm_close_docs(core.docs, core.root_view.close_all_docviews, core.root_view) end, + ["root:close-all-others"] = function() + local active_doc, docs = core.active_view and core.active_view.doc, {} + for k, v in pairs(core.docs) do if v ~= active_doc then table.insert(docs, v) end end + core.confirm_close_docs(docs, core.root_view.close_all_docviews, core.root_view, true) + end, + ["root:switch-to-previous-tab"] = function() local node = core.root_view:get_active_node() local idx = node:get_view_idx(core.active_view) diff --git a/data/core/init.lua b/data/core/init.lua index 6fbdde48..5c893d88 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -564,10 +564,10 @@ function core.init() end -function core.confirm_close_all(close_fn, ...) +function core.confirm_close_docs(docs, close_fn, ...) local dirty_count = 0 local dirty_name - for _, doc in ipairs(core.docs) do + for _, doc in ipairs(docs or core.docs) do if doc:is_dirty() then dirty_count = dirty_count + 1 dirty_name = doc:get_name() @@ -627,7 +627,7 @@ local function quit_with_function(quit_fn, force) save_session() quit_fn() else - core.confirm_close_all(quit_with_function, quit_fn, true) + core.confirm_close_docs(core.docs, quit_with_function, quit_fn, true) end end diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 3ef22173..c53d40de 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -594,12 +594,13 @@ function Node:is_empty() end -function Node:close_all_docviews() +function Node:close_all_docviews(keep_inactive) if self.type == "leaf" then local i = 1 while i <= #self.views do local view = self.views[i] - if view:is(DocView) and not view:is(CommandView) then + if view:is(DocView) and not view:is(CommandView) and + (not keep_inactive or view ~= self.active_view) then table.remove(self.views, i) else i = i + 1 @@ -609,8 +610,8 @@ function Node:close_all_docviews() self:add_view(EmptyView()) end else - self.a:close_all_docviews() - self.b:close_all_docviews() + self.a:close_all_docviews(keep_inactive) + self.b:close_all_docviews(keep_inactive) if self.a:is_empty() and not self.a.is_primary_node then self:consume(self.b) elseif self.b:is_empty() and not self.b.is_primary_node then @@ -736,8 +737,8 @@ function RootView:open_doc(doc) end -function RootView:close_all_docviews() - self.root_node:close_all_docviews() +function RootView:close_all_docviews(keep_inactive) + self.root_node:close_all_docviews(keep_inactive) end