YouCompleteMe icon indicating copy to clipboard operation
YouCompleteMe copied to clipboard

Fix the problem of key bindings in finder buffers

Open Shuangcheng-Ni opened this issue 2 years ago • 1 comments

PR Prelude

Thank you for working on YCM! :)

Please complete these steps and check these boxes (by putting an x inside the brackets) before filing your PR:

  • [x] I have read and understood YCM's CONTRIBUTING document.
  • [x] I have read and understood YCM's CODE_OF_CONDUCT document.
  • [x] I have included tests for the changes in my PR. If not, I have included a rationale for why I haven't.
  • [x] I understand my PR may be closed if it becomes obvious I didn't actually perform all of these steps.

Why this change is necessary and useful

As we discussed on gitter, some extra insert-mode key bindings might dismiss the finder buffer. For example, if a user has something like inoremap <BS> <C-r>=auto_pair()<CR> in his/her .vimrc, the finder buffer would immediately disappear after pressing <BS>. This commit fixes the problem. It tries to override all the global mappings with some buffer-local mappings that remap each previously mapped key sequence to itself in the finder buffer, while the previously defined buffer-local mappings in the finder buffer are not overridden.

[Please explain in detail why the changes in this PR are needed.]


This change is Reviewable

Shuangcheng-Ni avatar Jan 30 '23 10:01 Shuangcheng-Ni

The new mappings defined in my additional code are buffer-local mappings and only works in the finder buffer. They do not affect other buffers. They are just used to override the global mappings in the finder buffer and make each key sequence take its original form. Most insert-mode mappings take the form of imap sth. <C-o>:command<CR>, imap sth. <Cmd>command<CR> or imap sth. <C-r>=function()<CR>. All these mappings have the side effect of closing the finder buffer. I think there is no need to preserve them. As you said, it is also a good idea to disable some of the autocmds in augroup YCMPromptFindSymbol. But users will have to quit the prompt buffer by commands like :q then.

augroup YCMPromptFindSymbol
  autocmd!
  autocmd TextChanged,TextChangedI <buffer> call s:OnQueryTextChanged()
  autocmd WinLeave <buffer> call s:Cancel()
  autocmd CmdLineEnter <buffer> call s:Cancel()
augroup END

Shuangcheng-Ni avatar Jan 30 '23 11:01 Shuangcheng-Ni