Merge pull request #318 from lite-xl/MacOSClose

Created an extra command, to implement appropriate cmd+w behaviour on Mac.
This commit is contained in:
Adam 2021-07-09 14:30:48 -04:00 committed by GitHub
commit e1ae94a01b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 6 deletions

View File

@ -11,6 +11,15 @@ local t = {
node:close_active_view(core.root_view.root_node)
end,
["root:close-or-quit"] = function()
local node = core.root_view:get_active_node()
if node and (not node:is_empty() or not node.is_primary_node) then
node:close_active_view(core.root_view.root_node)
else
core.quit()
end
end,
["root:close-all"] = function()
core.confirm_close_all(core.root_view.close_all_docviews, core.root_view)
end,

View File

@ -17,7 +17,8 @@ local function keymap_macos(keymap)
["cmd+ctrl+i"] = "root:switch-to-up",
["cmd+ctrl+k"] = "root:switch-to-down",
["cmd+w"] = "root:close",
["cmd+w"] = "root:close-or-quit",
["ctrl+tab"] = "root:switch-to-next-tab",
["ctrl+shift+tab"] = "root:switch-to-previous-tab",
["cmd+pageup"] = "root:move-tab-left",
@ -31,7 +32,6 @@ local function keymap_macos(keymap)
["cmd+7"] = "root:switch-to-tab-7",
["cmd+8"] = "root:switch-to-tab-8",
["cmd+9"] = "root:switch-to-tab-9",
["cmd+f"] = "find-replace:find",
["cmd+r"] = "find-replace:replace",
["f3"] = "find-replace:repeat-find",

View File

@ -584,7 +584,7 @@ end
function Node:is_empty()
if self.type == "leaf" then
return #self.views == 0
return #self.views == 0 or (#self.views == 1 and self.views[1]:is(EmptyView))
else
return self.a:is_empty() and self.b:is_empty()
end
@ -608,9 +608,9 @@ function Node:close_all_docviews()
else
self.a:close_all_docviews()
self.b:close_all_docviews()
if self.a:is_empty() then
if self.a:is_empty() and not self.a.is_primary_node then
self:consume(self.b)
elseif self.b:is_empty() then
elseif self.b:is_empty() and not self.b.is_primary_node then
self:consume(self.a)
end
end