mirror of
https://github.com/preservim/nerdtree.git
synced 2025-02-22 04:37:40 +08:00
Better handling file renaming and deleting
If you are renaming a file via the mm hotkey and it is already opened then all tabs and windows containing the old file will be replaced with a new file. Current tab and windows structure is not changed anymore If you are deleting a file via the md hotkey and it is already open, i.e. presents in buffer lists then a buffer will be removed but a window and tab will be kept with a ':enew' file
This commit is contained in:
parent
0a16b24268
commit
6b687977d9
@ -58,7 +58,41 @@ endfunction
|
||||
function! s:promptToDelBuffer(bufnum, msg)
|
||||
echo a:msg
|
||||
if g:NERDTreeAutoDeleteBuffer || nr2char(getchar()) ==# 'y'
|
||||
exec "silent bdelete! " . a:bufnum
|
||||
" 1. ensure that all windows which display the just deleted filename
|
||||
" now display an empty buffer (so a layout is preserved).
|
||||
" Is not it better to close single tabs with this file only ?
|
||||
let s:originalTabNumber = tabpagenr()
|
||||
let s:originalWindowNumber = winnr()
|
||||
exec "tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':enew! ' | endif"
|
||||
exec "tabnext " . s:originalTabNumber
|
||||
exec s:originalWindowNumber . "wincmd w"
|
||||
" 3. We don't need a previous buffer anymore
|
||||
exec "bwipeout! " . a:bufnum
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:promptToRenameBuffer(bufnum, msg){{{1
|
||||
"prints out the given msg and, if the user responds by pushing 'y' then the
|
||||
"buffer with the given bufnum is replaced with a new one
|
||||
"
|
||||
"Args:
|
||||
"bufnum: the buffer that may be deleted
|
||||
"msg: a message that will be echoed to the user asking them if they wish to
|
||||
" del the buffer
|
||||
function! s:promptToRenameBuffer(bufnum, msg, newFileName)
|
||||
echo a:msg
|
||||
if g:NERDTreeAutoDeleteBuffer || nr2char(getchar()) ==# 'y'
|
||||
" 1. ensure that a new buffer is loaded
|
||||
exec "badd " . a:newFileName
|
||||
" 2. ensure that all windows which display the just deleted filename
|
||||
" display a buffer for a new filename.
|
||||
let s:originalTabNumber = tabpagenr()
|
||||
let s:originalWindowNumber = winnr()
|
||||
exec "tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':e! " . a:newFileName . "' | endif"
|
||||
exec "tabnext " . s:originalTabNumber
|
||||
exec s:originalWindowNumber . "wincmd w"
|
||||
" 3. We don't need a previous buffer anymore
|
||||
exec "bwipeout! " . a:bufnum
|
||||
endif
|
||||
endfunction
|
||||
"FUNCTION: NERDTreeAddNode(){{{1
|
||||
@ -112,8 +146,8 @@ function! NERDTreeMoveNode()
|
||||
"if the node is open in a buffer, ask the user if they want to
|
||||
"close that buffer
|
||||
if bufnum != -1
|
||||
let prompt = "\nNode renamed.\n\nThe old file is open in buffer ". bufnum . (bufwinnr(bufnum) ==# -1 ? " (hidden)" : "") .". Delete this buffer? (yN)"
|
||||
call s:promptToDelBuffer(bufnum, prompt)
|
||||
let prompt = "\nNode renamed.\n\nThe old file is open in buffer ". bufnum . (bufwinnr(bufnum) ==# -1 ? " (hidden)" : "") .". Replace this buffer with a new file? (yN)"
|
||||
call s:promptToRenameBuffer(bufnum, prompt, newNodePath)
|
||||
endif
|
||||
|
||||
call curNode.putCursorHere(1, 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user