Преглед на файлове

LibGUI: Add casefold_selection function to choose case conversion

Allows the passing of a Casing enum, Lowercase or Uppercase, and
converts the selected text accordingly. If Lowercase is passed as the
parameter, it converts the selected text to lowercase. If Uppercase is
passed as the parameter, it converts the selected text to uppercase.
huttongrabiel преди 3 години
родител
ревизия
45c5f68d8a
променени са 2 файла, в които са добавени 22 реда и са изтрити 0 реда
  1. 15 0
      Userland/Libraries/LibGUI/VimEditingEngine.cpp
  2. 7 0
      Userland/Libraries/LibGUI/VimEditingEngine.h

+ 15 - 0
Userland/Libraries/LibGUI/VimEditingEngine.cpp

@@ -1411,4 +1411,19 @@ void VimEditingEngine::move_to_next_empty_lines_block()
     m_editor->set_cursor(new_cursor);
     m_editor->set_cursor(new_cursor);
 };
 };
 
 
+void VimEditingEngine::casefold_selection(Casing casing)
+{
+    VERIFY(!m_editor.is_null());
+    VERIFY(m_editor->has_selection());
+
+    switch (casing) {
+    case Casing::Uppercase:
+        m_editor->insert_at_cursor_or_replace_selection(m_editor->selected_text().to_uppercase());
+        return;
+    case Casing::Lowercase:
+        m_editor->insert_at_cursor_or_replace_selection(m_editor->selected_text().to_lowercase());
+        return;
+    }
+}
+
 }
 }

+ 7 - 0
Userland/Libraries/LibGUI/VimEditingEngine.h

@@ -160,6 +160,11 @@ private:
         Selection
         Selection
     };
     };
 
 
+    enum class Casing {
+        Uppercase,
+        Lowercase
+    };
+
     VimMode m_vim_mode { VimMode::Normal };
     VimMode m_vim_mode { VimMode::Normal };
     VimMotion m_motion;
     VimMotion m_motion;
 
 
@@ -188,6 +193,8 @@ private:
     bool on_key_in_normal_mode(KeyEvent const& event);
     bool on_key_in_normal_mode(KeyEvent const& event);
     bool on_key_in_visual_mode(KeyEvent const& event);
     bool on_key_in_visual_mode(KeyEvent const& event);
 
 
+    void casefold_selection(Casing);
+
     virtual EngineType engine_type() const override { return EngineType::Vim; }
     virtual EngineType engine_type() const override { return EngineType::Vim; }
 };
 };