Skip to content

Commit

Permalink
docs(readme): add snippet for picking Telescope results
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Lifton <[email protected]>
  • Loading branch information
ggandor and aaronlifton committed Jun 20, 2024
1 parent 2ec33f2 commit eca8108
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,49 @@ vim.keymap.set({'x', 'o'}, '\\', leap_ts)

</details>

<details>
<summary>Shortcuts to Telescope results</summary>

```lua
-- NOTE: If you try to use this before entering any input, an error is thrown.
-- (Help would be appreciated, if someone knows a fix.)
local function get_targets (buf)
local pick = require('telescope.actions.state').get_current_picker(buf)
local scroller = require('telescope.pickers.scroller')
local wininfo = vim.fn.getwininfo(pick.results_win)[1]
local top = math.max(
scroller.top(pick.sorting_strategy, pick.max_results, pick.manager:num_results()),
wininfo.topline - 1
)
local bottom = wininfo.botline - 2 -- skip the current row
local targets = {}
for lnum = bottom, top, -1 do -- start labeling from the closest (bottom) row
table.insert(targets, { wininfo = wininfo, pos = { lnum + 1, 1 }, pick = pick, })
end
return targets
end

local function pick_with_leap (buf)
require('leap').leap {
targets = function () return get_targets(buf) end,
action = function (target)
target.pick:set_selection(target.pos[1] - 1)
require('telescope.actions').select_default(buf)
end,
}
end

require('telescope').setup {
defaults = {
mappings = {
i = { ['<a-p>'] = pick_with_leap },
}
}
}
```

</details>

<details>
<summary>Remote text objects</summary>

Expand Down

0 comments on commit eca8108

Please sign in to comment.