Skip to content

Commit

Permalink
Fixes gj/gk behaviour on wrapped lines; closes VSCodeVim#4120
Browse files Browse the repository at this point in the history
This more or less reverts the functionality introduced by commit
4b2e079 and raised in issue VSCodeVim#3890.

Unfortunately it is not currently possible to fully implement display
line movements over wrapped lines that will always preserve cursor
position. One of two things is necessary to change this, either the
VSCode API needs to be extended to return information about wrapped
lines (but this was rejected in issue microsoft/vscode#23045).
Alternatively VSCodeVim would need to reïimplement all motions using
vscode.commands.executeCommand() commands rather than manipulating
vscode.window.activeTextEditor.selections directly, as the former
preserves column position while the latter does not. However it's not
clear to me if all VIM beahviour could be reïmplemented this way without
first trying this out and sounds like a bit of a ground up rewrite.

It seems for now we're stuck with gj/gk not preserving column position
when jumping across short lines.
  • Loading branch information
hetmankp committed Oct 3, 2019
1 parent 4a8ac72 commit 00f69b2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 30 deletions.
17 changes: 15 additions & 2 deletions src/actions/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ abstract class MoveByScreenLineMaintainDesiredColumn extends MoveByScreenLine {
}
}

class MoveDownByScreenLineMaintainDesiredColumn extends MoveByScreenLineMaintainDesiredColumn {
movementType: CursorMovePosition = 'down';
by: CursorMoveByUnit = 'wrappedLine';
value = 1;
}


class MoveUpByScreenLineMaintainDesiredColumn extends MoveByScreenLineMaintainDesiredColumn {
movementType: CursorMovePosition = 'up';
by: CursorMoveByUnit = 'wrappedLine';
value = 1;
}

class MoveDownFoldFix extends MoveByScreenLineMaintainDesiredColumn {
movementType: CursorMovePosition = 'down';
by: CursorMoveByUnit = 'line';
Expand Down Expand Up @@ -785,7 +798,7 @@ class MoveScreenLineCenter extends MoveByScreenLine {
}

@RegisterAction
export class MoveUpByScreenLineMaintainDesiredColumn extends MoveByScreenLineMaintainDesiredColumn {
export class MoveUpByDisplayLine extends MoveByScreenLine {
modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual];
keys = [['g', 'k'], ['g', '<up>']];
movementType: CursorMovePosition = 'up';
Expand All @@ -794,7 +807,7 @@ export class MoveUpByScreenLineMaintainDesiredColumn extends MoveByScreenLineMai
}

@RegisterAction
class MoveDownByScreenLineMaintainDesiredColumn extends MoveByScreenLineMaintainDesiredColumn {
class MoveDownByDisplayLine extends MoveByScreenLine {
modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual];
keys = [['g', 'j'], ['g', '<down>']];
movementType: CursorMovePosition = 'down';
Expand Down
14 changes: 0 additions & 14 deletions test/mode/modeVisual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,6 @@ suite('Mode Visual', () => {
keysPressed: 'vgjx',
end: ['blah', 'duh', '|ur'],
});

newTest({
title: "Preserves cursor position when handling 'gk'",
start: ['blah', 'word', 'a', 'la|st'],
keysPressed: 'vgkgkx',
end: ['blah', 'wo|t'],
});

newTest({
title: "Preserves cursor position when handling 'gj'",
start: ['blah', 'wo|rd', 'a', 'last'],
keysPressed: 'vgjgjx',
end: ['blah', 'wo|t'],
});
});

suite('handles aw in visual mode', () => {
Expand Down
14 changes: 0 additions & 14 deletions test/mode/normalModeTests/motions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,18 +739,4 @@ suite('Motions in Normal Mode', () => {
keysPressed: 'gj',
end: ['blah', 'duh', 'dur', '|hur'],
});

newTest({
title: "Preserves cursor position when handling 'gk'",
start: ['blah', 'duh', 'a', 'hu|r '],
keysPressed: 'gkgk',
end: ['blah', 'du|h', 'a', 'hur '],
});

newTest({
title: "Preserves cursor position when handling 'gj'",
start: ['blah', 'du|h', 'a', 'hur '],
keysPressed: 'gjgj',
end: ['blah', 'duh', 'a', 'hu|r '],
});
});

0 comments on commit 00f69b2

Please sign in to comment.