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

BugFix: swapped cursor and caret. desired column not updated properly #119

Merged
merged 1 commit into from
Jan 3, 2016
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
6 changes: 3 additions & 3 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export default class ModeHandler implements vscode.Disposable {

switch (modeName) {
case ModeName.Insert:
this._motion = this._motion.changeMode(MotionMode.Caret);
this._motion = this._motion.changeMode(MotionMode.Cursor);
break;

case ModeName.Normal:
this._motion = this._motion.changeMode(MotionMode.Cursor);
this._motion = this._motion.changeMode(MotionMode.Caret);
break;
}

Expand All @@ -70,8 +70,8 @@ export default class ModeHandler implements vscode.Disposable {

if (nextMode) {
this.currentMode.HandleDeactivation();
nextMode.HandleActivation(key);
this.setCurrentModeByName(nextMode.Name);
nextMode.HandleActivation(key);
return;
}

Expand Down
55 changes: 30 additions & 25 deletions src/motion/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export class Motion implements vscode.Disposable {

public constructor(mode : MotionMode = null) {
let currentPosition = vscode.window.activeTextEditor.selection.active;
this.setPosition(new Position(currentPosition.line, currentPosition.character), true);
this._position = new Position(currentPosition.line, currentPosition.character);
this._desiredColumn = this._position.character;

if (mode !== null) {
this.changeMode(mode);
Expand All @@ -33,7 +34,8 @@ export class Motion implements vscode.Disposable {
let line = selection.active.line;
let char = selection.active.character;

this.setPosition(new Position(line, char), true);
this._position = new Position(line, char);
this._desiredColumn = this._position.character;
this.changeMode(this._motionMode);
}
}));
Expand All @@ -59,7 +61,8 @@ export class Motion implements vscode.Disposable {

public move(line : number = null, character : number = null) : Motion {
if (line !== null && character != null) {
this.setPosition(this.position.setLocation(line, character), true);
this._position = this.position.setLocation(line, character);
this._desiredColumn = this._position.character;
}

if (!this.position.isValid()) {
Expand All @@ -75,70 +78,81 @@ export class Motion implements vscode.Disposable {
}

public left() : Motion {
this.setPosition(this.position.getLeft(), true);
this._position = this.position.getLeft();
this._desiredColumn = this._position.character;
return this;
}

public right() : Motion {
this.setPosition(this.position.getRight(), true);
this._position = this.position.getRight();
this._desiredColumn = this._position.character;
return this;
}

public down() : Motion {
this.setPosition(this.position.getDown(this._desiredColumn));
this._position = this.position.getDown(this._desiredColumn);
return this;
}

public up() : Motion {
this.setPosition(this.position.getUp(this._desiredColumn));
this._position = this.position.getUp(this._desiredColumn);
return this;
}

public wordLeft(): Motion {
this.setPosition(this.position.getWordLeft(), true);
this._position = this.position.getWordLeft();
this._desiredColumn = this._position.character;
return this;
}

public wordRight() : Motion {
this.setPosition(this.position.getWordRight(), true);
this._position = this.position.getWordRight();
this._desiredColumn = this._position.character;
return this;
}

public lineBegin() : Motion {
this.setPosition(this.position.getLineBegin(), true);
this._position = this.position.getLineBegin();
this._desiredColumn = this._position.character;
return this;
}

public lineEnd() : Motion {
this.setPosition(this.position.getLineEnd(), true);
this._position = this.position.getLineEnd();
this._desiredColumn = this._position.character;
return this;
}

public firstLineNonBlankChar() : Motion {
this.setPosition(this.position.setLocation(0, Position.getFirstNonBlankCharAtLine(0)), true);
this._position = this.position.setLocation(0, Position.getFirstNonBlankCharAtLine(0));
this._desiredColumn = this._position.character;
return this;
}

public lastLineNonBlankChar() : Motion {
let lastLine = this.position.getDocumentEnd().line;
let character = Position.getFirstNonBlankCharAtLine(lastLine);

this.setPosition(this.position.setLocation(lastLine, character), true);
this._position = this.position.setLocation(lastLine, character);
this._desiredColumn = this._position.character;
return this;
}

public documentBegin() : Motion {
this.setPosition(this.position.getDocumentBegin(), true);
this._position = this.position.getDocumentBegin();
this._desiredColumn = this._position.character;
return this;
}

public documentEnd() : Motion {
this.setPosition(this.position.getDocumentEnd(), true);
this._position = this.position.getDocumentEnd();
this._desiredColumn = this._position.character;
return this;
}

public goToEndOfCurrentWord(): Motion {
this.setPosition(this.position.getCurrentWordEnd(), true);
this._position = this.position.getCurrentWordEnd();
this._desiredColumn = this._position.character;
return this;
}

Expand All @@ -147,13 +161,4 @@ export class Motion implements vscode.Disposable {
d.dispose();
});
}

private setPosition(position: Position, updateDesiredColumn = false) {
this._position = position;

if (updateDesiredColumn) {
this._desiredColumn = this._position.character;
}
}

}