mirror of
https://github.com/nvim-treesitter/nvim-treesitter-context
synced 2024-09-16 14:14:03 +02:00
feat: allow passing param depth to go_to_context() (#277)
* feat: allow passing param depth to go_to_context() * doc: update README * fix: remove usage of `vim.iter()` in `go_to_context()`
This commit is contained in:
parent
c9f2b429a1
commit
652ec514d6
2 changed files with 12 additions and 5 deletions
|
@ -242,7 +242,7 @@ hi TreesitterContextBottom gui=underline guisp=Grey
|
|||
|
||||
```lua
|
||||
vim.keymap.set("n", "[c", function()
|
||||
require("treesitter-context").go_to_context()
|
||||
require("treesitter-context").go_to_context(vim.v.count1)
|
||||
end, { silent = true })
|
||||
```
|
||||
|
||||
|
|
|
@ -212,15 +212,22 @@ function M.setup(options)
|
|||
end
|
||||
end
|
||||
|
||||
function M.go_to_context()
|
||||
---@param depth integer? default 1
|
||||
function M.go_to_context(depth)
|
||||
depth = depth or 1
|
||||
local line = api.nvim_win_get_cursor(0)[1]
|
||||
local context = nil
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local contexts = all_contexts[bufnr] or {}
|
||||
|
||||
for _, v in ipairs(contexts) do
|
||||
if v[1] + 1 < line then
|
||||
context = v
|
||||
for idx = #contexts, 1, -1 do
|
||||
local c = contexts[idx]
|
||||
if depth == 0 then
|
||||
break
|
||||
end
|
||||
if c[1] + 1 < line then
|
||||
context = c
|
||||
depth = depth - 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue