From f6561ad36165581f9802663adb1c1db723a5ee11 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 15 Sep 2024 12:43:59 +0200 Subject: [PATCH] feat: allow sharing from neo-tree view --- lua/codemp/neo-tree/commands.lua | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lua/codemp/neo-tree/commands.lua b/lua/codemp/neo-tree/commands.lua index cddea8e..2ce5edb 100644 --- a/lua/codemp/neo-tree/commands.lua +++ b/lua/codemp/neo-tree/commands.lua @@ -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 - local window = utils.get_appropriate_window(state) - local buf = vim.api.nvim_win_get_buf(window) - buf_manager.attach(selected.name, buf) - return + 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) + 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