Skip to content

Commit e7dcecb

Browse files
committed
feat(nvim-tree#2395): extends default bulk.move functionality with prompt option
1 parent d52fdeb commit e7dcecb

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

doc/nvim-tree-lua.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -2066,9 +2066,15 @@ marks.bulk.delete() *nvim-tree-api.marks.bulk.delete()*
20662066
marks.bulk.trash() *nvim-tree-api.marks.bulk.trash()*
20672067
Trash all marked. Optionally prompts.
20682068

2069-
marks.bulk.move() *nvim-tree-api.marks.bulk.move()*
2069+
marks.bulk.move({opts}) *nvim-tree-api.marks.bulk.move()*
20702070
Prompts for a directory to move all marked nodes into.
20712071

2072+
Parameters: ~
2073+
{opts} (table) optional parameters
2074+
2075+
Options: ~
2076+
{prompt} (fun(absolute_path: string): string) takes the absolute path of the node under the cursor, returns the absolute path for the prompt
2077+
20722078
marks.navigate.next() *nvim-tree-api.marks.navigate.next()*
20732079
Navigate to the next marked node, wraps.
20742080
Opens files as per |nvim-tree.actions.open_file|

lua/nvim-tree/api.lua

+4
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ Api.marks.toggle = wrap_node(marks.toggle_mark)
238238
Api.marks.clear = wrap(marks.clear_marks)
239239
Api.marks.bulk.delete = wrap(marks_bulk_delete.bulk_delete)
240240
Api.marks.bulk.trash = wrap(marks_bulk_trash.bulk_trash)
241+
242+
---@class ApiTreeBulkMoveOpts
243+
---@field prompt fun(absolute_path: string): string
244+
241245
Api.marks.bulk.move = wrap(marks_bulk_move.bulk_move)
242246
Api.marks.navigate.next = wrap(marks_navigation.next)
243247
Api.marks.navigate.prev = wrap(marks_navigation.prev)

lua/nvim-tree/marks/bulk-move.lua

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@ local core = require "nvim-tree.core"
33
local utils = require "nvim-tree.utils"
44
local rename_file = require "nvim-tree.actions.fs.rename-file"
55
local notify = require "nvim-tree.notify"
6+
local lib = require "nvim-tree.lib"
67

78
local M = {
89
config = {},
910
}
1011

11-
function M.bulk_move()
12+
---@param opts ApiTreeBulkMoveOpts
13+
function M.bulk_move(opts)
1214
if #marks.get_marks() == 0 then
1315
notify.warn "No bookmarks to move."
1416
return
1517
end
1618

19+
local defaultPrompt = core.get_cwd()
20+
21+
if type(opts) == "table" and opts.prompt and type(opts.prompt) == "function" then
22+
defaultPrompt = opts.prompt(lib.get_node_at_cursor().absolute_path)
23+
end
24+
1725
local input_opts = {
1826
prompt = "Move to: ",
19-
default = core.get_cwd(),
27+
default = defaultPrompt,
2028
completion = "dir",
2129
}
2230

0 commit comments

Comments
 (0)