diff --git a/keymap/vim.js b/keymap/vim.js index b03c1393cb..2fe1c85dbf 100644 --- a/keymap/vim.js +++ b/keymap/vim.js @@ -2310,7 +2310,13 @@ CodeMirror.signal(cm, "vim-mode-change", {mode: "replace"}); } else { cm.toggleOverwrite(false); - cm.setOption('keyMap', 'vim-insert'); + if (insertAt == 'newLine' && !vimGlobalState.macroModeState.isPlaying) { + //ugly, but this fixed a bug where thick cursor would get permantly stuck + //when (o | O) newLineandinsertMode function was called + setTimeout(cm.setOption.bind(cm, 'keyMap', 'vim-insert'),0); + } else { + cm.setOption('keyMap', 'vim-insert'); + } CodeMirror.signal(cm, "vim-mode-change", {mode: "insert"}); } if (!vimGlobalState.macroModeState.isPlaying) { @@ -2434,7 +2440,7 @@ CodeMirror.commands.newlineAndIndent; newlineFn(cm); } - this.enterInsertMode(cm, { repeat: actionArgs.repeat }, vim); + cm.operation(actions.enterInsertMode.bind(undefined, cm, { repeat: actionArgs.repeat, insertAt: 'newLine' }, vim)); }, paste: function(cm, actionArgs, vim) { var cur = copyCursor(cm.getCursor()); diff --git a/src/edit/CodeMirror.js b/src/edit/CodeMirror.js index 6d3084ff2e..7cadaaac29 100644 --- a/src/edit/CodeMirror.js +++ b/src/edit/CodeMirror.js @@ -29,7 +29,6 @@ import { defaults, optionHandlers, Init } from "./options.js" export function CodeMirror(place, options) { if (!(this instanceof CodeMirror)) return new CodeMirror(place, options) - this.options = options = options ? copyObj(options) : {} // Determine effective options based on given values and defaults. copyObj(defaults, options, false) @@ -98,6 +97,7 @@ export function CodeMirror(place, options) { // The default configuration options. CodeMirror.defaults = defaults + // Functions to run when options are changed. CodeMirror.optionHandlers = optionHandlers diff --git a/test/test.js b/test/test.js index b1044f1f36..f61848373d 100644 --- a/test/test.js +++ b/test/test.js @@ -1668,17 +1668,17 @@ testCM("lineWidgetIssue5486", function(cm) { var el = document.createElement('div') el.style.height='50px' el.textContent = '[[LINE WIDGET]]' - + var lineWidget = cm.addLineWidget(1, el, { above: false, coverGutter: false, noHScroll: false, showIfHidden: false, }) - + var marker = document.createElement('span') marker.textContent = '[--]' - + cm.markText({line:0, ch: 1}, {line:1, ch: 4}, { replacedWith: marker }) @@ -1686,12 +1686,12 @@ testCM("lineWidgetIssue5486", function(cm) { // before resizing the lineWidget, measure 3rd line position var measure_1 = Math.round(cm.charCoords({line:2, ch:0}).top) - + // resize lineWidget, height + 50 px el.style.height='100px' el.textContent += "\nlineWidget size changed.\nTry moving cursor to line 3?" - + lineWidget.changed() // re-measure 3rd line position diff --git a/test/vim_test.js b/test/vim_test.js index d70a46d7c7..3203024f2f 100644 --- a/test/vim_test.js +++ b/test/vim_test.js @@ -187,6 +187,9 @@ function testVim(name, run, opts, expectedFail) { matcher(text); } } + function runNextLoop(f) { + setTimeout(f, 0); + } var helpers = { doKeys: doKeysFn(cm), // Warning: Only emulates keymap events, not character insertions. Use @@ -199,7 +202,8 @@ function testVim(name, run, opts, expectedFail) { fakeOpenNotification: fakeOpenNotification, getRegisterController: function() { return CodeMirror.Vim.getRegisterController(); - } + }, + runNextLoop: runNextLoop } CodeMirror.Vim.resetVimGlobalState_(); var successful = false; @@ -1543,9 +1547,11 @@ testVim('I_visual_block', function(cm, vim, helpers) { testVim('o', function(cm, vim, helpers) { cm.setCursor(0, 4); helpers.doKeys('o'); - eq('word1\n\nword2', cm.getValue()); - helpers.assertCursorAt(1, 0); - eq('vim-insert', cm.getOption('keyMap')); + helpers.runNextLoop(function() { + eq('word1\n\nword2', cm.getValue()); + helpers.assertCursorAt(1, 0); + eq('vim-insert', cm.getOption('keyMap')); + }); }, { value: 'word1\nword2' }); testVim('o_repeat', function(cm, vim, helpers) { cm.setCursor(0, 0); @@ -1558,9 +1564,11 @@ testVim('o_repeat', function(cm, vim, helpers) { testVim('O', function(cm, vim, helpers) { cm.setCursor(0, 4); helpers.doKeys('O'); - eq('\nword1\nword2', cm.getValue()); - helpers.assertCursorAt(0, 0); - eq('vim-insert', cm.getOption('keyMap')); + helpers.runNextLoop(function() { + eq('\nword1\nword2', cm.getValue()); + helpers.assertCursorAt(0, 0); + eq('vim-insert', cm.getOption('keyMap')); + }); }, { value: 'word1\nword2' }); testVim('J', function(cm, vim, helpers) { cm.setCursor(0, 4); @@ -2930,12 +2938,14 @@ testVim('._insert', function(cm, vim, helpers) { helpers.assertCursorAt(0, 6); helpers.doKeys('O'); cm.replaceRange('xyz', cm.getCursor()); - helpers.doInsertModeKeys('Backspace'); - helpers.doInsertModeKeys('Down'); - helpers.doKeys(''); - helpers.doKeys('.'); - eq('xy\nxy\ntestestt', cm.getValue()); - helpers.assertCursorAt(1, 1); + helpers.runNextLoop(function() { + helpers.doInsertModeKeys('Backspace'); + helpers.doInsertModeKeys('Down'); + helpers.doKeys(''); + helpers.doKeys('.'); + eq('xy\nxy\ntestestt', cm.getValue()); + helpers.assertCursorAt(1, 1); + }); }, { value: ''}); testVim('._insert_repeat', function(cm, vim, helpers) { helpers.doKeys('i');