Class: EditorCore::History
- Inherits:
-
Object
- Object
- EditorCore::History
- Defined in:
- lib/editor_core/history.rb
Instance Method Summary collapse
- #can_redo? ⇒ Boolean
- #can_undo? ⇒ Boolean
-
#initialize ⇒ History
constructor
A new instance of History.
- #redo ⇒ Object
- #save(data, advance = true) ⇒ Object
- #undo ⇒ Object
- #undo_snapshot ⇒ Object
Constructor Details
#initialize ⇒ History
Returns a new instance of History.
4 5 6 7 |
# File 'lib/editor_core/history.rb', line 4 def initialize @snapshots = [] @current = -1 end |
Instance Method Details
#can_redo? ⇒ Boolean
22 23 24 |
# File 'lib/editor_core/history.rb', line 22 def can_redo? !redo_snapshot.nil? end |
#can_undo? ⇒ Boolean
14 15 16 |
# File 'lib/editor_core/history.rb', line 14 def can_undo? !undo_snapshot.nil? end |
#redo ⇒ Object
26 27 28 |
# File 'lib/editor_core/history.rb', line 26 def redo redo_snapshot.tap { @current += 1 } end |
#save(data, advance = true) ⇒ Object
9 10 11 12 |
# File 'lib/editor_core/history.rb', line 9 def save(data, advance = true) snapshots[@current+1] = data @current += 1 if advance end |
#undo ⇒ Object
18 19 20 |
# File 'lib/editor_core/history.rb', line 18 def undo undo_snapshot.tap { @current -= 1 } end |
#undo_snapshot ⇒ Object
30 31 32 |
# File 'lib/editor_core/history.rb', line 30 def undo_snapshot snapshots[current] if current >= 0 end |