Sha256: cc80f965eec698ae380e0c730d1ccf4ac444109d01d69cece521de38332cbc0b
Contents?: true
Size: 581 Bytes
Versions: 2
Compression:
Stored size: 581 Bytes
Contents
module EditorCore class History def initialize @snapshots = [] @current = -1 end def save(data, advance = true) snapshots[@current+1] = data @current += 1 if advance end def can_undo? !undo_snapshot.nil? end def undo undo_snapshot.tap { @current -= 1 } end def can_redo? !redo_snapshot.nil? end def redo redo_snapshot.tap { @current += 1 } end def undo_snapshot snapshots[current] if current >= 0 end private attr_reader :snapshots, :current def redo_snapshot snapshots[current + 2] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
editor_core-0.3.0 | lib/editor_core/history.rb |
editor_core-0.2.0 | lib/editor_core/history.rb |