fix(vim): fix vim tab keybinding fallback. (#763)

release-fix-intellij-update-support-version-range
Zhiming Ma 2023-11-17 13:24:57 +08:00 committed by GitHub
parent adb4bcd13f
commit d47dac9041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -12,11 +12,16 @@ function! tabby#keybindings#Map()
if !empty(mapcheck('<Tab>', 'i'))
" fallback to the original <Tab> mapping
let tab_maparg = maparg('<Tab>', 'i', 0, 1)
" warp as function if rhs is expr, otherwise encode rhs as json
let fallback_rhs = tab_maparg.expr ? '{ -> ' . tab_maparg.rhs . ' }' : substitute(json_encode(tab_maparg.rhs), '<', '\\<', 'g')
" inject <SID>
let fallback_rhs = substitute(fallback_rhs, '<SID>', "\<SNR>" . get(tab_maparg, 'sid') . '_', 'g')
exec 'imap <script><silent><nowait><expr> <Tab> tabby#Accept(' . fallback_rhs . ')'
if toupper(tab_maparg.rhs) == '<NOP>'
" if the original <Tab> mapping is <nop>, no need to fallback
imap <script><silent><nowait><expr> <Tab> tabby#Accept()
else
" warp as function if rhs is expr, otherwise encode rhs as json
let fallback_rhs = tab_maparg.expr ? '{ -> ' . tab_maparg.rhs . ' }' : substitute(json_encode(tab_maparg.rhs), '<', '\\<', 'g')
" inject <SID>
let fallback_rhs = substitute(fallback_rhs, '<SID>', "\<SNR>" . get(tab_maparg, 'sid') . '_', 'g')
exec 'imap ' . (get(tab_maparg, 'script') ? '<script>' : '') . '<silent><nowait><expr> <Tab> tabby#Accept(' . fallback_rhs . ')'
endif
else
" fallback to input \t
imap <script><silent><nowait><expr> <Tab> tabby#Accept("\t")