Skip to content

Commit b7e2404

Browse files
feat: scroll_signature_up/down keymap commands (#2057)
* add signature scrolling * docs: signature scrolling --------- Co-authored-by: Liam Dyer <[email protected]>
1 parent a0bcede commit b7e2404

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

doc/configuration/keymap.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ keymap = {
7070
- Optionally use `function(cmp) cmp.scroll_documentation_down(4) end` to scroll by a specific number of lines
7171
- `show_signature`: Shows the signature help window
7272
- `hide_signature`: Hides the signature help window
73+
- `scroll_signature_up`: Scrolls the signature help window up by 4 lines
74+
- Optionally use `function(cmp) cmp.scroll_signature_up(4) end` to scroll by a specific number of lines
75+
- `scroll_signature_down`: Scrolls the signature help window down by 4 lines
76+
- Optionally use `function(cmp) cmp.scroll_signature_down(4) end` to scroll by a specific number of lines
7377
- `snippet_forward`: Jumps to the next snippet placeholder
7478
- `snippet_backward`: Jumps to the previous snippet placeholder
7579
- `fallback`: Runs the next non-blink keymap, or runs the built-in neovim binding

doc/configuration/signature.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: Signature
77
This feature is _experimental_, [contributions welcome](https://github.com/Saghen/blink.cmp/issues/1071)!
88
:::
99

10-
Blink supports signature help, automatically triggered when typing trigger characters, defined by the LSP, such as `(` for `lua`. The menu will be updated when pressing a retrigger character, such as `,`. Due to it being experimental, this feature is opt-in.
10+
Blink supports signature help by manually pressing `<C-k>` (by default) or automatically triggered when typing trigger characters, defined by the LSP, such as `(` for `lua`. The menu will be updated when pressing a retrigger character, such as `,`. Due to it being experimental, this feature is opt-in.
1111

1212
```lua
1313
signature = { enabled = true }
@@ -16,3 +16,17 @@ signature = { enabled = true }
1616
<img src="https://github.com/user-attachments/assets/9ab576c8-2a04-465f-88c0-9c130fef146c" />
1717

1818
You may want to set `signature.window.show_documentation = false` to only show the signature, and not the documentation.
19+
20+
## Keymap
21+
22+
See the [keymap documentation](../modes/cmdline.md#keymap) for a full list of commands. By default, the `scroll_signature_up` and `scroll_signature_down` commands are not bound to any keys. You may bind them like so:
23+
24+
```lua
25+
keymap = {
26+
['<C-u>'] = { 'scroll_signature_up', 'fallback' },
27+
['<C-d>'] = { 'scroll_signature_down', 'fallback' },
28+
29+
-- default in all keymap presets
30+
['<C-k>'] = { 'show_signature', 'hide_signature', 'fallback' },
31+
}
32+
```

lua/blink/cmp/config/keymap.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
--- | 'scroll_documentation_down' Scroll the documentation window down
2121
--- | 'show_signature' Show the signature help window
2222
--- | 'hide_signature' Hide the signature help window
23+
--- | 'scroll_signature_up' Scroll the signature window up
24+
--- | 'scroll_signature_down' Scroll the signature window down
2325
--- | 'snippet_forward' Move the cursor forward to the next snippet placeholder
2426
--- | 'snippet_backward' Move the cursor backward to the previous snippet placeholder
2527
--- | (fun(cmp: blink.cmp.API): boolean?) Custom function where returning true will prevent the next command from running
@@ -185,6 +187,8 @@ function keymap.validate(config, is_mode)
185187
'scroll_documentation_down',
186188
'show_signature',
187189
'hide_signature',
190+
'scroll_signature_up',
191+
'scroll_signature_down',
188192
'snippet_forward',
189193
'snippet_backward',
190194
}

lua/blink/cmp/init.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,26 @@ function cmp.hide_signature()
305305
return true
306306
end
307307

308+
--- Scroll the documentation window up
309+
--- @param count? number
310+
function cmp.scroll_signature_up(count)
311+
local sig = require('blink.cmp.signature.window')
312+
if not sig.win:is_open() then return end
313+
314+
vim.schedule(function() sig.scroll_up(count or 4) end)
315+
return true
316+
end
317+
318+
--- Scroll the documentation window down
319+
--- @param count? number
320+
function cmp.scroll_signature_down(count)
321+
local sig = require('blink.cmp.signature.window')
322+
if not sig.win:is_open() then return end
323+
324+
vim.schedule(function() sig.scroll_down(count or 4) end)
325+
return true
326+
end
327+
308328
--- Check if a snippet is active, optionally filtering by direction
309329
--- @param filter? { direction?: number }
310330
function cmp.snippet_active(filter) return require('blink.cmp.config').snippets.active(filter) end

lua/blink/cmp/signature/window.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function signature.open_with_signature_help(context, signature_help)
8888

8989
signature.win:open()
9090
signature.update_position()
91+
signature.scroll_up(1)
9192
end
9293

9394
function signature.close()
@@ -100,7 +101,7 @@ function signature.scroll_up(amount)
100101
local top_line = math.max(1, vim.fn.line('w0', winnr) - 1)
101102
local desired_line = math.max(1, top_line - amount)
102103

103-
vim.api.nvim_win_set_cursor(signature.win:get_win(), { desired_line, 0 })
104+
signature.win:set_cursor({ desired_line, 0 })
104105
end
105106

106107
function signature.scroll_down(amount)
@@ -109,7 +110,7 @@ function signature.scroll_down(amount)
109110
local bottom_line = math.max(1, vim.fn.line('w$', winnr) + 1)
110111
local desired_line = math.min(line_count, bottom_line + amount)
111112

112-
vim.api.nvim_win_set_cursor(signature.win:get_win(), { desired_line, 0 })
113+
signature.win:set_cursor({ desired_line, 0 })
113114
end
114115

115116
function signature.update_position()

0 commit comments

Comments
 (0)