summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-10-20 17:59:38 +0100
committerBram Moolenaar <Bram@vim.org>2022-10-20 17:59:38 +0100
commit49660f5139d3fd55326a54eadf6bb31a3ffec2bf (patch)
treeadc4a0ba93db10b1bd3fe9033bd93826203ab161
parentd0fab10ed2a86698937e3c3fed2f10bd9bb5e731 (diff)
downloadvim-git-49660f5139d3fd55326a54eadf6bb31a3ffec2bf.tar.gz
patch 9.0.0806: 'langmap' works differently when there are modifiersv9.0.0806
Problem: 'langmap' works differently when there are modifiers. Solution: Only apply 'langmap' to a character where modifiers have no effect. (closes #11395, closes #11404)
-rw-r--r--src/getchar.c29
-rw-r--r--src/testdir/test_langmap.vim33
-rw-r--r--src/version.c2
3 files changed, 55 insertions, 9 deletions
diff --git a/src/getchar.c b/src/getchar.c
index 3f83b8484..da8132cbf 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -2590,24 +2590,35 @@ handle_mapping(
{
#ifdef FEAT_LANGMAP
int nomap = nolmaplen;
- int c2;
+ int modifiers = 0;
#endif
// find the match length of this mapping
for (mlen = 1; mlen < typebuf.tb_len; ++mlen)
{
+ int c2 = typebuf.tb_buf[typebuf.tb_off + mlen];
#ifdef FEAT_LANGMAP
- c2 = typebuf.tb_buf[typebuf.tb_off + mlen];
if (nomap > 0)
+ {
+ if (nomap == 2 && c2 == KS_MODIFIER)
+ modifiers = 1;
+ else if (nomap == 1 && modifiers == 1)
+ modifiers = c2;
--nomap;
- else if (c2 == K_SPECIAL)
- nomap = 2;
+ }
else
- LANGMAP_ADJUST(c2, TRUE);
- if (mp->m_keys[mlen] != c2)
-#else
- if (mp->m_keys[mlen] !=
- typebuf.tb_buf[typebuf.tb_off + mlen])
+ {
+ if (c2 == K_SPECIAL)
+ nomap = 2;
+ else if (merge_modifyOtherKeys(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;
+ }
#endif
+ if (mp->m_keys[mlen] != c2)
break;
}
diff --git a/src/testdir/test_langmap.vim b/src/testdir/test_langmap.vim
index 36e2f558c..228470460 100644
--- a/src/testdir/test_langmap.vim
+++ b/src/testdir/test_langmap.vim
@@ -49,6 +49,39 @@ func Test_langmap()
call feedkeys(';', 'tx')
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&
quit!
endfunc
diff --git a/src/version.c b/src/version.c
index 7f72a2c47..3d1feae4e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 806,
+/**/
805,
/**/
804,