Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug where vim new line creates a permanent thick cursor #5547

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions keymap/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/edit/CodeMirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1668,30 +1668,30 @@ 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
})

// 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
Expand Down
36 changes: 23 additions & 13 deletions test/vim_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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('<Esc>');
helpers.doKeys('.');
eq('xy\nxy\ntestestt', cm.getValue());
helpers.assertCursorAt(1, 1);
helpers.runNextLoop(function() {
helpers.doInsertModeKeys('Backspace');
helpers.doInsertModeKeys('Down');
helpers.doKeys('<Esc>');
helpers.doKeys('.');
eq('xy\nxy\ntestestt', cm.getValue());
helpers.assertCursorAt(1, 1);
});
}, { value: ''});
testVim('._insert_repeat', function(cm, vim, helpers) {
helpers.doKeys('i');
Expand Down