Skip to content

Commit

Permalink
Add CursorMotionType.Alone
Browse files Browse the repository at this point in the history
  • Loading branch information
tshino committed Apr 1, 2022
1 parent c73c150 commit 85b4dad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
7 changes: 6 additions & 1 deletion src/cursor_motion_detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@ const CursorMotionDetector = function() {
const motion = detectImplicitMotion(document, current, lastSelections);
if (motion) {
// Here, the occurence of this cursor change event is unexpected.
// This type of events includes:
// - cursor movement that happen with snippet insertion related commands
// - cursor movement that happen when the user types in the find input box
// We consider it an implicit cursor motion.
// We notify it so that it will be recorded to be able to playback.
notifyDetectedMotion(CursorMotionType.Trailing, motion);
notifyDetectedMotion(CursorMotionType.Alone, motion);
// console.log('motion without prediction');
} else {
// console.log('skip');
Expand All @@ -207,6 +210,8 @@ const CursorMotionDetector = function() {
const motion = detectImplicitMotion(document, current, predicted);
if (motion) {
// Here, the current cursor position is different from the one predicted.
// This type of events includes:
// - cursor movement happens right after bracket completion
// We consider it an implicit cursor motion.
// We notify it so that it will be recorded to be able to playback.
notifyDetectedMotion(CursorMotionType.Trailing, motion);
Expand Down
3 changes: 2 additions & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ function activate(context) {
addEventListener(
typingDetector.onDetectCursorMotion,
function(type, args) {
if (type === typingDetector.CursorMotionType.Trailing) {
if (type === typingDetector.CursorMotionType.Trailing ||
type === typingDetector.CursorMotionType.Alone) {
keyboardMacro.push({
command: '$moveCursor',
args: args
Expand Down
26 changes: 13 additions & 13 deletions test/suite/cursor_motion_detector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('CursorMotionDetector', () => {
inputs: [
{ changed: [ new vscode.Selection(3, 5, 3, 5) ] }
],
expectedLogs: [[ CursorMotionType.Trailing, MoveLeft(1) ]]
expectedLogs: [[ CursorMotionType.Alone, MoveLeft(1) ]]
});
});
it('should detect the unexpected motion of cursor (move to right)', async () => {
Expand All @@ -283,7 +283,7 @@ describe('CursorMotionDetector', () => {
inputs: [
{ changed: [ new vscode.Selection(3, 7, 3, 7) ] }
],
expectedLogs: [[ CursorMotionType.Trailing, MoveRight(1) ]]
expectedLogs: [[ CursorMotionType.Alone, MoveRight(1) ]]
});
});
it('should detect the unexpected motion of multi-cursor', async () => {
Expand All @@ -292,7 +292,7 @@ describe('CursorMotionDetector', () => {
inputs: [
{ changed: [ new vscode.Selection(3, 7, 3, 7), new vscode.Selection(4, 7, 4, 7) ] }
],
expectedLogs: [[ CursorMotionType.Trailing, MoveRight(1) ]]
expectedLogs: [[ CursorMotionType.Alone, MoveRight(1) ]]
});
});

Expand All @@ -302,7 +302,7 @@ describe('CursorMotionDetector', () => {
inputs: [
{ changed: [ new vscode.Selection(3, 10, 3, 10), new vscode.Selection(3, 12, 3, 12) ] }
],
expectedLogs: [[ CursorMotionType.Trailing, Split([ 3, 5 ]) ]]
expectedLogs: [[ CursorMotionType.Alone, Split([ 3, 5 ]) ]]
});
});
it('should detect implicit motion (split multi to multi)', async () => {
Expand All @@ -317,7 +317,7 @@ describe('CursorMotionDetector', () => {
new vscode.Selection(6, 10, 6, 10), new vscode.Selection(6, 12, 6, 12)
] }
],
expectedLogs: [[ CursorMotionType.Trailing, Split([ 3, 5 ]) ]]
expectedLogs: [[ CursorMotionType.Alone, Split([ 3, 5 ]) ]]
});
});
it('should detect implicit motion (split into multi-cursor on different lines) (1)', async () => {
Expand All @@ -326,7 +326,7 @@ describe('CursorMotionDetector', () => {
inputs: [
{ changed: [ new vscode.Selection(3, 10, 3, 10), new vscode.Selection(5, 2, 5, 2) ] }
],
expectedLogs: [[ CursorMotionType.Trailing, Split2([ 3, 2 ], [0, 2]) ]]
expectedLogs: [[ CursorMotionType.Alone, Split2([ 3, 2 ], [0, 2]) ]]
});
});
it('should detect implicit motion (split into multi-cursor on different lines) (2)', async () => {
Expand All @@ -341,7 +341,7 @@ describe('CursorMotionDetector', () => {
new vscode.Selection(7, 2, 7, 2), new vscode.Selection(8, 7, 8, 7),
] }
],
expectedLogs: [[ CursorMotionType.Trailing, Split2([ 2, 7 ], [ 1, 2 ]) ]]
expectedLogs: [[ CursorMotionType.Alone, Split2([ 2, 7 ], [ 1, 2 ]) ]]
});
});
it('should detect implicit motion (split into multi-cursor with selection)', async () => {
Expand All @@ -350,7 +350,7 @@ describe('CursorMotionDetector', () => {
inputs: [
{ changed: [ new vscode.Selection(3, 10, 3, 13), new vscode.Selection(3, 12, 3, 15) ] }
],
expectedLogs: [[ CursorMotionType.Trailing, SplitSelect([ 3, 5 ], 3) ]]
expectedLogs: [[ CursorMotionType.Alone, SplitSelect([ 3, 5 ], 3) ]]
});
});
it('should ignore implicit motion with splitting to non-uniform selection length', async () => {
Expand All @@ -369,7 +369,7 @@ describe('CursorMotionDetector', () => {
inputs: [
{ changed: [ new vscode.Selection(3, 8, 3, 8), new vscode.Selection(4, 9, 4, 9) ] }
],
expectedLogs: [[ CursorMotionType.Trailing, GroupMotion(2, [1, 9], [0, 1]) ]]
expectedLogs: [[ CursorMotionType.Alone, GroupMotion(2, [1, 9], [0, 1]) ]]
});
});
it('should detect grouped cursor motion (2)', async () => {
Expand All @@ -378,7 +378,7 @@ describe('CursorMotionDetector', () => {
inputs: [
{ changed: [ new vscode.Selection(3, 8, 3, 8), new vscode.Selection(5, 8, 5, 8) ] }
],
expectedLogs: [[ CursorMotionType.Trailing, GroupMotion(2, [1, 8], [0, 2]) ]]
expectedLogs: [[ CursorMotionType.Alone, GroupMotion(2, [1, 8], [0, 2]) ]]
});
});
it('should detect grouped cursor motion (3)', async () => {
Expand All @@ -387,7 +387,7 @@ describe('CursorMotionDetector', () => {
inputs: [
{ changed: [ new vscode.Selection(3, 8, 3, 8) ] }
],
expectedLogs: [[ CursorMotionType.Trailing, GroupMotion(2, 1) ]]
expectedLogs: [[ CursorMotionType.Alone, GroupMotion(2, 1) ]]
});
});
it('should detect grouped cursor motion (4)', async () => {
Expand All @@ -396,7 +396,7 @@ describe('CursorMotionDetector', () => {
inputs: [
{ changed: [ new vscode.Selection(4, 3, 4, 3), new vscode.Selection(6, 3, 6, 3) ] }
],
expectedLogs: [[ CursorMotionType.Trailing, GroupMotion(2, [3, 3], [1, 3]) ]]
expectedLogs: [[ CursorMotionType.Alone, GroupMotion(2, [3, 3], [1, 3]) ]]
});
});
it('should detect grouped cursor motion (5)', async () => {
Expand All @@ -408,7 +408,7 @@ describe('CursorMotionDetector', () => {
new vscode.Selection(6, 10, 6, 10), new vscode.Selection(6, 11, 6, 11) // <= not match non-grouped pure split
] }
],
expectedLogs: [[ CursorMotionType.Trailing, GroupMotion(2, [3, 5, 10, 11], [0, 0, 3, 3]) ]]
expectedLogs: [[ CursorMotionType.Alone, GroupMotion(2, [3, 5, 10, 11], [0, 0, 3, 3]) ]]
});
});
});
Expand Down

0 comments on commit 85b4dad

Please sign in to comment.