Skip to content

Commit c912733

Browse files
authored
fix gj clipping at the end of document (#258)
1 parent d19062a commit c912733

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
@@ -2451,21 +2451,15 @@ export function initVim(CM) {
24512451
default:
24522452
vim.lastHSPos = cm.charCoords(cur,'div').left;
24532453
}
2454-
var repeat = motionArgs.repeat;
2455-
var res=cm.findPosV(cur,(motionArgs.forward ? repeat : -repeat),'line',vim.lastHSPos);
2456-
if (res.hitSide) {
2457-
if (motionArgs.forward) {
2458-
var lastCharCoords = cm.charCoords(res, 'div');
2459-
var goalCoords = { top: lastCharCoords.top + 8, left: vim.lastHSPos };
2460-
res = cm.coordsChar(goalCoords, 'div');
2461-
} else {
2462-
var resCoords = cm.charCoords(new Pos(cm.firstLine(), 0), 'div');
2463-
resCoords.left = vim.lastHSPos;
2464-
res = cm.coordsChar(resCoords, 'div');
2465-
}
2454+
var repeat = Math.round(motionArgs.repeat);
2455+
for (var i = 0; i < repeat; i++) {
2456+
var res=cm.findPosV(cur,(motionArgs.forward ? 1 : -1),'line',vim.lastHSPos);
2457+
if (res.hitSide) break;
2458+
cur = res;
24662459
}
2467-
vim.lastHPos = res.ch;
2468-
return res;
2460+
if (cur != head)
2461+
vim.lastHPos = cur.ch;
2462+
return cur;
24692463
},
24702464
moveByPage: function(cm, head, motionArgs) {
24712465
// 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)