From 31e04907b4ec0eadd12001694cc9961752e041ae Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 2 Feb 2021 19:01:54 +0100 Subject: [PATCH] Revert "TextEditor: Add vim status indicators to the statusbar" This reverts commit bd6d0d229581e830c7a69cdb29252b9f63e0434a. --- .../TextEditor/TextEditorWidget.cpp | 20 +------ .../TextEditor/TextEditorWidget.h | 3 - .../TextEditor/TextEditorWindow.gml | 1 - Userland/Libraries/LibGUI/EditingEngine.h | 9 --- .../Libraries/LibGUI/RegularEditingEngine.cpp | 5 -- .../Libraries/LibGUI/RegularEditingEngine.h | 2 - Userland/Libraries/LibGUI/TextEditor.cpp | 47 --------------- Userland/Libraries/LibGUI/TextEditor.h | 8 --- .../Libraries/LibGUI/VimEditingEngine.cpp | 37 ++++-------- Userland/Libraries/LibGUI/VimEditingEngine.h | 59 ++----------------- 10 files changed, 20 insertions(+), 171 deletions(-) diff --git a/Userland/Applications/TextEditor/TextEditorWidget.cpp b/Userland/Applications/TextEditor/TextEditorWidget.cpp index 1bd7ac19aa0..9d31b106f8c 100644 --- a/Userland/Applications/TextEditor/TextEditorWidget.cpp +++ b/Userland/Applications/TextEditor/TextEditorWidget.cpp @@ -39,13 +39,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -59,7 +57,6 @@ #include #include #include -#include #include #include #include @@ -304,21 +301,6 @@ TextEditorWidget::TextEditorWidget() m_statusbar = *find_descendant_of_type_named("statusbar"); - m_statusbar->label(m_vim_mode_statusbar_index)->set_visible(m_editor->editing_engine()->type() == GUI::EditingEngineType::Vim); - m_statusbar->label(m_vim_mode_statusbar_index)->set_font(Gfx::FontDatabase::default_bold_font()); - - m_statusbar->label(m_vim_previous_keys_statusbar_index)->set_visible(m_editor->editing_engine()->type() == GUI::EditingEngineType::Vim); - - m_editor->on_vim_statusbar_messages_changed = [this] { - m_statusbar->set_text(m_vim_mode_statusbar_index, m_editor->vim_mode_statusbar_message()); - m_statusbar->set_text(m_vim_previous_keys_statusbar_index, m_editor->vim_previous_keys_statusbar_message()); - }; - - m_editor->on_editing_engine_changed = [this]() { - m_statusbar->label(m_vim_mode_statusbar_index)->set_visible(m_editor->editing_engine()->type() == GUI::EditingEngineType::Vim); - m_statusbar->label(m_vim_previous_keys_statusbar_index)->set_visible(m_editor->editing_engine()->type() == GUI::EditingEngineType::Vim); - }; - m_editor->on_cursor_change = [this] { update_statusbar_cursor_position(); }; m_new_action = GUI::Action::create("New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) { @@ -684,5 +666,5 @@ void TextEditorWidget::update_statusbar_cursor_position() { StringBuilder builder; builder.appendff("Line: {}, Column: {}", m_editor->cursor().line() + 1, m_editor->cursor().column()); - m_statusbar->set_text(m_cursor_position_statusbar_index, builder.to_string()); + m_statusbar->set_text(builder.to_string()); } diff --git a/Userland/Applications/TextEditor/TextEditorWidget.h b/Userland/Applications/TextEditor/TextEditorWidget.h index 28c4a9c3fd1..763087b9e4c 100644 --- a/Userland/Applications/TextEditor/TextEditorWidget.h +++ b/Userland/Applications/TextEditor/TextEditorWidget.h @@ -91,9 +91,6 @@ private: RefPtr m_html_preview_action; RefPtr m_statusbar; - const int m_cursor_position_statusbar_index = 0; - const int m_vim_mode_statusbar_index = 1; - const int m_vim_previous_keys_statusbar_index = 2; RefPtr m_find_textbox; RefPtr m_replace_textbox; diff --git a/Userland/Applications/TextEditor/TextEditorWindow.gml b/Userland/Applications/TextEditor/TextEditorWindow.gml index b13865f6974..433d01abff1 100644 --- a/Userland/Applications/TextEditor/TextEditorWindow.gml +++ b/Userland/Applications/TextEditor/TextEditorWindow.gml @@ -84,6 +84,5 @@ @GUI::StatusBar { name: "statusbar" - label_count: 3 } } diff --git a/Userland/Libraries/LibGUI/EditingEngine.h b/Userland/Libraries/LibGUI/EditingEngine.h index 3da65d2f092..a9eb525acf7 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 653d6da7bb7..ffcbe941cda 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 c91250333da..87e51b08d84 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 20615bcdce6..55be2949e66 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 0bc742b80e9..956e3cfcce1 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 213e267d35e..60a6a2b21b4 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 7af4e60677c..007472d0f9d 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();