mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:9.0.0806: 'langmap' works differently when there are modifiers
Problem: 'langmap' works differently when there are modifiers. Solution: Only apply 'langmap' to a character where modifiers have no effect. (closes vim/vim#11395, closes vim/vim#11404)49660f5139
(cherry picked from commite8877c4d7b
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
32ccb9770b
commit
06c63f50fc
@@ -1959,16 +1959,28 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
|
|||||||
if (mp->m_keys[0] == tb_c1 && (mp->m_mode & local_State)
|
if (mp->m_keys[0] == tb_c1 && (mp->m_mode & local_State)
|
||||||
&& ((mp->m_mode & MODE_LANGMAP) == 0 || typebuf.tb_maplen == 0)) {
|
&& ((mp->m_mode & MODE_LANGMAP) == 0 || typebuf.tb_maplen == 0)) {
|
||||||
int nomap = nolmaplen;
|
int nomap = nolmaplen;
|
||||||
int c2;
|
int modifiers = 0;
|
||||||
// find the match length of this mapping
|
// find the match length of this mapping
|
||||||
for (mlen = 1; mlen < typebuf.tb_len; mlen++) {
|
for (mlen = 1; mlen < typebuf.tb_len; mlen++) {
|
||||||
c2 = typebuf.tb_buf[typebuf.tb_off + mlen];
|
int c2 = typebuf.tb_buf[typebuf.tb_off + mlen];
|
||||||
if (nomap > 0) {
|
if (nomap > 0) {
|
||||||
|
if (nomap == 2 && c2 == KS_MODIFIER) {
|
||||||
|
modifiers = 1;
|
||||||
|
} else if (nomap == 1 && modifiers == 1) {
|
||||||
|
modifiers = c2;
|
||||||
|
}
|
||||||
nomap--;
|
nomap--;
|
||||||
} else if (c2 == K_SPECIAL) {
|
|
||||||
nomap = 2;
|
|
||||||
} else {
|
} else {
|
||||||
LANGMAP_ADJUST(c2, true);
|
if (c2 == K_SPECIAL) {
|
||||||
|
nomap = 2;
|
||||||
|
} else if (merge_modifiers(c2, &modifiers) == c2) {
|
||||||
|
// Only apply 'langmap' if merging modifiers into
|
||||||
|
// the key will not result in another character,
|
||||||
|
// so that 'langmap' behaves consistently in
|
||||||
|
// different terminals and GUIs.
|
||||||
|
LANGMAP_ADJUST(c2, true);
|
||||||
|
}
|
||||||
|
modifiers = 0;
|
||||||
}
|
}
|
||||||
if (mp->m_keys[mlen] != c2) {
|
if (mp->m_keys[mlen] != c2) {
|
||||||
break;
|
break;
|
||||||
|
@@ -49,6 +49,41 @@ func Test_langmap()
|
|||||||
call feedkeys(';', 'tx')
|
call feedkeys(';', 'tx')
|
||||||
call assert_equal(5, col('.'))
|
call assert_equal(5, col('.'))
|
||||||
|
|
||||||
|
set langmap=RL
|
||||||
|
let g:counter = 0
|
||||||
|
nnoremap L;L <Cmd>let g:counter += 1<CR>
|
||||||
|
nnoremap <C-L> <Cmd>throw 'This mapping shoud not be triggered'<CR>
|
||||||
|
|
||||||
|
" 'langmap' is applied to keys without modifiers when matching a mapping
|
||||||
|
call feedkeys('R;R', 'tx')
|
||||||
|
call assert_equal(1, g:counter)
|
||||||
|
nunmap L;L
|
||||||
|
unlet g:counter
|
||||||
|
|
||||||
|
delete
|
||||||
|
call assert_equal('', getline(1))
|
||||||
|
undo
|
||||||
|
call assert_equal('Hello World', getline(1))
|
||||||
|
" 'langmap' does not change Ctrl-R to Ctrl-L for consistency
|
||||||
|
call feedkeys("\<*C-R>", 'tx')
|
||||||
|
call assert_equal('', getline(1))
|
||||||
|
|
||||||
|
set langmap=6L
|
||||||
|
undo
|
||||||
|
setlocal bufhidden=hide
|
||||||
|
let oldbuf = bufnr()
|
||||||
|
enew
|
||||||
|
call assert_notequal(oldbuf, bufnr())
|
||||||
|
" 'langmap' does not change Ctrl-6 to Ctrl-L for consistency
|
||||||
|
" Ctrl-6 becomes Ctrl-^ after merging the Ctrl modifier
|
||||||
|
call feedkeys("\<*C-6>", 'tx')
|
||||||
|
call assert_equal(oldbuf, bufnr())
|
||||||
|
setlocal bufhidden&
|
||||||
|
|
||||||
|
nunmap <C-L>
|
||||||
|
|
||||||
set langmap&
|
set langmap&
|
||||||
quit!
|
quit!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user