MCPcopy Create free account
hub / github.com/easydiffusion/easydiffusion / rewindTo

Method rewindTo

ui/media/js/image-editor.js:384–428  ·  view source on GitHub ↗
(new_rewind_index)

Source from the content-addressed store, hash-verified

382 this.rewindTo(this.rewind_index - 1)
383 }
384 rewindTo(new_rewind_index) {
385 if (new_rewind_index < 0 || new_rewind_index > this.events.length) {
386 return // do nothing if target index is out of bounds
387 }
388
389 var ctx = this.editor.layers.drawing.ctx
390 ctx.clearRect(0, 0, this.editor.width, this.editor.height)
391
392 var target_index = this.events.length - 1 - new_rewind_index
393 var snapshot_index = target_index
394 while (snapshot_index > -1) {
395 if (this.events[snapshot_index].snapshot) {
396 break
397 }
398 snapshot_index--
399 }
400
401 if (snapshot_index != -1) {
402 ctx.putImageData(this.events[snapshot_index].snapshot, 0, 0)
403 }
404
405 for (var i = snapshot_index + 1; i <= target_index; i++) {
406 var event = this.events[i]
407 if (event.type == "action") {
408 var action = IMAGE_EDITOR_ACTIONS.find((a) => a.id == event.id)
409 action.handler(this.editor)
410 } else if (event.type == "edit") {
411 var tool = IMAGE_EDITOR_TOOLS.find((t) => t.id == event.id)
412 this.editor.setBrush(this.editor.layers.drawing, event.options)
413
414 var first_point = event.points[0]
415 tool.begin(this.editor, ctx, first_point.x, first_point.y)
416 for (var point_i = 1; point_i < event.points.length; point_i++) {
417 tool.move(this.editor, ctx, event.points[point_i].x, event.points[point_i].y)
418 }
419 var last_point = event.points[event.points.length - 1]
420 tool.end(this.editor, ctx, last_point.x, last_point.y)
421 }
422 }
423
424 // re-set brush to current settings
425 this.editor.setBrush(this.editor.layers.drawing)
426
427 this.rewind_index = new_rewind_index
428 }
429}
430
431class ImageEditor {

Callers 2

undoMethod · 0.95
redoMethod · 0.95

Calls 1

setBrushMethod · 0.80

Tested by

no test coverage detected