update vim.js

This commit is contained in:
nightwing 2014-11-20 20:22:27 +04:00
commit 2f32304c2e
4 changed files with 651 additions and 580 deletions

View file

@ -12,8 +12,8 @@
-->
<link rel="stylesheet" href="demo/kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
<!-- <script async="true" src="https://use.edgefonts.net/source-code-pro.js"></script>
-->
<script async="true" src="https://use.edgefonts.net/source-code-pro.js"></script>
<link href="./doc/site/images/favicon.ico" rel="icon" type="image/x-icon">
</head>
<body>
@ -96,7 +96,6 @@
<select id="keybinding" size="1">
<option value="ace">Ace</option>
<option value="vim">Vim</option>
<option value="vim2">Vim2</option>
<option value="emacs">Emacs</option>
<option value="custom">Custom</option>
</select>

View file

@ -2476,7 +2476,6 @@ var Editor = function(renderer, session) {
**/
this.undo = function() {
this.$blockScrolling++;
this.session.$syncInformUndoManager();
this.session.getUndoManager().undo();
this.$blockScrolling--;
this.renderer.scrollCursorIntoView(null, 0.5);
@ -2488,7 +2487,6 @@ var Editor = function(renderer, session) {
**/
this.redo = function() {
this.$blockScrolling++;
this.session.$syncInformUndoManager();
this.session.getUndoManager().redo();
this.$blockScrolling--;
this.renderer.scrollCursorIntoView(null, 0.5);

File diff suppressed because it is too large Load diff

View file

@ -72,6 +72,9 @@ function test(name, fn) {
exports["test " + name] = fn;
}
vim.CodeMirror.Vim.unmap("Y");
// cm.setBookmark({ch: 5, line: 0})
// cm.setBookmark({ch: 4, line: 0})
@ -985,32 +988,36 @@ testVim('cc_multiply_repeat', function(cm, vim, helpers) {
is(register.linewise);
eq('vim-insert', cm.getOption('keyMap'));
});
testVim('cc_append', function(cm, vim, helpers) {
testVim('cc_should_not_append_to_document', function(cm, vim, helpers) {
var expectedLineCount = cm.lineCount();
cm.setCursor(cm.lastLine(), 0);
helpers.doKeys('c', 'c');
eq(expectedLineCount, cm.lineCount());
});
function fillArray(val, times) {
var arr = [];
for (var i = 0; i < times; i++) {
arr.push(val);
}
return arr;
}
testVim('c_visual_block', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.doKeys('<C-v>', '2', 'j', 'l', 'l', 'l', 'c');
var replacement = new Array(cm.listSelections().length+1).join('hello ').split(' ');
replacement.pop();
var replacement = fillArray('hello', 3);
cm.replaceSelections(replacement);
eq('1hello\n5hello\nahellofg', cm.getValue());
helpers.doKeys('<Esc>');
cm.setCursor(2, 3);
helpers.doKeys('<C-v>', '2', 'k', 'h', 'C');
replacement = new Array(cm.listSelections().length+1).join('world ').split(' ');
replacement.pop();
replacement = fillArray('world', 3);
cm.replaceSelections(replacement);
eq('1hworld\n5hworld\nahworld', cm.getValue());
}, {value: '1234\n5678\nabcdefg'});
testVim('c_visual_block_replay', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.doKeys('<C-v>', '2', 'j', 'l', 'c');
var replacement = new Array(cm.listSelections().length+1).join('fo ').split(' ');
replacement.pop();
var replacement = fillArray('fo', 3);
cm.replaceSelections(replacement);
eq('1fo4\n5fo8\nafodefg', cm.getValue());
helpers.doKeys('<Esc>');
@ -1019,6 +1026,17 @@ testVim('c_visual_block_replay', function(cm, vim, helpers) {
eq('foo4\nfoo8\nfoodefg', cm.getValue());
}, {value: '1234\n5678\nabcdefg'});
testVim('d_visual_block', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.doKeys('<C-v>', '2', 'j', 'l', 'l', 'l', 'd');
eq('1\n5\nafg', cm.getValue());
}, {value: '1234\n5678\nabcdefg'});
testVim('D_visual_block', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.doKeys('<C-v>', '2', 'j', 'l', 'D');
eq('1\n5\na', cm.getValue());
}, {value: '1234\n5678\nabcdefg'});
// 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
@ -1042,7 +1060,7 @@ testVim('g~g~', function(cm, vim, helpers) {
var register = helpers.getRegisterController().getRegister();
eq('', register.toString());
is(!register.linewise);
eqPos({line: curStart.line, ch:0}, cm.getCursor());
eqPos(curStart, cm.getCursor());
}, { value: ' word1\nword2\nword3\nword4\nword5\nword6' });
testVim('gu_and_gU', function(cm, vim, helpers) {
var curStart = makeCursor(0, 7);
@ -1350,7 +1368,7 @@ testVim('a_eol', function(cm, vim, helpers) {
helpers.assertCursorAt(0, lines[0].length);
eq('vim-insert', cm.getOption('keyMap'));
});
testVim('a_endOfSelectedArea', function(cm, vim, helpers) {
testVim('A_endOfSelectedArea', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('v', 'j', 'l');
helpers.doKeys('A');
@ -1813,6 +1831,49 @@ testVim('visual', function(cm, vim, helpers) {
helpers.doKeys('d');
eq('15', cm.getValue());
}, { value: '12345' });
testVim('visual_yank', function(cm, vim, helpers) {
helpers.doKeys('v', '3', 'l', 'y');
helpers.assertCursorAt(0, 0);
helpers.doKeys('p');
eq('aa te test for yank', cm.getValue());
}, { value: 'a test for yank' })
testVim('visual_w', function(cm, vim, helpers) {
helpers.doKeys('v', 'w');
eq(cm.getSelection(), 'motion t');
}, { value: 'motion test'});
testVim('visual_initial_selection', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.doKeys('v');
cm.getSelection('n');
}, { value: 'init'});
testVim('visual_crossover_left', function(cm, vim, helpers) {
cm.setCursor(0, 2);
helpers.doKeys('v', 'l', 'h', 'h');
cm.getSelection('ro');
}, { value: 'cross'});
testVim('visual_crossover_left', function(cm, vim, helpers) {
cm.setCursor(0, 2);
helpers.doKeys('v', 'h', 'l', 'l');
cm.getSelection('os');
}, { value: 'cross'});
testVim('visual_crossover_up', function(cm, vim, helpers) {
cm.setCursor(3, 2);
helpers.doKeys('v', 'j', 'k', 'k');
eqPos(Pos(2, 2), cm.getCursor('head'));
eqPos(Pos(3, 3), cm.getCursor('anchor'));
helpers.doKeys('k');
eqPos(Pos(1, 2), cm.getCursor('head'));
eqPos(Pos(3, 3), cm.getCursor('anchor'));
}, { value: 'cross\ncross\ncross\ncross\ncross\n'});
testVim('visual_crossover_down', function(cm, vim, helpers) {
cm.setCursor(1, 2);
helpers.doKeys('v', 'k', 'j', 'j');
eqPos(Pos(2, 3), cm.getCursor('head'));
eqPos(Pos(1, 2), cm.getCursor('anchor'));
helpers.doKeys('j');
eqPos(Pos(3, 3), cm.getCursor('head'));
eqPos(Pos(1, 2), cm.getCursor('anchor'));
}, { value: 'cross\ncross\ncross\ncross\ncross\n'});
testVim('visual_exit', function(cm, vim, helpers) {
helpers.doKeys('<C-v>', 'l', 'j', 'j', '<Esc>');
eqPos(cm.getCursor('anchor'), cm.getCursor('head'));
@ -1822,20 +1883,23 @@ testVim('visual_line', function(cm, vim, helpers) {
helpers.doKeys('l', 'V', 'l', 'j', 'j', 'd');
eq(' 4\n 5', cm.getValue());
}, { value: ' 1\n 2\n 3\n 4\n 5' });
testVim('visual_block', function(cm, vim, helpers) {
testVim('visual_block_different_line_lengths', function(cm, vim, helpers) {
// test the block selection with lines of different length
// i.e. extending the selection
// till the end of the longest line.
helpers.doKeys('<C-v>', 'l', 'j', 'j', '6', 'l', 'd');
helpers.doKeys('d', 'd', 'd', 'd');
eq('', cm.getValue());
}, {value: '1234\n5678\nabcdefg'});
testVim('visual_block_truncate_on_short_line', function(cm, vim, helpers) {
// check for left side selection in case
// of moving up to a shorter line.
cm.replaceRange('hello world\n{\nthis is\nsparta!', cm.getCursor());
cm.replaceRange('', cm.getCursor());
cm.setCursor(3, 4);
helpers.doKeys('<C-v>', 'l', 'k', 'k', 'd');
eq('hello world\n{\ntis\nsa!', cm.getValue());
cm.replaceRange('12345\n67891\nabcde', {line: 0, ch: 0}, {line: cm.lastLine(), ch: 6});
}, {value: 'hello world\n{\nthis is\nsparta!'});
testVim('visual_block_corners', function(cm, vim, helpers) {
cm.setCursor(1, 2);
helpers.doKeys('<C-v>', '2', 'l', 'k');
// circle around the anchor
@ -1851,6 +1915,8 @@ testVim('visual_block', function(cm, vim, helpers) {
helpers.doKeys('4', 'l');
selections = cm.getSelections();
eq('891cde', selections.join(''));
}, {value: '12345\n67891\nabcde'});
testVim('visual_block_mode_switch', function(cm, vim, helpers) {
// switch between visual modes
cm.setCursor(1, 1);
// blockwise to characterwise visual
@ -1865,7 +1931,7 @@ testVim('visual_block', function(cm, vim, helpers) {
helpers.doKeys('V');
selections = cm.getSelections();
eq('67891\nabcde', selections.join(''));
}, {value: '1234\n5678\nabcdefg'});
}, {value: '12345\n67891\nabcde'});
testVim('visual_block_crossing_short_line', function(cm, vim, helpers) {
// visual block with long and short lines
cm.setCursor(0, 3);
@ -1945,12 +2011,15 @@ testVim('reselect_visual_block', function(cm, vim, helpers) {
helpers.doKeys('<C-v>', 'k', 'h', '<C-v>');
cm.setCursor(2, 1);
helpers.doKeys('v', 'l', 'g', 'v');
helpers.assertCursorAt(0, 1);
eqPos(Pos(1, 2), vim.sel.anchor);
eqPos(Pos(0, 1), vim.sel.head);
// Ensure selection is done with visual block mode rather than one
// continuous range.
eq(cm.getSelections().join(''), '23oo')
helpers.doKeys('g', 'v');
helpers.assertCursorAt(2, 3);
eqPos(Pos(2, 1), vim.sel.anchor);
eqPos(Pos(2, 2), vim.sel.head);
helpers.doKeys('<Esc>');
// Ensure selection of deleted range
cm.setCursor(1, 1);
helpers.doKeys('v', '<C-v>', 'j', 'd', 'g', 'v');
@ -1984,11 +2053,14 @@ testVim('o_visual', function(cm, vim, helpers) {
testVim('o_visual_block', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.doKeys('<C-v>','3','j','l','l', 'o');
helpers.assertCursorAt(0, 1);
eqPos(Pos(3, 3), vim.sel.anchor);
eqPos(Pos(0, 1), vim.sel.head);
helpers.doKeys('O');
helpers.assertCursorAt(0, 4);
eqPos(Pos(3, 1), vim.sel.anchor);
eqPos(Pos(0, 3), vim.sel.head);
helpers.doKeys('o');
helpers.assertCursorAt(3, 1);
eqPos(Pos(0, 3), vim.sel.anchor);
eqPos(Pos(3, 1), vim.sel.head);
}, { value: 'abcd\nefgh\nijkl\nmnop'});
testVim('changeCase_visual', function(cm, vim, helpers) {
cm.setCursor(0, 0);
@ -2023,7 +2095,9 @@ testVim('changeCase_visual_block', function(cm, vim, helpers) {
}, { value: 'abcdef\nghijkl\nmnopq\nfoo'});
testVim('visual_paste', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('v', 'l', 'l', 'y', 'j', 'v', 'l', 'p');
helpers.doKeys('v', 'l', 'l', 'y');
helpers.assertCursorAt(0, 0);
helpers.doKeys('3', 'l', 'j', 'v', 'l', 'p');
helpers.assertCursorAt(1, 5);
eq('this is a\nunithitest for visual paste', cm.getValue());
cm.setCursor(0, 0);