From 5a0f037b714513af96f71aa098096a5ad7a19105 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Fri, 2 Jun 2023 17:05:57 +0100 Subject: [PATCH] feat: add the paste functionality into the ivy prompt Now when you paste and you are in an ivy buffer the paste will be added to the prompt not into the completion window. You can use your usual paste key binding I.E. + ++ Ref: #11 --- lua/ivy/controller.lua | 4 ++++ plugin/ivy.lua | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lua/ivy/controller.lua b/lua/ivy/controller.lua index 5c26303..6f0caa4 100644 --- a/lua/ivy/controller.lua +++ b/lua/ivy/controller.lua @@ -30,6 +30,10 @@ controller.search = function(value) controller.update(prompt.text()) end +controller.paste = function() + controller.search(prompt.text() .. vim.fn.getreg "+p") +end + controller.update = function(text) vim.schedule(function() window.set_items(controller.items(text)) diff --git a/plugin/ivy.lua b/plugin/ivy.lua index a3a670e..383e866 100644 --- a/plugin/ivy.lua +++ b/plugin/ivy.lua @@ -25,7 +25,17 @@ local register_backend = function(backend) end end -register_backend(require "ivy.backends.ag") +vim.paste = (function(overridden) + return function(lines, phase) + local file_type = vim.api.nvim_buf_get_option(0, "filetype") + if file_type == "ivy" then + vim.ivy.paste() + else + overridden(lines, phase) + end + end +end)(vim.paste) + register_backend(require "ivy.backends.buffers") register_backend(require "ivy.backends.files") register_backend(require "ivy.backends.lines")