diff --git a/doc/carbon.txt b/doc/carbon.txt index 1c3c641..319268a 100644 --- a/doc/carbon.txt +++ b/doc/carbon.txt @@ -299,6 +299,15 @@ PLUGS *carbon-plug This mapping will never exit Neovim completely. See |carbon-carbon-quit| for more technical details. + `------------------------------------------------------------------------------` + (carbon-tabe) *carbon-plug-tabe* + + Implementation: `require('carbon').tabe()` + Mapping: |carbon-setting-actions-tabe| + + If the entry below the cursor is a directory, show that directory in a + Carbon buffer in a new tab. Otherwise the file is opened in a new tab. + `------------------------------------------------------------------------------` (carbon-edit) *carbon-plug-edit* @@ -2100,6 +2109,7 @@ SETTINGS *carbon-setting ` actions = {` ` up = `|carbon-setting-actions-up|`,` ` down = `|carbon-setting-actions-down|`,` + ` tabe = `|carbon-setting-actions-tabe|`,` ` edit = `|carbon-setting-actions-edit|`,` ` reset = `|carbon-setting-actions-reset|`,` ` split = `|carbon-setting-actions-split|`,` @@ -2369,6 +2379,7 @@ SETTINGS *carbon-setting ` up = '[',` *carbon-setting-actions-up* ` down = ']',` *carbon-setting-actions-down* ` quit = 'q',` *carbon-setting-actions-quit* + ` tabe = '',` *carbon-setting-actions-tabe* ` edit = '',` *carbon-setting-actions-edit* ` move = 'm',` *carbon-setting-actions-move* ` reset = 'u',` *carbon-setting-actions-reset* diff --git a/lua/carbon/init.lua b/lua/carbon/init.lua index 100c873..61333de 100644 --- a/lua/carbon/init.lua +++ b/lua/carbon/init.lua @@ -147,6 +147,16 @@ function carbon.toggle_recursive() end) end +function carbon.tabe() + view.execute(function(ctx) + view.handle_sidebar_or_float() + vim.cmd.tabedit({ + ctx.cursor.line.entry.path, + mods = { keepalt = #vim.fn.getreg('#') ~= 0 }, + }) + end) +end + function carbon.edit() view.execute(function(ctx) if ctx.cursor.line.entry.is_directory then diff --git a/lua/carbon/settings.lua b/lua/carbon/settings.lua index f088eee..6958504 100644 --- a/lua/carbon/settings.lua +++ b/lua/carbon/settings.lua @@ -54,6 +54,7 @@ local defaults = { up = '[', down = ']', quit = 'q', + tabe = '', edit = '', move = 'm', reset = 'u', diff --git a/test/specs/carbon_spec.lua b/test/specs/carbon_spec.lua index dbe74a9..7b3a6fa 100644 --- a/test/specs/carbon_spec.lua +++ b/test/specs/carbon_spec.lua @@ -84,6 +84,36 @@ describe('carbon', function() end) end) + describe('tabe', function() + it('opens directories in new tab', function() + assert.equal(#vim.api.nvim_list_tabpages(), 1) + + util.cursor(4, 1) + carbon.tabe() + + assert.equal('carbon.explorer', vim.bo.filetype) + assert.equal(#vim.api.nvim_list_tabpages(), 2) + + vim.cmd.tabclose() + + assert.equal(#vim.api.nvim_list_tabpages(), 1) + end) + + it('opens files in a new tab', function() + assert.equal(#vim.api.nvim_list_tabpages(), 1) + + util.cursor(12, 1) + carbon.tabe() + + assert.equal('toml', vim.bo.filetype) + assert.equal(#vim.api.nvim_list_tabpages(), 2) + + vim.cmd.tabclose() + + assert.equal(#vim.api.nvim_list_tabpages(), 1) + end) + end) + describe('edit', function() it('toggles directory when on directory', function() local doc_entry = helpers.entry('doc')