vi_state.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from __future__ import unicode_literals
  2. __all__ = (
  3. 'InputMode',
  4. 'CharacterFind',
  5. 'ViState',
  6. )
  7. class InputMode(object):
  8. INSERT = 'vi-insert'
  9. INSERT_MULTIPLE = 'vi-insert-multiple'
  10. NAVIGATION = 'vi-navigation'
  11. REPLACE = 'vi-replace'
  12. class CharacterFind(object):
  13. def __init__(self, character, backwards=False):
  14. self.character = character
  15. self.backwards = backwards
  16. class ViState(object):
  17. """
  18. Mutable class to hold the state of the Vi navigation.
  19. """
  20. def __init__(self):
  21. #: None or CharacterFind instance. (This is used to repeat the last
  22. #: search in Vi mode, by pressing the 'n' or 'N' in navigation mode.)
  23. self.last_character_find = None
  24. # When an operator is given and we are waiting for text object,
  25. # -- e.g. in the case of 'dw', after the 'd' --, an operator callback
  26. # is set here.
  27. self.operator_func = None
  28. self.operator_arg = None
  29. #: Named registers. Maps register name (e.g. 'a') to
  30. #: :class:`ClipboardData` instances.
  31. self.named_registers = {}
  32. #: The Vi mode we're currently in to.
  33. self.input_mode = InputMode.INSERT
  34. #: Waiting for digraph.
  35. self.waiting_for_digraph = False
  36. self.digraph_symbol1 = None # (None or a symbol.)
  37. #: When true, make ~ act as an operator.
  38. self.tilde_operator = False
  39. def reset(self, mode=InputMode.INSERT):
  40. """
  41. Reset state, go back to the given mode. INSERT by default.
  42. """
  43. # Go back to insert mode.
  44. self.input_mode = mode
  45. self.waiting_for_digraph = False
  46. self.operator_func = None
  47. self.operator_arg = None