Class: Kward::PromptInterface::EditorUndoHistory
- Inherits:
-
Object
- Object
- Kward::PromptInterface::EditorUndoHistory
- Defined in:
- lib/kward/prompt_interface/editor/undo_history.rb
Overview
Bounded undo/redo history for editor buffer snapshots.
Instance Attribute Summary collapse
-
#redo_stack ⇒ Object
readonly
Returns the value of attribute redo_stack.
-
#undo_stack ⇒ Object
readonly
Returns the value of attribute undo_stack.
Instance Method Summary collapse
-
#initialize(limit: 100, undo_stack: [], redo_stack: []) ⇒ EditorUndoHistory
constructor
A new instance of EditorUndoHistory.
- #push(snapshot) ⇒ Object
- #redo(current_snapshot) ⇒ Object
- #undo(current_snapshot) ⇒ Object
Constructor Details
#initialize(limit: 100, undo_stack: [], redo_stack: []) ⇒ EditorUndoHistory
Returns a new instance of EditorUndoHistory.
9 10 11 12 13 |
# File 'lib/kward/prompt_interface/editor/undo_history.rb', line 9 def initialize(limit: 100, undo_stack: [], redo_stack: []) @limit = limit @undo_stack = undo_stack @redo_stack = redo_stack end |
Instance Attribute Details
#redo_stack ⇒ Object (readonly)
Returns the value of attribute redo_stack.
7 8 9 |
# File 'lib/kward/prompt_interface/editor/undo_history.rb', line 7 def redo_stack @redo_stack end |
#undo_stack ⇒ Object (readonly)
Returns the value of attribute undo_stack.
7 8 9 |
# File 'lib/kward/prompt_interface/editor/undo_history.rb', line 7 def undo_stack @undo_stack end |
Instance Method Details
#push(snapshot) ⇒ Object
15 16 17 18 19 |
# File 'lib/kward/prompt_interface/editor/undo_history.rb', line 15 def push(snapshot) @undo_stack << snapshot trim(@undo_stack) @redo_stack.clear end |
#redo(current_snapshot) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/kward/prompt_interface/editor/undo_history.rb', line 30 def redo(current_snapshot) snapshot = @redo_stack.pop return nil unless snapshot @undo_stack << current_snapshot trim(@undo_stack) snapshot end |
#undo(current_snapshot) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/kward/prompt_interface/editor/undo_history.rb', line 21 def undo(current_snapshot) snapshot = @undo_stack.pop return nil unless snapshot @redo_stack << current_snapshot trim(@redo_stack) snapshot end |