Skip to content

Commit f9fb648

Browse files
authored
Merge branch 'master' into master
2 parents e13ac90 + 8f2a50f commit f9fb648

File tree

10 files changed

+77
-12
lines changed

10 files changed

+77
-12
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ name: CI
22

33
on:
44
pull_request:
5+
push:
6+
branches: [master]
57
workflow_dispatch:
68

9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
11+
cancel-in-progress: true
12+
713
permissions:
814
contents: read
915

.github/workflows/release-please.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ on:
33
branches:
44
- master
55
workflow_dispatch:
6-
6+
concurrency:
7+
group: ${{ github.workflow }}
8+
cancel-in-progress: true
79
name: release-please
810
permissions:
911
contents: write

.github/workflows/semantic-pr-subject.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ on:
77
- edited
88
- synchronize
99
workflow_dispatch:
10-
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.head_ref }}
12+
cancel-in-progress: true
1113
jobs:
1214
semantic-pr-subject:
1315
runs-on: ubuntu-latest

doc/nvim-tree-lua.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ Show the mappings: `g?`
185185
`f` Live Filter: Start |nvim-tree-api.live_filter.start()|
186186
`g?` Help |nvim-tree-api.tree.toggle_help()|
187187
`gy` Copy Absolute Path |nvim-tree-api.fs.copy.absolute_path()|
188+
`ge` Copy Basename |nvim-tree-api.fs.copy.basename()|
188189
`H` Toggle Filter: Dotfiles |nvim-tree-api.tree.toggle_hidden_filter()|
189190
`I` Toggle Filter: Git Ignore |nvim-tree-api.tree.toggle_gitignore_filter()|
190191
`J` Last Sibling |nvim-tree-api.node.navigate.sibling.last()|
@@ -2240,6 +2241,7 @@ You are encouraged to copy these to your own |nvim-tree.on_attach| function.
22402241
vim.keymap.set('n', 'f', api.live_filter.start, opts('Live Filter: Start'))
22412242
vim.keymap.set('n', 'g?', api.tree.toggle_help, opts('Help'))
22422243
vim.keymap.set('n', 'gy', api.fs.copy.absolute_path, opts('Copy Absolute Path'))
2244+
vim.keymap.set('n', 'ge', api.fs.copy.basename, opts('Copy Basename'))
22432245
vim.keymap.set('n', 'H', api.tree.toggle_hidden_filter, opts('Toggle Filter: Dotfiles'))
22442246
vim.keymap.set('n', 'I', api.tree.toggle_gitignore_filter, opts('Toggle Filter: Git Ignore'))
22452247
vim.keymap.set('n', 'J', api.node.navigate.sibling.last, opts('Last Sibling'))

lua/nvim-tree.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ function M.open_on_directory()
105105
end
106106

107107
function M.place_cursor_on_node()
108-
local search = vim.fn.searchcount()
109-
if search and search.exact_match == 1 then
108+
local ok, search = pcall(vim.fn.searchcount)
109+
if ok and search and search.exact_match == 1 then
110110
return
111111
end
112112

lua/nvim-tree/actions/fs/copy-paste.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ function M.copy_filename(node)
295295
copy_to_clipboard(node.name)
296296
end
297297

298+
---@param node Node
299+
function M.copy_basename(node)
300+
local basename = vim.fn.fnamemodify(node.name, ":r")
301+
copy_to_clipboard(basename)
302+
end
303+
298304
---@param node Node
299305
function M.copy_path(node)
300306
local absolute_path = node.absolute_path

lua/nvim-tree/actions/fs/rename-file.lua

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ local M = {
99
config = {},
1010
}
1111

