Merge pull request #36 from kyazdani42/add-tree-preview

add preview
This commit is contained in:
Kiyan Yazdani 2020-06-07 14:52:12 +02:00 committed by GitHub
commit 829538dafc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 20 deletions

View File

@ -47,12 +47,8 @@ let g:lua_tree_bindings = {
\ 'edit_vsplit': '<C-v>',
\ 'edit_split': '<C-x>',
\ 'edit_tab': '<C-t>',
\ 'cd': '.',
\ 'create': 'a',
\ 'remove': 'd',
\ 'rename': 'r'
\ }
\ 'preview': '<Tab>',
\ 'cd': '<C-]>',
" default will show icon by default if no icon is provided
" default shows no icon by default
let g:lua_tree_icons = {
@ -85,19 +81,20 @@ highlight LuaTreeFolderIcon guibg=blue
- move around like in any vim buffer
- `<CR>` on `..` will cd in the above directory
- `.` will cd in the directory under the cursor
- `<C-]>` will cd in the directory under the cursor
- type `a` to add a file. Adding a directory requires leaving a leading `/` at the end of the path.
> you can add multiple directories by doing foo/bar/baz/f and it will add foo bar and baz directories and f as a file
- type `r` to rename a file
- type `d` to delete a file (will prompt for confirmation)
- if the file is a directory, `<CR>` will open the directory otherwise it will open the file in the buffer near the tree
- if the file is a symlink, `<CR>` will follow the symlink (if the target is a file)
- type `<C-v>` will open the file in a vertical split
- type `<C-x>` will open the file in a horizontal split
- type `<C-t>` will open the file in a new tab
- type `gx` to open the file with the `open` command on MACOS and `xdg-open` in linux
- `<C-v>` will open the file in a vertical split
- `<C-x>` will open the file in a horizontal split
- `<C-t>` will open the file in a new tab
- `<Tab>` will open the file as a preview (keeps the cursor in the tree)
- `gx` opens the file with the `open` command on MACOS and `xdg-open` in linux
- Double left click acts like `<CR>`
- Double right click acts like `.`
- Double right click acts like `<C-]>`
## Note

View File

@ -122,7 +122,7 @@ INFORMATIONS *nvim-tree-info*
- move around like in any vim buffer
- '<CR>' on '..' will cd in the above directory
- typing '.' will cd in the directory under the cursor
- typing '<C-]>' will cd in the directory under the cursor
- type 'a' to add a file
- type 'r' to rename a file
@ -131,14 +131,15 @@ INFORMATIONS *nvim-tree-info*
- if the file is a directory, '<CR>' will open the directory
- otherwise it will open the file in the buffer near the tree
- if the file is a symlink, '<CR>' will follow the symlink
- type '<C-v>' will open the file in a vertical split
- type '<C-x>' will open the file in a horizontal split
- type '<C-t>' will open the file in a new tab
- type 'gx' to open the file with the `open` command on macos and `xdg-open`
- '<C-v>' will open the file in a vertical split
- '<C-x>' will open the file in a horizontal split
- '<C-t>' will open the file in a new tab
- '<Tab>' will open the file as a preview (keeps the cursor in the tree)
- 'gx' opens the file with the `open` command on macos and `xdg-open`
on linux.
- Double left click acts like '<CR>'
- Double right click acts like '.'
- Double right click acts like '<C-]>'
|g:lua_tree_bindings| *g:lua_tree_bindings*
@ -150,7 +151,8 @@ default keybindings will be applied to undefined keys.
\ edit_vsplit: '<c-v>',
\ edit_split: '<c-x>',
\ edit_tab: '<c-t>',
\ cd: '.',
\ cd: '<c-]>',
\ preview: '<Tab>',
\ create: 'a',
\ remove: 'd',
\ rename: 'r'

View File

@ -49,6 +49,7 @@ function M.get_bindings()
edit_vsplit = keybindings.edit_vsplit or '<C-v>',
edit_split = keybindings.edit_split or '<C-x>',
edit_tab = keybindings.edit_tab or '<C-t>',
preview = keybindings.preview or '<Tab>',
cd = keybindings.cd or '<C-]>',
create = keybindings.create or 'a',
remove = keybindings.remove or 'd',

View File

@ -183,7 +183,16 @@ function M.open_file(mode, filename)
else
api.nvim_command('noautocmd wincmd l')
end
if mode == 'preview' then
api.nvim_command(string.format("edit %s", filename))
if vim.g.lua_tree_side == 'right' then
api.nvim_command('noautocmd wincmd l')
else
api.nvim_command('noautocmd wincmd h')
end
else
api.nvim_command(string.format("%s %s", mode, filename))
end
end
function M.change_dir(foldername)
@ -207,6 +216,7 @@ local function set_mappings()
[bindings.create] = 'on_keypress("create")';
[bindings.remove] = 'on_keypress("remove")';
[bindings.rename] = 'on_keypress("rename")';
[bindings.preview] = 'on_keypress("preview")';
gx = "xdg_open()";
}

View File

@ -39,6 +39,11 @@ function M.on_keypress(mode)
return fs.rename(node)
end
if mode == 'preview' then
if node.entries ~= nil or node.name == '..' then return end
return tree.open_file(mode, node.absolute_path)
end
if node.name == ".." then
return tree.change_dir("..")
elseif mode == "cd" and node.entries ~= nil then
@ -49,6 +54,7 @@ function M.on_keypress(mode)
if node.link_to then
local stat = luv.fs_stat(node.link_to)
-- TODO: potentially CD here
if stat.type == 'directory' then return end
tree.open_file(mode, node.link_to)
elseif node.entries ~= nil then