Class: Fir::BackspaceCommand
- Inherits:
-
KeyCommand
- Object
- KeyCommand
- Fir::BackspaceCommand
- Defined in:
- lib/fir/key_command/backspace_command.rb
Instance Attribute Summary
Attributes inherited from KeyCommand
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from KeyCommand
build, #execute, for, handles?, inherited, #initialize, register, registry
Constructor Details
This class inherits a constructor from Fir::KeyCommand
Class Method Details
.character_regex ⇒ Object
8 9 10 |
# File 'lib/fir/key_command/backspace_command.rb', line 8 def self.character_regex /^\177$/ end |
Instance Method Details
#execute_hook(new_state) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fir/key_command/backspace_command.rb', line 12 def execute_hook(new_state) unless state.blank? if state.cursor.x.positive? new_state.cursor = state.cursor.left(1) new_line = state.current_line.clone new_line.delete_at(state.cursor.x - 1) new_state.current_line = new_line elsif state.cursor.x.zero? && state.cursor.y.positive? new_state.cursor = state.cursor.up.right(state.lines[state.cursor.y - 1].length) new_state.lines = state.lines.remove end end new_state end |