1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:37:43 +00:00

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.
This commit is contained in:
huttongrabiel 2022-05-18 11:33:33 -07:00 committed by Linus Groh
parent 3b0785a636
commit 45c5f68d8a
2 changed files with 22 additions and 0 deletions

View file

@ -1411,4 +1411,19 @@ void VimEditingEngine::move_to_next_empty_lines_block()
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;
}
}
}

View file

@ -160,6 +160,11 @@ private:
Selection
};
enum class Casing {
Uppercase,
Lowercase
};
VimMode m_vim_mode { VimMode::Normal };
VimMotion m_motion;
@ -188,6 +193,8 @@ private:
bool on_key_in_normal_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; }
};