EditingEngine.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <AK/Noncopyable.h>
  28. #include <LibGUI/Event.h>
  29. #include <LibGUI/TextDocument.h>
  30. namespace GUI {
  31. enum CursorWidth {
  32. NARROW,
  33. WIDE
  34. };
  35. class EditingEngine {
  36. AK_MAKE_NONCOPYABLE(EditingEngine);
  37. AK_MAKE_NONMOVABLE(EditingEngine);
  38. public:
  39. virtual ~EditingEngine();
  40. virtual CursorWidth cursor_width() const { return NARROW; }
  41. void attach(TextEditor& editor);
  42. void detach();
  43. virtual bool on_key(const KeyEvent& event);
  44. protected:
  45. EditingEngine() { }
  46. WeakPtr<TextEditor> m_editor;
  47. void move_one_left(const KeyEvent& event);
  48. void move_one_right(const KeyEvent& event);
  49. void move_one_up(const KeyEvent& event);
  50. void move_one_down(const KeyEvent& event);
  51. void move_to_previous_span(const KeyEvent& event);
  52. void move_to_next_span(const KeyEvent& event);
  53. void move_to_line_beginning(const KeyEvent& event);
  54. void move_to_line_end(const KeyEvent& event);
  55. void move_page_up(const KeyEvent& event);
  56. void move_page_down(const KeyEvent& event);
  57. void move_to_first_line();
  58. void move_to_last_line();
  59. TextPosition find_beginning_of_next_word();
  60. void move_to_beginning_of_next_word();
  61. TextPosition find_end_of_next_word();
  62. void move_to_end_of_next_word();
  63. TextPosition find_end_of_previous_word();
  64. void move_to_end_of_previous_word();
  65. TextPosition find_beginning_of_previous_word();
  66. void move_to_beginning_of_previous_word();
  67. void move_up(const KeyEvent& event, double page_height_factor);
  68. void move_down(const KeyEvent& event, double page_height_factor);
  69. void get_selection_line_boundaries(size_t& first_line, size_t& last_line);
  70. void delete_line();
  71. void delete_char();
  72. private:
  73. void move_selected_lines_up();
  74. void move_selected_lines_down();
  75. };
  76. }