From 1b667bc99e1e2cf090362579726fa2a55a4e1acc Mon Sep 17 00:00:00 2001 From: kiyan Date: Mon, 18 Jul 2022 14:20:55 +0200 Subject: [PATCH] feat(search-node): use vim.ui.input --- lua/nvim-tree/actions/finders/search-node.lua | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lua/nvim-tree/actions/finders/search-node.lua b/lua/nvim-tree/actions/finders/search-node.lua index 5e410796..94f84268 100644 --- a/lua/nvim-tree/actions/finders/search-node.lua +++ b/lua/nvim-tree/actions/finders/search-node.lua @@ -1,7 +1,6 @@ local api = vim.api local uv = vim.loop -local utils = require "nvim-tree.utils" local core = require "nvim-tree.core" local filters = require "nvim-tree.explorer.filters" local find_file = require("nvim-tree.actions.finders.find-file").fn @@ -56,25 +55,26 @@ function M.fn() local path_existed, path_opt = pcall(api.nvim_buf_get_option, bufnr, "path") api.nvim_buf_set_option(bufnr, "path", core.get_cwd() .. "/**") - -- completes files/dirs under cwd - local input_path = vim.fn.input("Search: ", "", "file_in_path") - utils.clear_prompt() + vim.ui.input({ prompt = "Search: ", completion = "file_in_path" }, function(input_path) + if not input_path or input_path == "" then + return + end + -- reset &path + if path_existed then + api.nvim_buf_set_option(bufnr, "path", path_opt) + else + api.nvim_buf_set_option(bufnr, "path", nil) + end - -- reset &path - if path_existed then - api.nvim_buf_set_option(bufnr, "path", path_opt) - else - api.nvim_buf_set_option(bufnr, "path", nil) - end + -- strip trailing slash + input_path = string.gsub(input_path, "/$", "") - -- strip trailing slash - input_path = string.gsub(input_path, "/$", "") - - -- search under cwd - local found = search(core.get_cwd(), input_path) - if found then - find_file(found) - end + -- search under cwd + local found = search(core.get_cwd(), input_path) + if found then + find_file(found) + end + end) end return M