class Fir::BackspaceCommand

Public Class Methods

character_regex() click to toggle source
# File lib/fir/key_command/backspace_command.rb, line 8
def self.character_regex
  /^\177$/
end

Public Instance Methods

execute_hook(new_state) click to toggle source
# 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