EditingEngine.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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();
  38. void move_to_logical_line_beginning();
  39. void move_to_logical_line_end();
  40. void move_to_line_beginning();
  41. void move_to_line_end();
  42. void move_page_up();
  43. void move_page_down();
  44. void move_to_first_line();
  45. void move_to_last_line();
  46. TextPosition find_beginning_of_next_word();
  47. void move_to_beginning_of_next_word();
  48. TextPosition find_end_of_next_word();
  49. void move_to_end_of_next_word();
  50. TextPosition find_end_of_previous_word();
  51. void move_to_end_of_previous_word();
  52. TextPosition find_beginning_of_previous_word();
  53. void move_to_beginning_of_previous_word();
  54. void move_up(double page_height_factor);
  55. void move_down(double page_height_factor);
  56. void get_selection_line_boundaries(size_t& first_line, size_t& last_line);
  57. void delete_line();
  58. void delete_char();
  59. private:
  60. void move_selected_lines_up();
  61. void move_selected_lines_down();
  62. };
  63. }