Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/open in new tab #134

Merged
merged 3 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/carbon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ PLUGS *carbon-plug
This mapping will never exit Neovim completely. See |carbon-carbon-quit| for
more technical details.

`------------------------------------------------------------------------------`
<Plug>(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.

`------------------------------------------------------------------------------`
<Plug>(carbon-edit) *carbon-plug-edit*

Expand Down Expand Up @@ -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|`,`
Expand Down Expand Up @@ -2369,6 +2379,7 @@ SETTINGS *carbon-setting
` up = '[',` *carbon-setting-actions-up*
` down = ']',` *carbon-setting-actions-down*
` quit = 'q',` *carbon-setting-actions-quit*
` tabe = '<c-t>',` *carbon-setting-actions-tabe*
` edit = '<cr>',` *carbon-setting-actions-edit*
` move = 'm',` *carbon-setting-actions-move*
` reset = 'u',` *carbon-setting-actions-reset*
Expand Down
10 changes: 10 additions & 0 deletions lua/carbon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/carbon/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ local defaults = {
up = '[',
down = ']',
quit = 'q',
tabe = '<c-t>',
edit = '<cr>',
move = 'm',
reset = 'u',
Expand Down
30 changes: 30 additions & 0 deletions test/specs/carbon_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down