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

"cancel" action that is distinct from "hide" #215

Closed
djdv opened this issue Oct 30, 2024 · 4 comments
Closed

"cancel" action that is distinct from "hide" #215

djdv opened this issue Oct 30, 2024 · 4 comments
Labels
feature New feature or request

Comments

@djdv
Copy link

djdv commented Oct 30, 2024

This might make more sense visually: https://youtu.be/AaoAj_5geOw

With auto_insert enabled, if I tab through a selection the text will be inserted automatically into the buffer, and if I hide the selection the text remains.
That seems right to me, but I'd also like an action which cancels the selection and removes the automatically inserted text.
This is especially desirable for multiline snippets.

config
{
	'saghen/blink.cmp',
	lazy = false, -- lazy loading handled internally
	dependencies = 'rafamadriz/friendly-snippets',
	build = 'cargo build --release',
	---@module 'blink.cmp'
	---@type blink.cmp.Config
	opts = {
		keymap = {
			['<Tab>'] = { 'select_next', 'snippet_forward', 'fallback' },
			['<Down>'] = { 'select_next', 'snippet_forward', 'fallback' },

			['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
			['<C-e>'] = { 'hide' },
			['<C-y>'] = { 'select_and_accept' },

			['<CR>'] = { 'accept', 'fallback' },
			['<Space>'] = { 'accept', 'fallback' },

			['<S-Tab>'] = { 'select_prev', 'snippet_backward', 'fallback' },
			['<Up>'] = { 'select_prev', 'snippet_backward', 'fallback' },
			['<C-p>'] = { 'select_prev', 'fallback' },
			['<C-n>'] = { 'select_next', 'fallback' },

			['<C-b>'] = { 'scroll_documentation_up', 'fallback' },
			['<C-f>'] = { 'scroll_documentation_down', 'fallback' },
		},
		windows = {
			autocomplete = {
				border = 'double',
				selection = 'auto_insert'
			},
		},
		documentation = {
			border = 'double'
		},
		signature_help = {
			border = 'double'
		},
		highlight = {
			use_nvim_cmp_as_default = true
		},
		nerd_font_variant = 'mono',
		accept = { auto_brackets = { enabled = true } },
		trigger = { signature_help = { enabled = true } }
	}
}
@Saghen Saghen changed the title request: "cancel" action that is distinct from "hide" "cancel" action that is distinct from "hide" Oct 30, 2024
@Saghen Saghen added the feature New feature or request label Oct 30, 2024
@Shougo
Copy link

Shougo commented Oct 31, 2024

It seems builtin <C-e> feature instead of <C-y>.

@djdv
Copy link
Author

djdv commented Oct 31, 2024

It seems builtin <C-e> feature instead of <C-y>.

with windows = { autocomplete = { selection = 'auto_insert' } } the text is inserted into the buffer without invoking <C-y>.
Pressing <C-e> at this point will hide the popup menu, but the inserted text will remain.

While using hrsh7th/nvim-cmp, I had separate triggers for cmp.close and cmp.abort.

@djdv
Copy link
Author

djdv commented Nov 1, 2024

I realized something related to this. There's some feature/overlap with "abort" and how selection cycling could be handled.

With the default cycle config
windows = { autocomplete = { cycle = { from_bottom = true, from_top = true, } } },
cycling through the popup menu can wrap around the end of the list, back to the first item.

In hrsh7th/nvim-cmp, my config was set up so that wrapping around the list reverted you back to the state you were in pre-selection, but without hiding the popup menu.
That is to say, moving selection to the next item while on the last item, is equivalent to "abort" without closing the menu.

Note that what I type in this video is fmt.Print and that gets restored when I tab past fmt.Println and does not hover me over suggestion 1.
Going through the suggested items in both directions you can see I wrap around to an invisible 0th entry representing the state I was initially in.

tab.cycling.webm

Maybe it's worth filing a separate request for different cycle handling, but in either case, either of these features would solve the issue of getting stuck in the selection menu.
Both of these features seem like they would depend on the same underlying code centered around abort's ability to restore the state.

Saghen added a commit that referenced this issue Nov 24, 2024
@Saghen
Copy link
Owner

Saghen commented Nov 27, 2024

#389 should match the behavior of nvim-cmp for wrapping around and c58b3a8 added a cancel command

@Saghen Saghen closed this as completed Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants