Skip to content

Commit

Permalink
Address PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfn committed Jan 30, 2016
1 parent 1cb53f3 commit 0825461
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/motion/position.ts
Expand Up @@ -48,6 +48,9 @@ export class Position extends vscode.Position {
return this;
}

/**
* Get the position of the line directly below the current line.
*/
public getDown(desiredColumn: number) : Position {
if (this.getDocumentEnd().line !== this.line) {
let nextLine = this.line + 1;
Expand All @@ -59,6 +62,9 @@ export class Position extends vscode.Position {
return this;
}

/**
* Get the position of the line directly above the current line.
*/
public getUp(desiredColumn: number) : Position {
if (this.getDocumentBegin().line !== this.line) {
let prevLine = this.line - 1;
Expand Down Expand Up @@ -165,38 +171,38 @@ export class Position extends vscode.Position {
* do the above.
*/
public getCurrentParagraphEnd(): Position {
let pos = this.translate(0);
let pos: Position = this;

while (TextEditor.getLineAt(pos).text === "" && !TextEditor.isLastLine(pos)) {
pos = pos.translate(1);
pos = pos.getDown(0);
}

for (pos; pos.line < TextEditor.getLineCount() - 1; pos = pos.translate(1)) {
for (pos; pos.line < TextEditor.getLineCount() - 1; pos = pos.getDown(0)) {
if (TextEditor.getLineAt(pos).text === "") {
break;
}
}

return new Position(pos.line, 0, this.positionOptions).getLineEnd();
return pos.getLineEnd();
}

/**
* The same as getCurrentParagraphEnd, but in reverse.
*/
public getCurrentParagraphBeginning(): Position {
let pos = this.translate(0);
let pos: Position = this;

while (TextEditor.getLineAt(pos).text === "" && !TextEditor.isFirstLine(pos)) {
pos = pos.translate(-1);
pos = pos.getUp(0);
}

for (pos; pos.line > 0; pos = pos.translate(-1)) {
for (pos; pos.line > 0; pos = pos.getUp(0)) {
if (TextEditor.getLineAt(pos).text === "") {
break;
}
}

return new Position(pos.line, 0, this.positionOptions).getLineBegin();
return pos.getLineBegin();
}

public getLineBegin() : Position {
Expand Down Expand Up @@ -242,10 +248,16 @@ export class Position extends vscode.Position {
return true;
}

/**
* Is this position at the beginning of the line?
*/
public isLineBeginning() : boolean {
return this.character === 0;
}

/**
* Is this position at the end of the line?
*/
public isLineEnd() : boolean {
return this.character === Position.getLineLength(this.line, this.positionOptions);
}
Expand Down

0 comments on commit 0825461

Please sign in to comment.