1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:47:35 +00:00

TextEditor: Add vim status indicators to the statusbar

When using the VimEditingEngine in the TextEditor, vim's mode and the
previous key are shown in the editor's statusbar.
This commit is contained in:
Zac 2021-01-27 15:49:29 +10:00 committed by Andreas Kling
parent e11ec20650
commit bd6d0d2295
10 changed files with 171 additions and 20 deletions

View file

@ -30,20 +30,48 @@
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;
private:
enum VimMode {
Normal,
Insert,
Visual
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 {};
};
Function<void(VimMode)> on_mode_change;
Function<void(const PreviousKey&, bool has_previous_key)> on_previous_keys_change;
private:
enum YankType {
Line,
Selection
@ -61,7 +89,26 @@ private:
void update_selection_on_cursor_move();
void clear_visual_mode_data();
KeyCode m_previous_key {};
// 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);
}
void switch_to_normal_mode();
void switch_to_insert_mode();
void switch_to_visual_mode();