[vim bindings] Skip folded code when moving with j/k

This commit is contained in:
leaf 2019-11-19 19:03:29 +08:00 committed by Marijn Haverbeke
parent 18a8ae2f28
commit ab25dd7582
3 changed files with 39 additions and 5 deletions

View File

@ -1843,6 +1843,12 @@
var line = motionArgs.forward ? cur.line + repeat : cur.line - repeat;
var first = cm.firstLine();
var last = cm.lastLine();
var posV = cm.findPosV(cur, (motionArgs.forward ? repeat : -repeat), 'line', vim.lastHSPos);
var hasMarkedText = motionArgs.forward ? posV.line > line : posV.line < line;
if (hasMarkedText) {
line = posV.line;
endCh = posV.ch;
}
// Vim go to line begin or line end when cursor at first/last line and
// move to previous/next line is triggered.
if (line < first && cur.line == first){

View File

@ -59,10 +59,10 @@
<script src="../mode/dylan/dylan.js"></script>
<style>
.ok {color: #090;}
.fail {color: #e00;}
.error {color: #c90;}
.done {font-weight: bold;}
.ok { color: #090; }
.fail { color: #e00; }
.error { color: #c90; }
.done { font-weight: bold; }
#progress {
background: #45d;
color: white;
@ -152,6 +152,9 @@
<script src="../mode/mscgen/msgenny_test.js"></script>
<script src="../mode/dylan/test.js"></script>
<script src="../addon/mode/multiplex_test.js"></script>
<script src="../addon/fold/foldcode.js"></script>
<script src="../addon/fold/brace-fold.js"></script>
<script src="emacs_test.js"></script>
<script src="sql-hint-test.js"></script>
<script src="sublime_test.js"></script>
@ -182,7 +185,7 @@
if (running) {
quit = true;
setStatus("Restarting tests...", '', true);
setTimeout(function(){runHarness();}, 500);
setTimeout(function(){ runHarness(); }, 500);
return;
}
filters = [];

View File

@ -38,6 +38,8 @@ var bigWordLine = lines[1];
var charLine = lines[2];
var bracesLine = lines[3];
var seekBraceLine = lines[4];
var foldingStart = lines[7];
var foldingEnd = lines[11];
var word1 = {
start: new Pos(wordLine.line, 1),
@ -94,6 +96,14 @@ var seekInside = {
start: new Pos(seekBraceLine.line, 14),
end: new Pos(seekBraceLine.line, 11)
};
var foldingRangeDown = {
start: new Pos(foldingStart.line, 3),
end: new Pos(foldingEnd.line, 0)
};
var foldingRangeUp = {
start: new Pos(foldingEnd.line, 0),
end: new Pos(foldingStart.line, 0)
};
function copyCursor(cur) {
return new Pos(cur.line, cur.ch);
@ -310,6 +320,16 @@ function testMotion(name, keys, endPos, startPos) {
});
}
function testMotionWithFolding(name, keys, endPos, startPos) {
testVim(name, function (cm, vim, helpers) {
cm.foldCode(startPos);
cm.foldCode(endPos);
cm.setCursor(startPos);
helpers.doKeys(keys);
helpers.assertCursorAt(endPos)
})
}
function makeCursor(line, ch) {
return new Pos(line, ch);
}
@ -392,6 +412,11 @@ testMotion('%_squares', ['%'], squares1.end, squares1.start);
testMotion('%_braces', ['%'], curlys1.end, curlys1.start);
testMotion('%_seek_outside', ['%'], seekOutside.end, seekOutside.start);
testMotion('%_seek_inside', ['%'], seekInside.end, seekInside.start);
// Motion with folding tests
testMotionWithFolding('j_with_folding', 'j', foldingRangeDown.end, foldingRangeDown.start);
testMotionWithFolding('k_with_folding', 'k', foldingRangeUp.end, foldingRangeUp.start);
testVim('%_seek_skip', function(cm, vim, helpers) {
cm.setCursor(0,0);
helpers.doKeys(['%']);