implement tab splitting

When a user drags the tab out of the tab bar and releases it, a new
instance with that tab is created. Only DocViews are supported.
This commit is contained in:
takase1121 2021-08-30 15:21:03 +08:00
parent 3c80559db2
commit 062e588fde
No known key found for this signature in database
GPG Key ID: 60EEFFC68EB3031B
1 changed files with 14 additions and 2 deletions

View File

@ -786,6 +786,7 @@ function RootView:on_mouse_pressed(button, x, y, clicks)
if button == "middle" or node.hovered_close == idx then if button == "middle" or node.hovered_close == idx then
node:close_view(self.root_node, node.views[idx]) node:close_view(self.root_node, node.views[idx])
else else
system.capture_mouse(true)
self.dragged_node = { node, idx } self.dragged_node = { node, idx }
node:set_active_view(node.views[idx]) node:set_active_view(node.views[idx])
end end
@ -798,14 +799,25 @@ function RootView:on_mouse_pressed(button, x, y, clicks)
end end
function RootView:on_mouse_released(...) function RootView:on_mouse_released(button, x, y)
if self.dragged_divider then if self.dragged_divider then
self.dragged_divider = nil self.dragged_divider = nil
end end
if self.dragged_node then if self.dragged_node then
local _, _, _, h = Node.get_tab_rect(self.dragged_node[1], self.dragged_node[2])
if x < 0 or x > self.size.x or y < 0 or y > h then
local tab = self.dragged_node[1].views[self.dragged_node[2]]
if tab:is(DocView) then
local filename = tab.doc.abs_filename or tab.doc.filename or "unsaved"
core.fork(filename)
else
core.log("tab splitting is not supported for this View")
end
end
system.capture_mouse(false)
self.dragged_node = nil self.dragged_node = nil
end end
self.root_node:on_mouse_released(...) self.root_node:on_mouse_released(button, x, y)
end end