Class: EditorCore::History

Inherits:
Object
  • Object
show all
Defined in:
lib/editor_core/history.rb

Instance Method Summary collapse

Constructor Details

#initializeHistory

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

Returns:

  • (Boolean)


22
23
24
# File 'lib/editor_core/history.rb', line 22

def can_redo?
  !redo_snapshot.nil?
end

#can_undo?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/editor_core/history.rb', line 14

def can_undo?
  !undo_snapshot.nil?
end

#redoObject



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

#undoObject



18
19
20
# File 'lib/editor_core/history.rb', line 18

def undo
  undo_snapshot.tap { @current -= 1 }
end

#undo_snapshotObject



30
31
32
# File 'lib/editor_core/history.rb', line 30

def undo_snapshot
  snapshots[current] if current >= 0
end