12+
---@param iter function iterable
13+
---@return integer
14+
local function get_num_nodes(iter)
15+
local i = 0
16+
for _ in iter do
17+
i = i + 1
18+
end
19+
return i
20+
end
21+
1222
local ALLOWED_MODIFIERS = {
1323
[":p"] = true,
1424
[":p:h"] = true,
@@ -31,15 +41,46 @@ function M.rename(node, to)
3141
return
3242
end
3343

34-
events._dispatch_will_rename_node(node.absolute_path, to)
35-
local success, err = vim.loop.fs_rename(node.absolute_path, to)
36-
if not success then
37-
notify.warn(err_fmt(notify_from, notify_to, err))
38-
return
44+
-- create a folder for each path element if the folder does not exist
45+
local idx = 0
46+
local path_to_create = ""
47+
48+
local num_nodes = get_num_nodes(utils.path_split(utils.path_remove_trailing(to)))
49+
local is_error = false
50+
for path in utils.path_split(to) do
51+
idx = idx + 1
52+
53+
local p = utils.path_remove_trailing(path)
54+
if #path_to_create == 0 and vim.fn.has "win32" == 1 then
55+
path_to_create = utils.path_join { p, path_to_create }
56+
else
57+
path_to_create = utils.path_join { path_to_create, p }
58+
end
59+
60+
if idx == num_nodes then
61+
events._dispatch_will_rename_node(node.absolute_path, to)
62+
local success, err = vim.loop.fs_rename(node.absolute_path, to)
63+
64+
if not success then
65+
notify.warn(err_fmt(notify_from, notify_to, err))
66+
return
67+
end
68+
elseif not utils.file_exists(path_to_create) then
69+
local success = vim.loop.fs_mkdir(path_to_create, 493)
70+
if not success then
71+
notify.error("Could not create folder " .. notify.render_path(path_to_create))
72+
is_error = true
73+
break
74+
end
75+
is_error = false
76+
end
77+
end
78+
79+
if not is_error then
80+
notify.info(string.format("%s -> %s", notify_from, notify_to))
81+
utils.rename_loaded_buffers(node.absolute_path, to)
82+
events._dispatch_node_renamed(node.absolute_path, to)
3983
end
40-
notify.info(string.format("%s -> %s", notify_from, notify_to))
41-
utils.rename_loaded_buffers(node.absolute_path, to)
42-
events._dispatch_node_renamed(node.absolute_path, to)
4384
end
4485

4586
---@param default_modifier string|nil

lua/nvim-tree/api.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Api.fs.print_clipboard = wrap(actions.fs.copy_paste.print_clipboard)
163163
Api.fs.copy.node = wrap_node(actions.fs.copy_paste.copy)
164164
Api.fs.copy.absolute_path = wrap_node(actions.fs.copy_paste.copy_absolute_path)
165165
Api.fs.copy.filename = wrap_node(actions.fs.copy_paste.copy_filename)
166+
Api.fs.copy.basename = wrap_node(actions.fs.copy_paste.copy_basename)
166167
Api.fs.copy.relative_path = wrap_node(actions.fs.copy_paste.copy_path)
167168

168169
---@param mode string

lua/nvim-tree/git/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ end
136136
---@param path string absolute
137137
---@return string|nil
138138
function M.get_toplevel(path)
139+
if not path then
140+
return nil
141+
end
142+
139143
if not M.config.git.enable then
140144
return nil
141145
end

lua/nvim-tree/keymap.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function M.default_on_attach(bufnr)
6868
vim.keymap.set('n', 'f', api.live_filter.start, opts('Live Filter: Start'))
6969
vim.keymap.set('n', 'g?', api.tree.toggle_help, opts('Help'))
7070
vim.keymap.set('n', 'gy', api.fs.copy.absolute_path, opts('Copy Absolute Path'))
71+
vim.keymap.set('n', 'ge', api.fs.copy.basename, opts('Copy Basename'))
7172
vim.keymap.set('n', 'H', api.tree.toggle_hidden_filter, opts('Toggle Filter: Dotfiles'))
7273
vim.keymap.set('n', 'I', api.tree.toggle_gitignore_filter, opts('Toggle Filter: Git Ignore'))
7374
vim.keymap.set('n', 'J', api.node.navigate.sibling.last, opts('Last Sibling'))

0 commit comments

Comments
 (0)