Class: Yatte::UndoStack

Inherits:
Object
  • Object
show all
Defined in:
lib/yatte/undo.rb

Defined Under Namespace

Classes: Action

Instance Method Summary collapse

Constructor Details

#initializeUndoStack

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

Returns:

  • (Boolean)


40
41
42
# File 'lib/yatte/undo.rb', line 40

def can_redo?
  !@redo.empty?
end

#can_undo?Boolean

Returns:

  • (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

#redoObject



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

#undoObject



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