Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gj/gk so it maintains cursor position #3890

Merged
merged 8 commits into from
Sep 27, 2019
Merged
8 changes: 4 additions & 4 deletions src/actions/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ class MoveScreenLineCenter extends MoveByScreenLine {
}

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

@RegisterAction
class MoveDownByScreenLine extends MoveByScreenLine {
class MoveDownByScreenLine extends MoveByScreenLineMaintainDesiredColumn {
modes = [ModeName.Insert, ModeName.Normal, ModeName.Visual];
keys = [['g', 'j'], ['g', '<down>']];
movementType: CursorMovePosition = 'down';
Expand All @@ -783,7 +783,7 @@ class MoveDownByScreenLine extends MoveByScreenLine {
// and moving by screen line just snaps us back to the original position.
// Check PR #1600 for discussion.
@RegisterAction
class MoveUpByScreenLineVisualLine extends MoveByScreenLine {
class MoveUpByScreenLineVisualLine extends MoveByScreenLineMaintainDesiredColumn {
modes = [ModeName.VisualLine];
keys = [['g', 'k'], ['g', '<up>']];
movementType: CursorMovePosition = 'up';
Expand All @@ -792,7 +792,7 @@ class MoveUpByScreenLineVisualLine extends MoveByScreenLine {
}

@RegisterAction
class MoveDownByScreenLineVisualLine extends MoveByScreenLine {
class MoveDownByScreenLineVisualLine extends MoveByScreenLineMaintainDesiredColumn {
modes = [ModeName.VisualLine];
keys = [['g', 'j'], ['g', '<down>']];
movementType: CursorMovePosition = 'down';
Expand Down
16 changes: 16 additions & 0 deletions test/mode/modeVisual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ suite('Mode Visual', () => {
});
});

suite('Screen line motions in Visual Mode', () => {
newTest({
title: "Can handle 'gk'",
start: ['blah', 'duh', '|dur', 'hur'],
keysPressed: 'vgkx',
end: ['blah', '|ur', 'hur'],
});

newTest({
title: "Can handle 'gj'",
start: ['blah', 'duh', '|dur', 'hur'],
keysPressed: 'vgjx',
end: ['blah', 'duh', '|ur'],
});
});

suite('handles aw in visual mode', () => {
newTest({
title: "Can handle 'vawd' on word with cursor inside spaces",
Expand Down
16 changes: 16 additions & 0 deletions test/mode/modeVisualLine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ suite('Mode Visual Line', () => {
});
});

suite('Screen line motions in Visual Line Mode', () => {
newTest({
title: "Can handle 'gk'",
start: ['blah', 'duh', '|dur', 'hur'],
keysPressed: 'Vgkx',
end: ['blah', '|hur'],
});

newTest({
title: "Can handle 'gj'",
start: ['blah', 'duh', '|dur', 'hur'],
keysPressed: 'Vgjx',
end: ['blah', '|duh'],
});
});

suite('Can handle d/c correctly in Visual Line Mode', () => {
newTest({
title: 'Can handle d key',
Expand Down
14 changes: 14 additions & 0 deletions test/mode/normalModeTests/motions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,4 +725,18 @@ suite('Motions in Normal Mode', () => {
keysPressed: '<right>',
end: ['blah', 'duh', 'd|ur', 'hur'],
});

newTest({
title: "Can handle 'gk'",
start: ['blah', 'duh', '|dur', 'hur'],
keysPressed: 'gk',
end: ['blah', '|duh', 'dur', 'hur'],
});

newTest({
title: "Can handle 'gj'",
start: ['blah', 'duh', '|dur', 'hur'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests don't seem like they exhibit the bug in #1323 (since the cursor is at the front of the line each time). Am I wrong? If not, we should have some regression tests.

keysPressed: 'gj',
end: ['blah', 'duh', 'dur', '|hur'],
});
});