aboutsummaryrefslogtreecommitdiff
path: root/src/keymap/KeymapEvaluator.hpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-20 22:10:57 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-20 22:10:57 +0530
commitfdeb33d34a97d062a120f72da919f81d7b1d45bf (patch)
tree91165d5e3e718d4008bf73259f45d1705965f4b0 /src/keymap/KeymapEvaluator.hpp
parent9e3474b5d8ee4afdd9c03cfb4a151ffebfca36b7 (diff)
downloadnull-browser-fdeb33d34a97d062a120f72da919f81d7b1d45bf.tar.gz
null-browser-fdeb33d34a97d062a120f72da919f81d7b1d45bf.zip
Move header files to src
Diffstat (limited to 'src/keymap/KeymapEvaluator.hpp')
-rw-r--r--src/keymap/KeymapEvaluator.hpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/keymap/KeymapEvaluator.hpp b/src/keymap/KeymapEvaluator.hpp
new file mode 100644
index 0000000..db93900
--- /dev/null
+++ b/src/keymap/KeymapEvaluator.hpp
@@ -0,0 +1,42 @@
+#pragma once
+
+#include <QWidget>
+#include <QtCore/qmap.h>
+#include <QtCore/qnamespace.h>
+#include <QtCore>
+#include <functional>
+
+#include "keymap/KeySeqParser.hpp"
+#include "utils.hpp"
+
+typedef std::function<void()> KeyAction;
+
+struct KeyMap {
+ KeySequence keySequence;
+ KeyAction action;
+};
+
+enum KeyMode { Normal, Insert };
+
+class KeymapEvaluator : public QObject {
+ Q_OBJECT
+
+public:
+ KeymapEvaluator();
+
+ void addKeymap(KeyMode mode, QString key, KeyAction action);
+ bool evaluate(Qt::KeyboardModifiers modifiers, Qt::Key key);
+
+ DEFINE_SETTER(setCurrentMode, currentMode)
+ DEFINE_GETTER(getCurrentMode, currentMode)
+
+private:
+ const QList<KeyMap> *currentModeKeys();
+ bool isInsertableMode();
+
+private:
+ QMap<KeyMode, QList<KeyMap>> modalKeys;
+ KeySeqParser keySeqParser;
+ KeyMode currentMode = KeyMode::Normal;
+ KeySequence activeKeySequence;
+};