Skip to content

Commit c6ca1af

Browse files
committed
fix gj clipping at the end of document
1 parent 71919db commit c6ca1af

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

src/vim.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,21 +2443,15 @@ export function initVim(CM) {
24432443
default:
24442444
vim.lastHSPos = cm.charCoords(cur,'div').left;
24452445
}
2446-
var repeat = motionArgs.repeat;
2447-
var res=cm.findPosV(cur,(motionArgs.forward ? repeat : -repeat),'line',vim.lastHSPos);
2448-
if (res.hitSide) {
2449-
if (motionArgs.forward) {
2450-
var lastCharCoords = cm.charCoords(res, 'div');
2451-
var goalCoords = { top: lastCharCoords.top + 8, left: vim.lastHSPos };
2452-
res = cm.coordsChar(goalCoords, 'div');
2453-
} else {
2454-
var resCoords = cm.charCoords(new Pos(cm.firstLine(), 0), 'div');
2455-
resCoords.left = vim.lastHSPos;
2456-
res = cm.coordsChar(resCoords, 'div');
2457-
}
2446+
var repeat = Math.round(motionArgs.repeat);
2447+
for (var i = 0; i < repeat; i++) {
2448+
var res=cm.findPosV(cur,(motionArgs.forward ? 1 : -1),'line',vim.lastHSPos);
2449+
if (res.hitSide) break;
2450+
cur = res;
24582451
}
2459-
vim.lastHPos = res.ch;
2460-
return res;
2452+
if (cur != head)
2453+
vim.lastHPos = cur.ch;
2454+
return cur;
24612455
},
24622456
moveByPage: function(cm, head, motionArgs) {
24632457
// CodeMirror only exposes functions that move the cursor page down, so

test/vim_test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,12 @@ testVim('gj_gk_clipping', function(cm,vim,helpers){
452452
cm.setCursor(0, 1);
453453
helpers.doKeys('g','j','g','j');
454454
helpers.assertCursorAt(2, 1);
455+
helpers.doKeys('g','j');
456+
helpers.assertCursorAt(2, 1);
455457
helpers.doKeys('g','k','g','k');
456458
helpers.assertCursorAt(0, 1);
459+
helpers.doKeys('9','g','j');
460+
helpers.assertCursorAt(2, 1);
457461
},{value: 'line 1\n\nline 2'});
458462
//testing a mix of j/k and gj/gk
459463
testVim('j_k_and_gj_gk', function(cm,vim,helpers){

0 commit comments

Comments
 (0)