2021-01-02 11:59:55 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-01-02 11:59:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibGUI/EditingEngine.h>
|
|
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
|
|
class VimEditingEngine final : public EditingEngine {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual CursorWidth cursor_width() const override;
|
|
|
|
|
|
|
|
|
|
virtual bool on_key(const KeyEvent& event) override;
|
|
|
|
|
|
2021-02-02 19:01:54 +01:00
|
|
|
private:
|
|
|
|
|
enum VimMode {
|
|
|
|
|
Normal,
|
|
|
|
|
Insert,
|
|
|
|
|
Visual
|
2021-01-02 11:59:55 +01:00
|
|
|
};
|
|
|
|
|
|
2021-01-25 23:24:33 +10:00
|
|
|
enum YankType {
|
|
|
|
|
Line,
|
|
|
|
|
Selection
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-02 11:59:55 +01:00
|
|
|
VimMode m_vim_mode { VimMode::Normal };
|
|
|
|
|
|
2021-01-25 23:24:33 +10:00
|
|
|
YankType m_yank_type {};
|
|
|
|
|
String m_yank_buffer {};
|
|
|
|
|
void yank(YankType);
|
|
|
|
|
void yank(TextRange);
|
|
|
|
|
void put(const GUI::KeyEvent&);
|
|
|
|
|
|
2021-01-18 20:39:41 +10:00
|
|
|
TextPosition m_selection_start_position {};
|
|
|
|
|
void update_selection_on_cursor_move();
|
|
|
|
|
void clear_visual_mode_data();
|
|
|
|
|
|
2021-02-02 19:01:54 +01:00
|
|
|
KeyCode m_previous_key {};
|
2021-01-02 11:59:55 +01:00
|
|
|
void switch_to_normal_mode();
|
|
|
|
|
void switch_to_insert_mode();
|
2021-01-18 20:39:41 +10:00
|
|
|
void switch_to_visual_mode();
|
2021-01-02 11:59:55 +01:00
|
|
|
void move_half_page_up(const KeyEvent& event);
|
|
|
|
|
void move_half_page_down(const KeyEvent& event);
|
|
|
|
|
|
|
|
|
|
bool on_key_in_insert_mode(const KeyEvent& event);
|
|
|
|
|
bool on_key_in_normal_mode(const KeyEvent& event);
|
2021-01-18 20:39:41 +10:00
|
|
|
bool on_key_in_visual_mode(const KeyEvent& event);
|
2021-01-02 11:59:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|