Describe the bug
When popup has filter function set then Ctrl-C is always consumed by popup and cannot be caught inside filter function.
To Reproduce
Detailed steps to reproduce the behavior:
test.vim:function! Filter(id, key) if a:key == "\<C-C>" " <- never reached echo "C-C from popup" endif return v:false endfunction " comment out to see that Filter() is not receiving <C-C>: nnoremap <C-C> <Cmd>echo "C-C from global mapping"<CR> help only call popup_create("hello", #{filter: "Filter"}) " terminal is important to reproduce the problem: term sleep 100
vim --clean -g -S test.vim.Expected behavior
C-C from global mapping.Actual behavior
C-C from global mapping.Environment
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.![]()
If there is a terminal with a job - popup will always get closed by ctrl-c. If there is no job in terminal then my global <C-C> will get executed as expected.
I would like my global <C-C> work even when terminal has a job running. In both cases I would like my popup to ignore <C-C> if there is global mapping for the same keys.
@bfrg According to documentation mapping is true by default. Setting it to true explicitly doesn't make a difference.
The filter gets all keys, no matter whether they were mapped or not.
This doesn't happen for me. For example I cannot handle <C-C> in the filter. Otherwise I could return v:false and let other handlers (terminal or global mappings) process the keys.
When I set 'mapping' to v:true and press <c-c>, Vim will print "C-C from global mapping". It won't work in the terminal window while the job is running since you didn't set tnoremap. And you're right, <c-c> cannot be handled in the popup filter. I don't know why.
Try this:
function Filter(id, key) if a:key == 'q' call popup_close(a:id) return v:true
endif
return v:false
endfunction
nnoremap <C-C> <Cmd>echo "C-C from global mapping"<CR>
tnoremap <C-C> <Cmd>echo "C-C from terminal mapping"<CR> call popup_create('Hello Vim world...', #{filter: 'Filter', filtermode: 'n', mapping: 1, border: []}) terminal
@bfrg according to my report Vim was expected to print "C-C from global mapping" on the second <c-c> invocation, because the focus on the terminal was intentional.
But thanks, adding filtermode: 'n' fixes the original problem. However in my other code I still have a situation that popup swallows <c-c> and gets closed. I'll try to narrow it down and post an update.
Isn't that expected? Ctrl-C is the key to generally cancel/kill all running commands. You can only catch it, if you mapped it previously.
Isn't that expected? Ctrl-C is the key to generally cancel/kill all running commands. You can only catch it, if you mapped it previously.
Correct. If Ctrl-C is mapped - it should be caught by mapping and never by popup. However sometimes Ctrl-C is intercepted by popup that has filter set and never happen if popup doesn't have a filter.
I managed to narrow down the problem and terminal is not needed anymore (@bfrg filtermode: 'n' doesn't help here):
function! Filter(id, key) if a:key == "\<C-C>" " <- never reached echo "C-C from popup" endif return v:false endfunction
nnoremap <C-C> <Cmd>echo "C-C from global mapping"<CR> help only
call popup_create("hello", #{filter: "Filter", filtermode: 'a', mapping: v:true})
To reproduce:
C-C periodically while moving mouse cursor without clicking anything.C-C pressing and moving mouse.C-C - that should not happen, because there is already noremap mapping.And no, that's NOT how I'm using Vim but this is one of the ways I found how to reproduce the problem that I'm facing in my code.
Personally, I’ve created a pop-up where you can select text and press Ctrl+C to copy it, but unfortunately that’s not possible. I think it should be up to the developer of the pop-up plugin to provide another way to close the pop-up; for example, in my case, it’s the Esc key.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()