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

Implement single char sneak #3999

Merged
merged 7 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/actions/plugins/sneak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class SneakForward extends BaseMovement {
const editor = vscode.window.activeTextEditor!;
const document = editor.document;
const lineCount = document.lineCount;

if (this.keysPressed[2] === '\n') {
// Single key sneak
this.keysPressed[2] = '';
}

const searchString = this.keysPressed[1] + this.keysPressed[2];

for (let i = position.line; i < lineCount; ++i) {
Expand Down Expand Up @@ -82,6 +88,12 @@ class SneakBackward extends BaseMovement {

const editor = vscode.window.activeTextEditor!;
const document = editor.document;

if (this.keysPressed[2] === '\n') {
// Single key sneak
this.keysPressed[2] = '';
}

const searchString = this.keysPressed[1] + this.keysPressed[2];

for (let i = position.line; i >= 0; --i) {
Expand Down
63 changes: 63 additions & 0 deletions test/plugins/sneak.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,67 @@ suite('sneak plugin', () => {
keysPressed: 'Sab,',
end: ['abc abc |abc'],
});

newTest({
JohnnyUrosevic marked this conversation as resolved.
Show resolved Hide resolved
title: 'Can handle single letter s motion',
start: ['|abc abc'],
keysPressed: 'sa\n',
end: ['abc |abc'],
});

newTest({
title: 'Can handle single letter S motion',
start: ['abc |abc'],
keysPressed: 'Sa\n',
end: ['|abc abc'],
});

newTest({
title: 'Can handle single letter <operator>z motion',
start: ['|abc abc'],
keysPressed: 'dza\n',
end: ['|abc'],
});

newTest({
title: 'Can handle single letter <operator>Z motion',
start: ['abc |abc'],
keysPressed: 'dZa\n',
end: ['|abc'],
});

newTest({
title: 'Can handle single letter s; motion',
start: ['|abc abc abc'],
keysPressed: 'sa\n;',
end: ['abc abc |abc'],
});

newTest({
title: 'Can handle single letter s, motion',
start: ['abc abc| abc'],
keysPressed: 'sa\n,',
end: ['abc |abc abc'],
});

newTest({
title: 'Can handle single letter S; motion',
start: ['abc abc |abc'],
keysPressed: 'Sa\n;',
end: ['|abc abc abc'],
});

newTest({
title: 'Can handle single letter S, motion',
start: ['abc abc| abc'],
keysPressed: 'Sa\n,',
end: ['abc abc |abc'],
});

newTest({
title: 'Can handle multiline single char <number>s motion',
start: ['|abc', 'aac', 'abc'],
keysPressed: '3sa\n',
end: ['abc', 'aac', '|abc'],
});
});