VimEditingEngine.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibGUI/EditingEngine.h>
  8. namespace GUI {
  9. class VimEditingEngine final : public EditingEngine {
  10. public:
  11. virtual CursorWidth cursor_width() const override;
  12. virtual bool on_key(const KeyEvent& event) override;
  13. private:
  14. enum VimMode {
  15. Normal,
  16. Insert,
  17. Visual
  18. };
  19. enum YankType {
  20. Line,
  21. Selection
  22. };
  23. VimMode m_vim_mode { VimMode::Normal };
  24. YankType m_yank_type {};
  25. String m_yank_buffer {};
  26. void yank(YankType);
  27. void yank(TextRange);
  28. void put(const GUI::KeyEvent&);
  29. TextPosition m_selection_start_position {};
  30. void update_selection_on_cursor_move();
  31. void clear_visual_mode_data();
  32. KeyCode m_previous_key {};
  33. void switch_to_normal_mode();
  34. void switch_to_insert_mode();
  35. void switch_to_visual_mode();
  36. void move_half_page_up(const KeyEvent& event);
  37. void move_half_page_down(const KeyEvent& event);
  38. void move_to_previous_empty_lines_block();
  39. void move_to_next_empty_lines_block();
  40. bool on_key_in_insert_mode(const KeyEvent& event);
  41. bool on_key_in_normal_mode(const KeyEvent& event);
  42. bool on_key_in_visual_mode(const KeyEvent& event);
  43. };
  44. }