[vim] Fix vim-mode-change event being signalled twice

This commit is contained in:
benhormann 2020-05-29 08:07:16 +01:00 committed by GitHub
parent a66f466e33
commit b42ee0965e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -3203,7 +3203,7 @@
vim.visualMode = false;
vim.visualLine = false;
vim.visualBlock = false;
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
if (!vim.insertMode) CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
clearFakeCursor(vim);
}

View File

@ -1153,6 +1153,41 @@ testVim('s_visual_block', function(cm, vim, helpers) {
eq('1hello{\n world\n', cm.getValue());
}, {value: '1234\n5678\nabcdefg\n'});
// Test mode change event. It should only fire once per mode transition.
testVim('on_mode_change', function(cm, vim, helpers) {
var modeHist = [];
function callback(arg) {
var subMode = arg.subMode ? ':' + arg.subMode : '';
modeHist.push(arg.mode + subMode);
}
helpers.doKeys('<Esc>', '<Esc>');
cm.on('vim-mode-change', callback);
function test(key, mode) {
modeHist.length = 0;
helpers.doKeys(key);
eq(modeHist.join(';'), mode);
}
test('v', 'visual');
test('c', 'insert');
test('<Esc>', 'normal');
test('<C-v>', 'visual:blockwise');
test('I', 'insert');
test('<Esc>', 'normal');
test('R', 'replace');
test('x', '');
test('<C-[>', 'normal');
test('v', 'visual');
test('V', 'visual:linewise');
test('<C-v>', 'visual:blockwise');
test('v', 'visual');
test('<C-c>', 'normal');
test('a', 'insert');
test('<Esc>', 'normal');
test('v', 'visual');
test(':', ''); // Event for Command-line mode not implemented.
test('y', 'normal');
});
// Swapcase commands edit in place and do not modify registers.
testVim('g~w_repeat', function(cm, vim, helpers) {
// Assert that dw does delete newline if it should go to the next line, and