Skip to content
Closed
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ Install with your favorite manager. With [lazy.nvim](https://github.com/folke/la
mode = { "n", "x" },
desc = "Sidekick Select Prompt",
},
-- Example of a keybinding to move cursor to left window
{
"<c-h>",
function() require("sidekick.cli").term_nav("h") end,
mode = { "t" },
desc = "Go to Left Window",
},
-- Example of a keybinding to open Claude directly
{
"<leader>ac",
Expand Down
11 changes: 11 additions & 0 deletions lua/sidekick/cli/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ function M.focus(opts)
})
end

--- Toggle focus of the terminal window directionally
---@param dir string The direction to navigate (h, j, k, l)
---@param opts? sidekick.cli.Show
---@overload fun(dir: string, name: string)
function M.term_nav(dir, opts)
opts = type(opts) == "string" and { name = opts } or opts or {}
M.with(function(t)
t:term_nav(dir)
end, { filter = { name = opts.name }, create = true })
end

---@param opts? sidekick.cli.Hide
---@overload fun(name: string)
function M.hide(opts)
Expand Down
20 changes: 15 additions & 5 deletions lua/sidekick/cli/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ function M:win_valid()
return self.win and vim.api.nvim_win_is_valid(self.win)
end

function M:is_floating()
return self.opts.layout == "float"
end

function M:start()
if self:is_running() then
return
Expand Down Expand Up @@ -277,19 +281,17 @@ function M:open_win()
return
end

local is_float = self.opts.layout == "float"

---@type vim.api.keyset.win_config
local opts = vim.tbl_extend(
"force",
vim.deepcopy(is_float and win_opts.float or win_opts.split),
vim.deepcopy(is_float and self.opts.float or self.opts.split)
vim.deepcopy(self:is_floating() and win_opts.float or win_opts.split),
vim.deepcopy(self:is_floating() and self.opts.float or self.opts.split)
)

opts.width = opts.width <= 1 and math.floor(vim.o.columns * opts.width) or opts.width
opts.height = opts.height <= 1 and math.floor(vim.o.lines * opts.height) or opts.height

if is_float then
if self:is_floating() then
opts.row = opts.row <= 1 and math.floor((vim.o.lines - (opts.height or 0)) * opts.row) or opts.row
opts.col = opts.col <= 1 and math.floor((vim.o.columns - (opts.width or 0)) * opts.col) or opts.col
else
Expand All @@ -311,6 +313,14 @@ function M:open_win()
end
end

function M:term_nav(dir)
if not self:is_focused() or self:is_floating() then
return
end
vim.cmd.wincmd(dir)
vim.cmd.stopinsert()
end

function M:focus()
self:show()
if not self:is_running() then
Expand Down
18 changes: 0 additions & 18 deletions tests/textobject_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -441,24 +441,6 @@ describe("textobject context", function()
-- assert.is_not_nil(result)
-- end)

it("works with go", function()
if not has_parser("go") then
pending("Go parser not available")
return
end

vim.bo[buf].filetype = "go"
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {
"func Add(a, b int) int {",
" return a + b",
"}",
})
vim.api.nvim_win_set_cursor(win, { 2, 4 })

local ctx = Context.ctx()
local result = TextObject.get(ctx, { type = "function" })

assert.is_not_nil(result)
end)
end)
end)