From 31e04907b4ec0eadd12001694cc9961752e041ae Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 2 Feb 2021 19:01:54 +0100 Subject: Revert "TextEditor: Add vim status indicators to the statusbar" This reverts commit bd6d0d229581e830c7a69cdb29252b9f63e0434a. --- Userland/Libraries/LibGUI/EditingEngine.h | 9 ---- Userland/Libraries/LibGUI/RegularEditingEngine.cpp | 5 -- Userland/Libraries/LibGUI/RegularEditingEngine.h | 2 - Userland/Libraries/LibGUI/TextEditor.cpp | 47 ----------------- Userland/Libraries/LibGUI/TextEditor.h | 8 --- Userland/Libraries/LibGUI/VimEditingEngine.cpp | 37 +++++--------- Userland/Libraries/LibGUI/VimEditingEngine.h | 59 +++------------------- 7 files changed, 19 insertions(+), 148 deletions(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibGUI/EditingEngine.h b/Userland/Libraries/LibGUI/EditingEngine.h index 3da65d2f09..a9eb525acf 100644 --- a/Userland/Libraries/LibGUI/EditingEngine.h +++ b/Userland/Libraries/LibGUI/EditingEngine.h @@ -37,11 +37,6 @@ enum CursorWidth { WIDE }; -enum EditingEngineType { - Regular, - Vim -}; - class EditingEngine { AK_MAKE_NONCOPYABLE(EditingEngine); AK_MAKE_NONMOVABLE(EditingEngine); @@ -56,15 +51,11 @@ public: virtual bool on_key(const KeyEvent& event); - EditingEngineType type() const { return m_editing_engine_type; } - protected: EditingEngine() { } WeakPtr m_editor; - EditingEngineType m_editing_engine_type; - void move_one_left(const KeyEvent& event); void move_one_right(const KeyEvent& event); void move_one_up(const KeyEvent& event); diff --git a/Userland/Libraries/LibGUI/RegularEditingEngine.cpp b/Userland/Libraries/LibGUI/RegularEditingEngine.cpp index 653d6da7bb..ffcbe941cd 100644 --- a/Userland/Libraries/LibGUI/RegularEditingEngine.cpp +++ b/Userland/Libraries/LibGUI/RegularEditingEngine.cpp @@ -30,11 +30,6 @@ namespace GUI { -RegularEditingEngine::RegularEditingEngine() -{ - m_editing_engine_type = EditingEngineType::Regular; -} - CursorWidth RegularEditingEngine::cursor_width() const { return CursorWidth::NARROW; diff --git a/Userland/Libraries/LibGUI/RegularEditingEngine.h b/Userland/Libraries/LibGUI/RegularEditingEngine.h index c91250333d..87e51b08d8 100644 --- a/Userland/Libraries/LibGUI/RegularEditingEngine.h +++ b/Userland/Libraries/LibGUI/RegularEditingEngine.h @@ -33,8 +33,6 @@ namespace GUI { class RegularEditingEngine final : public EditingEngine { public: - RegularEditingEngine(); - virtual CursorWidth cursor_width() const override; virtual bool on_key(const KeyEvent& event) override; diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 20615bcdce..55be2949e6 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -1626,52 +1625,6 @@ void TextEditor::set_editing_engine(OwnPtr editing_engine) update_cursor(); stop_timer(); start_timer(500); - - if (on_editing_engine_changed) - on_editing_engine_changed(); - - if (m_editing_engine->type() == EditingEngineType::Vim) { - VimEditingEngine* vim = dynamic_cast(m_editing_engine.ptr()); - vim->on_mode_change = [&](VimMode mode) { - switch (mode) { - case Normal: - m_vim_mode_statusbar_message = {}; - break; - case Insert: - m_vim_mode_statusbar_message = "-- INSERT --"; - break; - case Visual: - m_vim_mode_statusbar_message = "-- VISUAL --"; - break; - default: - dbgln("Unhandled vim mode"); - m_vim_mode_statusbar_message = {}; - } - if (on_vim_statusbar_messages_changed) - on_vim_statusbar_messages_changed(); - }; - - // FIXME: Update this method to take multiple previous keys when that is implemented - vim->on_previous_keys_change = [&](const VimEditingEngine::PreviousKey& event, bool has_previous_key) { - if (has_previous_key) { - StringBuilder sb = StringBuilder(1); - sb.append_code_point(event.code_point); - m_vim_previous_keys_statusbar_message = sb.to_string(); - } else { - m_vim_previous_keys_statusbar_message = {}; - } - if (on_vim_statusbar_messages_changed) - on_vim_statusbar_messages_changed(); - }; - } else { - m_vim_mode_statusbar_message = {}; - m_vim_previous_keys_statusbar_message = {}; - if (on_vim_statusbar_messages_changed) - on_vim_statusbar_messages_changed(); - if (on_editing_engine_changed) { - on_editing_engine_changed(); - } - } } int TextEditor::line_height() const diff --git a/Userland/Libraries/LibGUI/TextEditor.h b/Userland/Libraries/LibGUI/TextEditor.h index 0bc742b80e..956e3cfcce 100644 --- a/Userland/Libraries/LibGUI/TextEditor.h +++ b/Userland/Libraries/LibGUI/TextEditor.h @@ -150,8 +150,6 @@ public: Function on_down_pressed; Function on_pageup_pressed; Function on_pagedown_pressed; - Function on_vim_statusbar_messages_changed; - Function on_editing_engine_changed; Action& undo_action() { return *m_undo_action; } Action& redo_action() { return *m_redo_action; } @@ -197,9 +195,6 @@ public: void delete_text_range(TextRange); - String vim_mode_statusbar_message() const { return m_vim_mode_statusbar_message; } - String vim_previous_keys_statusbar_message() const { return m_vim_previous_keys_statusbar_message; } - protected: explicit TextEditor(Type = Type::MultiLine); @@ -356,9 +351,6 @@ private: Gfx::IntPoint m_last_mousemove_position; RefPtr m_icon; - - String m_vim_mode_statusbar_message {}; - String m_vim_previous_keys_statusbar_message {}; }; } diff --git a/Userland/Libraries/LibGUI/VimEditingEngine.cpp b/Userland/Libraries/LibGUI/VimEditingEngine.cpp index 213e267d35..60a6a2b21b 100644 --- a/Userland/Libraries/LibGUI/VimEditingEngine.cpp +++ b/Userland/Libraries/LibGUI/VimEditingEngine.cpp @@ -30,11 +30,6 @@ namespace GUI { -VimEditingEngine::VimEditingEngine() -{ - m_editing_engine_type = EditingEngineType::Vim; -} - CursorWidth VimEditingEngine::cursor_width() const { return m_vim_mode == VimMode::Insert ? CursorWidth::NARROW : CursorWidth::WIDE; @@ -106,19 +101,19 @@ bool VimEditingEngine::on_key_in_normal_mode(const KeyEvent& event) delete_to.set_column(delete_to.column() + 1); m_editor->delete_text_range(TextRange(m_editor->cursor(), delete_to).normalized()); } - clear_previous_key(); + m_previous_key = {}; } else if (m_previous_key == KeyCode::Key_G) { if (event.key() == KeyCode::Key_G) { move_to_first_line(); } else if (event.key() == KeyCode::Key_E) { move_to_end_of_previous_word(); } - clear_previous_key(); + m_previous_key = {}; } else if (m_previous_key == KeyCode::Key_Y) { if (event.key() == KeyCode::Key_Y) { yank(Line); } - clear_previous_key(); + m_previous_key = {}; } else if (m_previous_key == KeyCode::Key_C) { if (event.key() == KeyCode::Key_C) { // Needed because the code to replace the deleted line is called after delete_line() so @@ -174,7 +169,7 @@ bool VimEditingEngine::on_key_in_normal_mode(const KeyEvent& event) m_editor->delete_text_range(TextRange(adjusted_cursor, delete_to).normalized()); switch_to_insert_mode(); } - clear_previous_key(); + m_previous_key = {}; } else { // Handle first any key codes that are to be applied regardless of modifiers. switch (event.key()) { @@ -245,7 +240,7 @@ bool VimEditingEngine::on_key_in_normal_mode(const KeyEvent& event) move_to_beginning_of_previous_word(); break; case (KeyCode::Key_C): - set_previous_key(event); + m_previous_key = event.key(); break; case (KeyCode::Key_Backspace): case (KeyCode::Key_H): @@ -253,13 +248,13 @@ bool VimEditingEngine::on_key_in_normal_mode(const KeyEvent& event) move_one_left(event); break; case (KeyCode::Key_D): - set_previous_key(event); + m_previous_key = event.key(); break; case (KeyCode::Key_E): move_to_end_of_next_word(); break; case (KeyCode::Key_G): - set_previous_key(event); + m_previous_key = event.key(); break; case (KeyCode::Key_Down): case (KeyCode::Key_J): @@ -298,7 +293,7 @@ bool VimEditingEngine::on_key_in_normal_mode(const KeyEvent& event) switch_to_visual_mode(); break; case (KeyCode::Key_Y): - set_previous_key(event); + m_previous_key = event.key(); break; case (KeyCode::Key_P): put(event); @@ -321,7 +316,7 @@ bool VimEditingEngine::on_key_in_visual_mode(const KeyEvent& event) move_to_end_of_previous_word(); update_selection_on_cursor_move(); } - clear_previous_key(); + m_previous_key = {}; } else { // Handle first any key codes that are to be applied regardless of modifiers. switch (event.key()) { @@ -396,7 +391,7 @@ bool VimEditingEngine::on_key_in_visual_mode(const KeyEvent& event) update_selection_on_cursor_move(); break; case (KeyCode::Key_G): - set_previous_key(event); + m_previous_key = event.key(); break; case (KeyCode::Key_Down): case (KeyCode::Key_J): @@ -453,32 +448,26 @@ void VimEditingEngine::switch_to_normal_mode() { m_vim_mode = VimMode::Normal; m_editor->reset_cursor_blink(); - clear_previous_key(); + m_previous_key = {}; clear_visual_mode_data(); - if (on_mode_change) - on_mode_change(m_vim_mode); }; void VimEditingEngine::switch_to_insert_mode() { m_vim_mode = VimMode::Insert; m_editor->reset_cursor_blink(); - clear_previous_key(); + m_previous_key = {}; clear_visual_mode_data(); - if (on_mode_change) - on_mode_change(m_vim_mode); }; void VimEditingEngine::switch_to_visual_mode() { m_vim_mode = VimMode::Visual; m_editor->reset_cursor_blink(); - clear_previous_key(); + m_previous_key = {}; m_selection_start_position = m_editor->cursor(); m_editor->selection()->set(m_editor->cursor(), { m_editor->cursor().line(), m_editor->cursor().column() + 1 }); m_editor->did_update_selection(); - if (on_mode_change) - on_mode_change(m_vim_mode); } void VimEditingEngine::update_selection_on_cursor_move() diff --git a/Userland/Libraries/LibGUI/VimEditingEngine.h b/Userland/Libraries/LibGUI/VimEditingEngine.h index 7af4e60677..007472d0f9 100644 --- a/Userland/Libraries/LibGUI/VimEditingEngine.h +++ b/Userland/Libraries/LibGUI/VimEditingEngine.h @@ -30,48 +30,20 @@ namespace GUI { -enum VimMode { - Normal, - Insert, - Visual -}; - class VimEditingEngine final : public EditingEngine { public: - VimEditingEngine(); - virtual CursorWidth cursor_width() const override; virtual bool on_key(const KeyEvent& event) override; - class PreviousKey { - public: - PreviousKey() = default; - PreviousKey(const KeyEvent& event) - : key(event.key()) - , code_point(event.code_point()) - { - } - - bool operator==(const KeyCode& key) const - { - return this->key == key; - } - - bool operator==(const u32& code_point) const - { - return this->code_point == code_point; - } - - KeyCode key {}; - u32 code_point {}; +private: + enum VimMode { + Normal, + Insert, + Visual }; - Function on_mode_change; - Function on_previous_keys_change; - -private: enum YankType { Line, Selection @@ -89,26 +61,7 @@ private: void update_selection_on_cursor_move(); void clear_visual_mode_data(); - // FIXME Support multiple previous keys, this is a temporary measure. - PreviousKey m_previous_key {}; - bool has_previous_key { false }; - - void set_previous_key(PreviousKey event) - { - m_previous_key = event; - has_previous_key = true; - if (on_previous_keys_change) - on_previous_keys_change(m_previous_key, has_previous_key); - } - - void clear_previous_key() - { - m_previous_key = {}; - has_previous_key = false; - if (on_previous_keys_change) - on_previous_keys_change(m_previous_key, has_previous_key); - } - + KeyCode m_previous_key {}; void switch_to_normal_mode(); void switch_to_insert_mode(); void switch_to_visual_mode(); -- cgit v1.2.3