Skip to content

Commit

Permalink
Implement new tab behavior for the file browser (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
asoderman authored Sep 30, 2024
1 parent 823267c commit f3a4a1c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lua/distant/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ local DEFAULT_SETTINGS = {
--- Keymap to edit the file or directory under the cursor.
--- @type distant.plugin.settings.Keymap
edit = '<Return>',
-- Keymap to open the file or directory under the cursor in a new tab.
-- @type distant.plugin.settings.Keymap
tabedit = '<C-t>',
--- Keymap to display metadata for the file or directory under the cursor.
--- @type distant.plugin.settings.Keymap
metadata = 'M',
Expand Down
6 changes: 6 additions & 0 deletions lua/distant/editor/open/configurator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function M.configure(opts)
mapper.apply_mappings(bufnr, {
[keymap.copy] = nav.actions.copy,
[keymap.edit] = nav.actions.edit,
[keymap.tabedit] = nav.actions.tabedit,
[keymap.metadata] = nav.actions.metadata,
[keymap.newdir] = nav.actions.mkdir,
[keymap.newfile] = nav.actions.newfile,
Expand Down Expand Up @@ -154,6 +155,11 @@ function M.configure(opts)

-- Display the buffer in the specified window, defaulting to current
if not opts.no_focus then
if winnr == -1 then
-- TODO: At time of implementation there does not seem to be a lua API to create a new tabpage
vim.api.nvim_command('tabedit')
winnr = 0
end
vim.api.nvim_win_set_buf(winnr, bufnr)
end

Expand Down
8 changes: 8 additions & 0 deletions lua/distant/nav/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ M.edit = function(opts)
end
end

M.tabedit = function(opts)
opts = opts or {}
opts.bufnr = nil
opts.winnr = -1

M.edit(opts)
end

--- Displays metadata for the path under the cursor.
M.metadata = function()
local client_id = plugin.buf.client_id()
Expand Down

0 comments on commit f3a4a1c

Please sign in to comment.