diff --git a/keymap/vim.js b/keymap/vim.js index 50b1c554f5d3c9847e82a5d042f62b22e6e29859..a4cfd5796559f171c1eae7d08cd4fd263a5280c9 100644 --- a/keymap/vim.js +++ b/keymap/vim.js @@ -1862,10 +1862,15 @@ // including the trailing \n, include the \n before the starting line if (operatorArgs.linewise && curEnd.line == cm.lastLine() && curStart.line == curEnd.line) { - var tmp = copyCursor(curEnd); - curStart.line--; - curStart.ch = lineLength(cm, curStart.line); - curEnd = tmp; + if (curEnd.line == 0) { + curStart.ch = 0; + } + else { + var tmp = copyCursor(curEnd); + curStart.line--; + curStart.ch = lineLength(cm, curStart.line); + curEnd = tmp; + } cm.replaceRange('', curStart, curEnd); } else { cm.replaceSelections(replacement); diff --git a/test/vim_test.js b/test/vim_test.js index 1a5d0f5d60ac670dd20a6a7ec349cf967aa3d9e3..7d5e5a148e239ec3146cf215095ba1b38ede740c 100644 --- a/test/vim_test.js +++ b/test/vim_test.js @@ -828,6 +828,15 @@ testVim('dd_lastline', function(cm, vim, helpers) { eq(expectedLineCount, cm.lineCount()); helpers.assertCursorAt(cm.lineCount() - 1, 0); }); +testVim('dd_only_line', function(cm, vim, helpers) { + cm.setCursor(0, 0); + var expectedRegister = cm.getValue() + "\n"; + helpers.doKeys('d','d'); + eq(1, cm.lineCount()); + eq('', cm.getValue()); + var register = helpers.getRegisterController().getRegister(); + eq(expectedRegister, register.toString()); +}, { value: "thisistheonlyline" }); // Yank commands should behave the exact same as d commands, expect that nothing // gets deleted. testVim('yw_repeat', function(cm, vim, helpers) {