diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2022-06-07 22:32:35 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-19 10:49:38 +0100 |
commit | 7a8104e79b9c8b4bb63d9ad8386ed73125ca07a5 (patch) | |
tree | 9c6a6f18eb64dd3734769c6d5ec5ba9c10b9488d /Userland/Libraries/LibGUI/EditingEngine.h | |
parent | cf693136e25eb6bbee6f0cecf229cc56820c8808 (diff) | |
download | serenity-7a8104e79b9c8b4bb63d9ad8386ed73125ca07a5.zip |
LibGUI: Add MoveLineUpOrDownCommand
This allows lines moved by Ctrl+Shift+[Up, Down] to be registered as a
command, i.e. cancellable by Ctrl+Z.
This patch also introduces the usage of TextDocument::[take,
insert]_line. Those functions forward changes to the visual lines and
then avoid some data mismatch.
Co-authored-by: Jorropo <jorropo.pgm@gmail.com>
Diffstat (limited to 'Userland/Libraries/LibGUI/EditingEngine.h')
-rw-r--r-- | Userland/Libraries/LibGUI/EditingEngine.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/EditingEngine.h b/Userland/Libraries/LibGUI/EditingEngine.h index 13c71a3dca..d6dacb1205 100644 --- a/Userland/Libraries/LibGUI/EditingEngine.h +++ b/Userland/Libraries/LibGUI/EditingEngine.h @@ -22,6 +22,8 @@ enum EngineType { Vim, }; +class MoveLineUpOrDownCommand; + class EditingEngine { AK_MAKE_NONCOPYABLE(EditingEngine); AK_MAKE_NONMOVABLE(EditingEngine); @@ -45,6 +47,8 @@ public: bool is_regular() const { return engine_type() == EngineType::Regular; } bool is_vim() const { return engine_type() == EngineType::Vim; } + void get_selection_line_boundaries(Badge<MoveLineUpOrDownCommand>, size_t& first_line, size_t& last_line); + protected: EditingEngine() = default; @@ -80,10 +84,27 @@ protected: void delete_char(); virtual EngineType engine_type() const = 0; +}; + +class MoveLineUpOrDownCommand : public TextDocumentUndoCommand { +public: + MoveLineUpOrDownCommand(TextDocument&, KeyEvent event, EditingEngine&); + virtual void undo() override; + virtual void redo() override; + bool merge_with(GUI::Command const&) override; + String action_text() const override; + + static bool valid_operation(EditingEngine& engine, VerticalDirection direction); private: - void move_selected_lines_up(); - void move_selected_lines_down(); + void move_lines(VerticalDirection); + TextRange retrieve_selection(VerticalDirection); + + KeyEvent m_event; + VerticalDirection m_direction; + EditingEngine& m_engine; + TextRange m_selection; + TextPosition m_cursor; }; } |