xkblayout: support fcitx5-ui.nvim (#2680)

https://github.com/black-desk/fcitx5-ui.nvim
This commit is contained in:
wzy 2024-06-16 22:57:43 +08:00 committed by GitHub
parent 16c1638f93
commit 02894b6ef4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 9 deletions

View File

@ -440,7 +440,7 @@ function! airline#extensions#load()
call add(s:loaded_ext, 'grepper')
endif
if get(g:, 'airline#extensions#xkblayout#enabled', 1) && (exists('g:XkbSwitchLib') || exists('*FcitxCurrentIM'))
if get(g:, 'airline#extensions#xkblayout#enabled', 1) && (exists('g:XkbSwitchLib') || exists('*FcitxCurrentIM') || has('nvim'))
call airline#extensions#xkblayout#init(s:ext)
call add(s:loaded_ext, 'xkblayout')
endif

View File

@ -3,7 +3,7 @@
scriptencoding utf-8
if !exists('g:XkbSwitchLib') && !exists('*FcitxCurrentIM')
if !exists('g:XkbSwitchLib') && !exists('*FcitxCurrentIM') && !has('nvim')
finish
endif
@ -11,15 +11,21 @@ function! airline#extensions#xkblayout#status()
if exists('g:XkbSwitchLib')
let keyboard_layout = libcall(g:XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '')
let keyboard_layout = get(split(keyboard_layout, '\.'), -1, '')
elseif exists('*FcitxCurrentIMwithRime')
let keyboard_layout = FcitxCurrentIMwithRime()
elseif exists('*FcitxCurrentIM')
let keyboard_layout = FcitxCurrentIM()
elseif has('nvim')
try
let keyboard_layout = luaeval('require"fcitx5-ui".displayCurrentIM()')
catch /.*/
let keyboard_layout = ''
endtry
else
if exists('*FcitxCurrentIMwithRime')
let keyboard_layout = FcitxCurrentIMwithRime()
else
let keyboard_layout = FcitxCurrentIM()
endif
" substitute keyboard-us to us
let keyboard_layout = substitute(keyboard_layout, 'keyboard-', '', 'g')
let keyboard_layout = ''
endif
" substitute keyboard-us to us
let keyboard_layout = substitute(keyboard_layout, 'keyboard-', '', 'g')
let short_codes = get(g:, 'airline#extensions#xkblayout#short_codes', {'2SetKorean': 'KR', 'Chinese': 'CN', 'Japanese': 'JP'})
if has_key(short_codes, keyboard_layout)