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

Manual history tracking #370

Merged
merged 30 commits into from
Jun 30, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1c7c539
Begin rolling our own history tracker
johnfn Jun 27, 2016
59a16f1
Undo more or less works
johnfn Jun 27, 2016
b712527
Fix undo cursor position
johnfn Jun 27, 2016
030c522
Refactor
johnfn Jun 27, 2016
ab0cdfa
I actually think I got it! (Maybe.)
johnfn Jun 28, 2016
2f920a0
This history tracking stuff really seems to work!
johnfn Jun 28, 2016
5cbb49f
Align history change point with . command.
johnfn Jun 28, 2016
573e0b6
Fix issue with running tests.
johnfn Jun 28, 2016
2fc08e2
Add documentation.
johnfn Jun 28, 2016
fdf79ab
Fix braindead previous commit.
johnfn Jun 28, 2016
2d033cc
Fix cursor position
johnfn Jun 28, 2016
4650f86
Fix a few bugs
johnfn Jun 28, 2016
2486982
Track cursor position correctly.
johnfn Jun 28, 2016
cc10d25
More cursor position wrangling
johnfn Jun 28, 2016
655565c
Fix a few more bugs.
johnfn Jun 28, 2016
bbf89ee
Minor cleanup
johnfn Jun 28, 2016
eb6e4b9
Fix bug with .
johnfn Jun 29, 2016
f2021dc
Fix a bug with running tests.
johnfn Jun 29, 2016
d9b6f29
Fix undo cursor position corner case.
johnfn Jun 29, 2016
a28597f
Add comment.
johnfn Jun 29, 2016
df09e0a
Add diff as dependency.
johnfn Jun 29, 2016
e801447
Fix cursor position bug
johnfn Jun 29, 2016
f80dfd8
Different type of insert for undo/redo.
johnfn Jun 29, 2016
1ba07cf
Handle multiple files with multiple undo stacks
johnfn Jun 29, 2016
0530e2b
Add initial history state
johnfn Jun 30, 2016
616a680
Collapse multiple small edits into one
johnfn Jun 30, 2016
7f769c0
Fix bug with autocomplete.
johnfn Jun 30, 2016
c25ddaa
Fix some race conditions.
johnfn Jun 30, 2016
52b455e
Wrap locked code in try/catch
johnfn Jun 30, 2016
8d2b389
Merge branch 'master' into history
johnfn Jun 30, 2016
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
Prev Previous commit
Next Next commit
This history tracking stuff really seems to work!
  • Loading branch information
johnfn committed Jun 28, 2016
commit 2f920a02be15e4bfc74d84e792293818840395ec
8 changes: 6 additions & 2 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,9 @@ class CommandUndo extends BaseCommand {
public async exec(position: Position, vimState: VimState): Promise<VimState> {
const newPosition = await HistoryTracker.goBackHistoryStep();

vimState.cursorPosition = newPosition;
if (newPosition !== undefined) {
vimState.cursorPosition = newPosition;
}
vimState.alteredHistory = true;
return vimState;
}
Expand All @@ -922,7 +924,9 @@ class CommandRedo extends BaseCommand {
public async exec(position: Position, vimState: VimState): Promise<VimState> {
const newPosition = await HistoryTracker.goForwardHistoryStep();

vimState.cursorPosition = newPosition;
if (newPosition !== undefined) {
vimState.cursorPosition = newPosition;
}
vimState.alteredHistory = true;
return vimState;
}
Expand Down
15 changes: 11 additions & 4 deletions src/history/historyTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ class HistoryTrackerClass {
this.currentHistoryStep.isFinished = true;
}

/**
* Returns undefined on failure.
*/
async goBackHistoryStep(): Promise<Position> {
if (this.currentHistoryStepIndex === -1) {
return;
return undefined;
}

let position: Position;
Expand All @@ -145,16 +148,19 @@ class HistoryTrackerClass {
return position;
}

/**
* Returns undefined on failure.
*/
async goForwardHistoryStep(): Promise<Position> {
if (this.currentHistoryStepIndex === this.historySteps.length - 1) {
return undefined;
}

this.currentHistoryStepIndex++;

let position: Position;
let step = this.currentHistoryStep;

this.currentHistoryStepIndex++;

for (const change of step.changes) {
position = await change.do();
}
Expand All @@ -168,7 +174,8 @@ class HistoryTrackerClass {
for (let i = 0; i < this.historySteps.length; i++) {
const step = this.historySteps[i];

result += step.changes.map(x => x.text).join(",");
result += step.changes.map(x => x.text).join("");
if (this.currentHistoryStepIndex === i) { result += "+"; }
if (step.isFinished) { result += "✓"; }
result += "| ";
}
Expand Down