feat: allow sharing from neo-tree view

This commit is contained in:
əlemi 2024-09-15 12:43:59 +02:00
parent 637a6ee11d
commit f6561ad361
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,5 +1,6 @@
local cc = require("neo-tree.sources.common.commands")
local utils = require("neo-tree.utils")
local codemp_utils = require("codemp.utils")
local manager = require("neo-tree.sources.manager")
local session = require("codemp.session")
local buf_manager = require("codemp.buffers")
@ -63,14 +64,32 @@ end
M.move = function(state, path, extra)
local selected = state.tree:get_node()
if selected.type == "buffer" then
return vim.ui.input({ prompt = "move content into open buffer?" }, function (input)
if input == nil then return end
if not vim.startswith("y", string.lower(input)) then return end
local window = utils.get_appropriate_window(state)
local buf = vim.api.nvim_win_get_buf(window)
buf_manager.attach(selected.name, buf)
return
end)
end
error("only buffers can be moved to current file")
end
M.copy = function(state, path, extra)
local selected = state.tree:get_node()
if selected.type == "buffer" then
return vim.ui.input({ prompt = "copy content to remote buffer?" }, function (input)
if input == nil then return end
if not vim.startswith("y", string.lower(input)) then return end
local window = utils.get_appropriate_window(state)
local buf = vim.api.nvim_win_get_buf(window)
local content = codemp_utils.buffer.get_content(buf)
buf_manager.attach(selected.name, buf, content)
end)
end
error("current file can only be copied into buffers")
end
M.delete = function(state, path, extra)
local selected = state.tree:get_node()
if selected.type == "root" and vim.startswith(selected.name, "#") then