Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix redo

  • Loading branch information...
commit 06de0e4eb4d992eb2625342ddcec1a1a7be150dc 1 parent b6d8d6f
U-EIDOS.COM\tomre authored
View
1  .gitignore 100644 → 100755
@@ -1,3 +1,4 @@
*.sublime-*
*.hi
*.o
+*.exe
View
44 js/app.coffee 100644 → 100755
@@ -4,47 +4,53 @@ class Document
@layer = new Layer(@width,@height)
@backup = new Layer(@width,@height)
@history = []
- @histIndex = -1
+ @histIndex = 0
afterEdit: (rect)->
if @histIndex > 0
+ # Discard obsolete history branch
@history.splice 0, @histIndex
+ @histIndex = 0
+ # Insert item at the top
@history.splice 0, 0, {
data: @backup.getCopy(rect)
rect: rect
}
+
+ # Backup current layer
@backup.getBuffer().set(@layer.getBuffer())
+
+ # Limit history
histSize = 10
if @history.length > histSize
@history.splice(histSize)
- @histIndex = -1
- console.log "History len: #{this.history.length}"
-
undo: ->
- if @histIndex >= @history.length - 1
+ if @histIndex >= @history.length
return
-
- if @histIndex is -1
- @afterEdit(@history[0].rect)
- @histIndex = 1
- else
- @histIndex++
-
- console.log "History idx: #{this.histIndex}"
- @restore( @history[ @histIndex ] )
+
+ @restore()
+ @histIndex++
redo: ->
- if @histIndex <= 0
+ if @histIndex is 0
return
+
@histIndex--
- console.log "History idx: #{this.histIndex}"
- @restore( @history[ @histIndex ] )
+ @restore()
+
+ restore: ->
+ toRestore = @history[ @histIndex ]
+ # Backup what we are going to undo
+ rect = toRestore.rect
+ @history[ @histIndex ] = {
+ data: @layer.getCopy(rect)
+ rect: rect
+ }
- restore: (histItem)->
- @layer.setData(histItem.data, histItem.rect)
+ @layer.setData(toRestore.data, toRestore.rect)
Renderers = [GammaRenderer, NormalRenderer, GradientRenderer]
View
35 js/app.js 100644 → 100755
@@ -10,7 +10,7 @@ Document = (function() {
this.layer = new Layer(this.width, this.height);
this.backup = new Layer(this.width, this.height);
this.history = [];
- this.histIndex = -1;
+ this.histIndex = 0;
}
Document.prototype.afterEdit = function(rect) {
@@ -18,6 +18,7 @@ Document = (function() {
if (this.histIndex > 0) {
this.history.splice(0, this.histIndex);
}
+ this.histIndex = 0;
this.history.splice(0, 0, {
data: this.backup.getCopy(rect),
rect: rect
@@ -25,37 +26,35 @@ Document = (function() {
this.backup.getBuffer().set(this.layer.getBuffer());
histSize = 10;
if (this.history.length > histSize) {
- this.history.splice(histSize);
+ return this.history.splice(histSize);
}
- this.histIndex = -1;
- return console.log("History len: " + this.history.length);
};
Document.prototype.undo = function() {
- if (this.histIndex >= this.history.length - 1) {
+ if (this.histIndex >= this.history.length) {
return;
}
- if (this.histIndex === -1) {
- this.afterEdit(this.history[0].rect);
- this.histIndex = 1;
- } else {
- this.histIndex++;
- }
- console.log("History idx: " + this.histIndex);
- return this.restore(this.history[this.histIndex]);
+ this.restore();
+ return this.histIndex++;
};
Document.prototype.redo = function() {
- if (this.histIndex <= 0) {
+ if (this.histIndex === 0) {
return;
}
this.histIndex--;
- console.log("History idx: " + this.histIndex);
- return this.restore(this.history[this.histIndex]);
+ return this.restore();
};
- Document.prototype.restore = function(histItem) {
- return this.layer.setData(histItem.data, histItem.rect);
+ Document.prototype.restore = function() {
+ var rect, toRestore;
+ toRestore = this.history[this.histIndex];
+ rect = toRestore.rect;
+ this.history[this.histIndex] = {
+ data: this.layer.getCopy(rect),
+ rect: rect
+ };
+ return this.layer.setData(toRestore.data, toRestore.rect);
};
return Document;
View
0  js/core.coffee 100644 → 100755
File mode changed
View
0  js/core.js 100644 → 100755
File mode changed
View
0  js/tools.coffee 100644 → 100755
File mode changed
View
0  js/tools.js 100644 → 100755
File mode changed
View
0  js/vendor/backbone.js 100644 → 100755
File mode changed
Please sign in to comment.
Something went wrong with that request. Please try again.