Class: Yatte::UndoStack
- Inherits:
-
Object
- Object
- Yatte::UndoStack
- Defined in:
- lib/yatte/undo.rb
Defined Under Namespace
Classes: Action
Instance Method Summary collapse
- #can_redo? ⇒ Boolean
- #can_undo? ⇒ Boolean
-
#initialize ⇒ UndoStack
constructor
A new instance of UndoStack.
- #push(type:, row:, col:, text:, cursor_row:, cursor_col:) ⇒ Object
- #redo ⇒ Object
- #undo ⇒ Object
Constructor Details
#initialize ⇒ UndoStack
Returns a new instance of UndoStack.
7 8 9 10 |
# File 'lib/yatte/undo.rb', line 7 def initialize @undo = [] @redo = [] end |
Instance Method Details
#can_redo? ⇒ Boolean
40 41 42 |
# File 'lib/yatte/undo.rb', line 40 def can_redo? !@redo.empty? end |
#can_undo? ⇒ Boolean
36 37 38 |
# File 'lib/yatte/undo.rb', line 36 def can_undo? !@undo.empty? end |
#push(type:, row:, col:, text:, cursor_row:, cursor_col:) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/yatte/undo.rb', line 12 def push(type:, row:, col:, text:, cursor_row:, cursor_col:) @redo.clear @undo.push(Action.new( type: type, row: row, col: col, text: text, cursor_row: cursor_row, cursor_col: cursor_col )) end |
#redo ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/yatte/undo.rb', line 28 def redo return nil if @redo.empty? action = @redo.pop @undo.push(action) action end |
#undo ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/yatte/undo.rb', line 20 def undo return nil if @undo.empty? action = @undo.pop @redo.push(action) action end |