Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3b26232

Browse files
author
Michelle Tilley
committed
Initial attempt at undo/redo
1 parent 3ce880d commit 3b26232

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

‎js/controlbox.js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ function(_yargs) {
2525
this._currentCommand = -1;
2626
this._tempCommand = '';
2727
this.rebaseConfig = {}; // to configure branches for rebase
28+
29+
this.undoStacks = {
30+
hv: [this.historyView.serialize()]
31+
}
32+
this.undoPointers = {
33+
hv: 0
34+
}
2835
}
2936

3037
ControlBox.prototype = {
@@ -117,6 +124,30 @@ function(_yargs) {
117124
return;
118125
}
119126

127+
if (entry.trim() === 'undo') {
128+
var lastId = this.undoPointers.hv - 1
129+
var lastState = this.undoStacks.hv[lastId]
130+
if (lastState) {
131+
this.historyView.deserialize(lastState)
132+
this.undoPointers.hv = lastId
133+
} else {
134+
this.error("Nothing to undo")
135+
}
136+
return
137+
}
138+
139+
if (entry.trim() === 'redo') {
140+
var lastId = this.undoPointers.hv + 1
141+
var lastState = this.undoStacks.hv[lastId]
142+
if (lastState) {
143+
this.historyView.deserialize(lastState)
144+
this.undoPointers.hv = lastId
145+
} else {
146+
this.error("Nothing to redo")
147+
}
148+
return
149+
}
150+
120151
var split = entry.split(' ');
121152

122153
this.terminalOutput.append('div')
@@ -137,7 +168,13 @@ function(_yargs) {
137168

138169
try {
139170
if (typeof this[method] === 'function') {
171+
140172
this[method](args, options, argsStr);
173+
174+
var state = this.historyView.serialize()
175+
this.undoPointers.hv++
176+
this.undoStacks.hv.length = this.undoPointers.hv
177+
this.undoStacks.hv.push(state)
141178
} else {
142179
this.error();
143180
}

‎js/historyview.js‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,27 @@ define(['d3'], function() {
277277
};
278278

279279
HistoryView.prototype = {
280+
serialize: function () {
281+
var data = {
282+
commitData: this.commitData,
283+
branches: this.branches,
284+
logs: this.logs,
285+
currentBranch: this.currentBranch,
286+
}
287+
288+
return JSON.stringify(data)
289+
},
290+
291+
deserialize: function (data) {
292+
data = JSON.parse(data)
293+
this.commitData = data.commitData
294+
this.branches = data.branches
295+
this.logs = data.logs
296+
this.currentBranch = data.currentBranch
297+
this.renderCommits()
298+
this.renderTags()
299+
},
300+
280301
/**
281302
* @method getCommit
282303
* @param ref {String} the id or a tag name that refers to the commit
@@ -581,7 +602,10 @@ define(['d3'], function() {
581602
.attr('r', 1)
582603
.transition("inflate")
583604
.duration(500)
584-
.attr('r', this.commitRadius);
605+
.attr('r', this.commitRadius)
606+
607+
existingCircles.exit()
608+
.remove()
585609

586610
},
587611

@@ -620,6 +644,9 @@ define(['d3'], function() {
620644
.transition()
621645
.duration(500)
622646
.call(fixPointerEndPosition, view);
647+
648+
existingPointers.exit()
649+
.remove()
623650
},
624651

625652
_renderMergePointers: function() {
@@ -674,6 +701,9 @@ define(['d3'], function() {
674701
points[1] = x2 + ',' + y2;
675702
return points.join(' ');
676703
});
704+
705+
existingPointers.exit()
706+
.remove()
677707
},
678708

679709
_renderIdLabels: function() {
@@ -703,6 +733,9 @@ define(['d3'], function() {
703733
.classed(className, true)
704734
.text(getText)
705735
.call(fixIdPosition, view, delta);
736+
737+
existingTexts.exit()
738+
.remove()
706739
},
707740

708741
_parseTagData: function() {
@@ -857,6 +890,9 @@ define(['d3'], function() {
857890
return commit.cx;
858891
});
859892

893+
existingTags.exit()
894+
.remove()
895+
860896
this._markBranchlessCommits();
861897
},
862898

@@ -1363,6 +1399,7 @@ define(['d3'], function() {
13631399
if (origBranch) {
13641400
this.moveTag(origBranch, newHeadCommit.id)
13651401
this.reset(origBranch)
1402+
this._setCurrentBranch(origBranch)
13661403
this.addReflogEntry(
13671404
'HEAD', targetCommit.id, 'rebase finished: returning to resf/heads/' + origBranch
13681405
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /