Class: Fir::SingleKeyCommand

Inherits:
KeyCommand show all
Defined in:
lib/fir/key_command/single_key_command.rb

Instance Attribute Summary

Attributes inherited from KeyCommand

#character, #state

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_regexObject



8
9
10
11
# File 'lib/fir/key_command/single_key_command.rb', line 8

def self.character_regex
  # Matches all printable ASCII characters
  /[ -~]/
end

Instance Method Details

#execute_hook(new_state) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/fir/key_command/single_key_command.rb', line 13

def execute_hook(new_state)
  new_state.current_line = state.lines[-1].clone.insert(
    state.cursor.x,
    character
  )
  new_state.cursor = state.cursor.right(1)
  new_state.history.reset
  new_state
end