Skip to content

Commit

Permalink
Added support for N.
Browse files Browse the repository at this point in the history
  • Loading branch information
aioutecism committed Apr 13, 2017
1 parent 42d618f commit ee37359
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/Motions/Paragraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,29 @@ export class MotionParagraph extends Motion {

const document = activeTextEditor.document;

for (let i = 0; i < this.n; i++) {
const result = this.applyOnce(document, from);

from = result.to;

if (result.shouldStop) {
break;
}
}

return from;
}

private applyOnce(
document: TextDocument,
from: Position,
): {
to: Position,
shouldStop: boolean,
} {
let toLine: number | undefined = undefined;
let toCharacter = 0;
let shouldStop = false;

// Skip first group of empty lines if currently on empty line.
let shouldSkip = MotionParagraph.isLineEmpty(document, from.line);
Expand All @@ -66,6 +87,7 @@ export class MotionParagraph extends Motion {
}

if (toLine === undefined) {
shouldStop = true;
toLine = 0;
}
}
Expand All @@ -87,12 +109,16 @@ export class MotionParagraph extends Motion {
}

if (toLine === undefined) {
shouldStop = true;
toLine = document.lineCount - 1;
toCharacter = document.lineAt(toLine).text.length;
}
}

return new Position(toLine, toCharacter);
return {
to: new Position(toLine, toCharacter),
shouldStop: shouldStop,
};
}

private static isLineEmpty(document: TextDocument, line: number): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/Motions/Word.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class MotionWord extends Motion {
return from;
}

applyOnce(
private applyOnce(
document: TextDocument,
from: Position,
matchKind: MotionWordMatchKind,
Expand Down

0 comments on commit ee37359

Please sign in to comment.