selection.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """
  2. Data structures for the selection.
  3. """
  4. from __future__ import annotations
  5. from enum import Enum
  6. __all__ = [
  7. "SelectionType",
  8. "PasteMode",
  9. "SelectionState",
  10. ]
  11. class SelectionType(Enum):
  12. """
  13. Type of selection.
  14. """
  15. #: Characters. (Visual in Vi.)
  16. CHARACTERS = "CHARACTERS"
  17. #: Whole lines. (Visual-Line in Vi.)
  18. LINES = "LINES"
  19. #: A block selection. (Visual-Block in Vi.)
  20. BLOCK = "BLOCK"
  21. class PasteMode(Enum):
  22. EMACS = "EMACS" # Yank like emacs.
  23. VI_AFTER = "VI_AFTER" # When pressing 'p' in Vi.
  24. VI_BEFORE = "VI_BEFORE" # When pressing 'P' in Vi.
  25. class SelectionState:
  26. """
  27. State of the current selection.
  28. :param original_cursor_position: int
  29. :param type: :class:`~.SelectionType`
  30. """
  31. def __init__(
  32. self,
  33. original_cursor_position: int = 0,
  34. type: SelectionType = SelectionType.CHARACTERS,
  35. ) -> None:
  36. self.original_cursor_position = original_cursor_position
  37. self.type = type
  38. self.shift_mode = False
  39. def enter_shift_mode(self) -> None:
  40. self.shift_mode = True
  41. def __repr__(self) -> str:
  42. return "{}(original_cursor_position={!r}, type={!r})".format(
  43. self.__class__.__name__,
  44. self.original_cursor_position,
  45. self.type,
  46. )