EditingEngine.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Noncopyable.h>
  8. #include <LibGUI/Event.h>
  9. #include <LibGUI/TextDocument.h>
  10. namespace GUI {
  11. enum CursorWidth {
  12. NARROW,
  13. WIDE
  14. };
  15. class EditingEngine {
  16. AK_MAKE_NONCOPYABLE(EditingEngine);
  17. AK_MAKE_NONMOVABLE(EditingEngine);
  18. public:
  19. virtual ~EditingEngine();
  20. virtual CursorWidth cursor_width() const { return NARROW; }
  21. void attach(TextEditor& editor);
  22. void detach();
  23. TextEditor& editor()
  24. {
  25. VERIFY(!m_editor.is_null());
  26. return *m_editor.unsafe_ptr();
  27. }
  28. virtual bool on_key(const KeyEvent& event);
  29. protected:
  30. EditingEngine() { }
  31. WeakPtr<TextEditor> m_editor;
  32. void move_one_left();
  33. void move_one_right();
  34. void move_one_up(const KeyEvent& event);
  35. void move_one_down(const KeyEvent& event);
  36. void move_to_previous_span();
  37. void move_to_next_span(const KeyEvent& event);
  38. void move_to_line_beginning();
  39. void move_to_line_end();
  40. void move_page_up();
  41. void move_page_down();
  42. void move_to_first_line();
  43. void move_to_last_line();
  44. TextPosition find_beginning_of_next_word();
  45. void move_to_beginning_of_next_word();
  46. TextPosition find_end_of_next_word();
  47. void move_to_end_of_next_word();
  48. TextPosition find_end_of_previous_word();
  49. void move_to_end_of_previous_word();
  50. TextPosition find_beginning_of_previous_word();
  51. void move_to_beginning_of_previous_word();
  52. void move_up(double page_height_factor);
  53. void move_down(double page_height_factor);
  54. void get_selection_line_boundaries(size_t& first_line, size_t& last_line);
  55. void delete_line();
  56. void delete_char();
  57. private:
  58. void move_selected_lines_up();
  59. void move_selected_lines_down();
  60. };
  61. }