lyokha / vim-xkbswitch

vim plugin for automatic keyboard layout switching in insert mode
MIT License
481 stars 23 forks source link

xkb-switch triggered by neoclide Coc documentation float window #46

Closed evoludigit closed 3 years ago

evoludigit commented 3 years ago

Hello,

thank you for your amazing plugin. It has solved elegantly a problem that I had since I have started to learn to use Vim with qwerty keyboard, but typing with french bépo layout.

I have one question : in insert mode, layout switches from my locale (fr(bepo) in my case) to us layout, when a documentation float window is triggered by Neoclide Coc Intellisense-like plugin.

cfv https://github.com/neoclide/coc.nvim, and screen captures on https://www.reddit.com/r/neovim/comments/b1pctc/float_window_support_with_cocnvim/ to see how it looks like.

It sticks to us layout after the float window disappear, so I end up typing in qwerty instead of bépo whenever I hit some autocompletion trigger.

Is there a known workaround ?

this is an excerpt of a vim log, but feel free to close issue if appropriate as is really a borderline case.

chdir(/home/evoludigit/code/project)
Executing InsertEnter Autocommands for "*"
autocommand let s:XkbSwitchLastIEnterBufnr = bufnr('%') | call <SID>xkb_switch(1)

Executing InsertEnter Autocommands for "*"
autocommand call s:Autocmd('InsertEnter', +expand('<abuf>'))

Executing InsertEnter Autocommands for "*"
autocommand match ExtraWhitespace /\s\+\%#\@<!$/    
-- INSERT --
Executing CursorMovedI Autocommands for "*"
autocommand call s:Autocmd('CursorMovedI', +expand('<abuf>'), [line('.'), col('.')])

Executing CursorMovedI Autocommands for "*"
autocommand call s:Highlight_Matching_Pair()

Executing CursorMovedI Autocommands for "<buffer=1>"
autocommand call SemshiCursorMoved(line('w0'), line('w$'))

Executing User Autocommands for "AirlineModeChanged"
autocommand call airline#mode_changed()

chdir(/home/evoludigit/code/project)
chdir(tests/entrypoints)
chdir(/home/evoludigit/code/project)
chdir(/home/evoludigit/code/project)
chdir(tests/entrypoints)
chdir(/home/evoludigit/code/project)
chdir(/home/evoludigit/code/project)
chdir(tests/entrypoints)
chdir(/home/evoludigit/code/project)
chdir(/home/evoludigit/code/project)
Executing CursorHoldI Autocommands for "*"
autocommand call s:Autocmd('CursorHoldI', +expand('<abuf>'))

chdir(/home/evoludigit/code/project)
chdir(tests/entrypoints)
chdir(/home/evoludigit/code/project)
chdir(/home/evoludigit/code/project)
chdir(tests/entrypoints)
chdir(/home/evoludigit/code/project)
Executing InsertCharPre Autocommands for "*"
autocommand call s:Autocmd('InsertCharPre', v:char)

airline: group: airline_error already done, skipping
airline: group: airline_error_bold already done, skipping
airline: group: airline_error_red already done, skipping
airline: group: airline_warning already done, skipping
airline: group: airline_warning_bold already done, skipping
airline: group: airline_warning_red already done, skipping
airline: group: airline_c already done, skipping
airline: group: airline_c_bold already done, skipping
airline: group: airline_c_red already done, skipping
airline: group: airline_term already done, skipping
airline: group: airline_term_bold already done, skipping
airline: group: airline_term_red already done, skipping
Executing User Autocommands for "AirlineModeChanged"
autocommand call airline#mode_changed()

chdir(/home/evoludigit/code/project)
chdir(tests/entrypoints)
chdir(/home/evoludigit/code/project)
chdir(/home/evoludigit/code/project)
chdir(tests/entrypoints)
chdir(/home/evoludigit/code/project)-- INSERT --
Executing CursorMovedI Autocommands for "*"
autocommand call s:Autocmd('CursorMovedI', +expand('<abuf>'), [line('.'), col('.')])

Executing CursorMovedI Autocommands for "*"
autocommand call s:Highlight_Matching_Pair()

Executing CursorMovedI Autocommands for "<buffer=1>"
autocommand call SemshiCursorMoved(line('w0'), line('w$'))

Executing TextChangedI Autocommands for "*"
autocommand call s:Autocmd('TextChangedI', +expand('<abuf>'), {'lnum': line('.'), 'col': col('.'), 'pre': strpart(getline('.'), 0, col('.') - 1), 'changedtick': b:changedtick})

Executing TextChangedI Autocommands for "*"
autocommand call s:Highlight_Matching_Pair()

Executing TextChangedI Autocommands for "<buffer=1>"
autocommand call SemshiTextChanged()

Executing FuncUndefined Autocommands for "SemshiTextChanged"
autocommand call remote#define#FunctionBootstrap("python3", "/home/evoludigit/.config/nvim/plugged/semshi/rplugin/python3/semshi:function:SemshiTextChanged", v:false, "SemshiTextChanged", {}, "RPC_DEFINE_AUTOCMD_GROUP_6")
lyokha commented 3 years ago

Hi, thank you for your kind words!

I never used Neovim and got familiar with the floating window notion just now. It seems that it has some specific lower-level optimizations that skip triggering BufEnter/InsertEnter events when returning to the original window. It could be fixed with checking a filetype inside g:XkbSwitchSkipFt, but Coc does not provide specific filetypes. However, it looks that this floating windows do have a special parameter that can be hooked: they have window variable float. So I made a new list g:XkbSwitchSkipWinVar with default value ['float'] to let the xkbswitch plugin skip setting layouts on entering such windows.

Please try this fix (you only need to pull the latest version), however I am not very sure that it will work.

evoludigit commented 3 years ago

Hello,

thank you so much ! It works great, you’ve made my day :+1: