From 116ea10fe24252328b6a7e93bb80617df95630c7 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 22 Apr 2023 13:24:54 -0400 Subject: [PATCH] Added in double-clicking on emptyview and tab bar. (#1478) * Added in double-clicking on emptyview and tab bar. * Fixed issue with split tabs. * Early exit if no overlapping node. * Changed category of command to tabbar. * Additional cleanup. * Changed for whether we should show tabs. * Fixed erroneous hover. --- data/core/commands/root.lua | 15 +++++++++++++++ data/core/keymap.lua | 2 +- data/core/node.lua | 9 ++++++++- data/core/rootview.lua | 10 ++++------ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/data/core/commands/root.lua b/data/core/commands/root.lua index acbd697c..0ae4c68e 100644 --- a/data/core/commands/root.lua +++ b/data/core/commands/root.lua @@ -176,3 +176,18 @@ command.add(function() end } ) + +-- double clicking the tab bar, or on the emptyview should open a new doc +command.add(function(x, y) + local node = x and y and core.root_view.root_node:get_child_overlapping_point(x, y) + return node and node:is_in_tab_area(x, y) +end, { + ["tabbar:new-doc"] = function() + command.perform("core:new-doc") + end +}) +command.add("core.emptyview", { + ["emptyview:new-doc"] = function() + command.perform("core:new-doc") + end +}) diff --git a/data/core/keymap.lua b/data/core/keymap.lua index c0a78dd3..f2257a3e 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -369,7 +369,7 @@ keymap.add_direct { ["shift+1lclick"] = "doc:select-to-cursor", ["ctrl+1lclick"] = "doc:split-cursor", ["1lclick"] = "doc:set-cursor", - ["2lclick"] = "doc:set-cursor-word", + ["2lclick"] = { "doc:set-cursor-word", "emptyview:new-doc", "tabbar:new-doc" }, ["3lclick"] = "doc:set-cursor-line", ["shift+left"] = "doc:select-to-previous-char", ["shift+right"] = "doc:select-to-next-char", diff --git a/data/core/node.lua b/data/core/node.lua index aff4bb11..e282882c 100644 --- a/data/core/node.lua +++ b/data/core/node.lua @@ -308,7 +308,7 @@ function Node:tab_hovered_update(px, py) if px >= cx and px < cx + cw and py >= y and py < y + h and config.tab_close_button then self.hovered_close = tab_index end - else + elseif #self.views > self:get_visible_tabs_number() then self.hovered_scroll_button = self:get_scroll_button_index(px, py) or 0 end end @@ -615,6 +615,13 @@ function Node:is_empty() end +function Node:is_in_tab_area(x, y) + if not self:should_show_tabs() then return false end + local _, ty, _, th = self:get_scroll_button_rect(1) + return y >= ty and y < ty + th +end + + function Node:close_all_docviews(keep_active) local node_active_view = self.active_view local lost_active_view = false diff --git a/data/core/rootview.lua b/data/core/rootview.lua index f9bde17e..c6b18c47 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -291,16 +291,14 @@ function RootView:on_mouse_moved(x, y, dx, dy) if last_overlapping_node and last_overlapping_node ~= self.overlapping_node then last_overlapping_node:on_mouse_left() end + if not self.overlapping_node then return end local div = self.root_node:get_divider_overlapping_point(x, y) - local tab_index = self.overlapping_node and self.overlapping_node:get_tab_overlapping_point(x, y) - if self.overlapping_node and self.overlapping_node:get_scroll_button_index(x, y) then + if self.overlapping_node:get_scroll_button_index(x, y) or self.overlapping_node:is_in_tab_area(x, y) then core.request_cursor("arrow") - elseif div and (self.overlapping_node and not self.overlapping_node.active_view:scrollbar_overlaps_point(x, y)) then + elseif div and not self.overlapping_node.active_view:scrollbar_overlaps_point(x, y) then core.request_cursor(div.type == "hsplit" and "sizeh" or "sizev") - elseif tab_index then - core.request_cursor("arrow") - elseif self.overlapping_node then + else core.request_cursor(self.overlapping_node.active_view.cursor) end end