diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-23 19:48:53 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-23 21:47:03 +0530 |
| commit | 346c16b4e2ea26f47e0e370a490b7794492a9ebb (patch) | |
| tree | 277a30ac8b0c82a9c9736985385d0d150a55fcb5 /src/keymap/KeymapEvaluator.cpp | |
| parent | 9cc72e8ea9f59f9a9627d05528d54a559ebd412c (diff) | |
| download | null-browser-346c16b4e2ea26f47e0e370a490b7794492a9ebb.tar.gz null-browser-346c16b4e2ea26f47e0e370a490b7794492a9ebb.zip | |
Apply clang-tidy suggestions
Diffstat (limited to '')
| -rw-r--r-- | src/keymap/KeymapEvaluator.cpp | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/src/keymap/KeymapEvaluator.cpp b/src/keymap/KeymapEvaluator.cpp index 692317b..912c84d 100644 --- a/src/keymap/KeymapEvaluator.cpp +++ b/src/keymap/KeymapEvaluator.cpp @@ -1,20 +1,22 @@ #include <QWidget> #include <QtCore> +#include <utility> +#include "keymap/KeySeqParser.hpp" #include "keymap/KeymapEvaluator.hpp" -KeymapEvaluator::KeymapEvaluator() : QObject() {} - // TODO: Clear mapping after some time -void KeymapEvaluator::addKeymap(KeyMode mode, QString key, KeyAction action) { - if (!modalKeys.contains(mode)) - modalKeys.insert(mode, {}); +void KeymapEvaluator::add_keymap(KeyMode mode, const QString &key, + KeyAction action) { + if (!modal_keys.contains(mode)) + modal_keys.insert(mode, {}); qDebug() << " " << mode << key; - auto keySeq = keySeqParser.parse(key); - modalKeys[mode].append(KeyMap{.keySequence = keySeq, .action = action}); + auto key_seq = key_seq_parser.parse(key); + modal_keys[mode].append( + KeyMap{.key_sequence = key_seq, .action = std::move(action)}); } bool KeymapEvaluator::evaluate(Qt::KeyboardModifiers modifiers, Qt::Key key) { @@ -22,48 +24,49 @@ bool KeymapEvaluator::evaluate(Qt::KeyboardModifiers modifiers, Qt::Key key) { key == Qt::Key_Alt) return true; - auto keymaps = currentModeKeys(); - auto foundPendingMatches = false; + const auto *keymaps = current_mode_keys(); + auto found_pending_matches = false; - activeKeySequence.append(KeyChord{.mod = modifiers, .key = key}); + active_key_sequence.append(KeyChord{.mod = modifiers, .key = key}); - for (auto &keymap : *keymaps) { - auto matchType = - KeySeqParser::keySequenceMatch(keymap.keySequence, activeKeySequence); + for (const auto &keymap : *keymaps) { + auto match_type = KeySeqParser::key_sequence_match(keymap.key_sequence, + active_key_sequence); - if (matchType == KeyMatchType::Match) { + if (match_type == KeyMatchType::Match) { keymap.action(); - activeKeySequence.clear(); + active_key_sequence.clear(); return true; - } else if (matchType == KeyMatchType::Pending) { - foundPendingMatches = true; + } + if (match_type == KeyMatchType::Pending) { + found_pending_matches = true; } } - if (!foundPendingMatches) - activeKeySequence.clear(); + if (!found_pending_matches) + active_key_sequence.clear(); - if (isInsertableMode()) - return foundPendingMatches; + if (is_insertable_mode()) + return found_pending_matches; return true; } -bool KeymapEvaluator::isInsertableMode() { - return currentMode == KeyMode::Insert; +bool KeymapEvaluator::is_insertable_mode() { + return current_mode == KeyMode::Insert; } -const QList<KeyMap> *KeymapEvaluator::currentModeKeys() { - if (!modalKeys.contains(currentMode)) +const QList<KeyMap> *KeymapEvaluator::current_mode_keys() { + if (!modal_keys.contains(current_mode)) return new QList<KeyMap>(); - return &modalKeys[currentMode]; + return &modal_keys[current_mode]; } -KeyMode KeymapEvaluator::modeFromString(QString modeString) { - if (modeString == "n") +KeyMode KeymapEvaluator::mode_from_string(const QString &mode_string) { + if (mode_string == "n") return KeyMode::Normal; - if (modeString == "i") + if (mode_string == "i") return KeyMode::Insert; return KeyMode::Normal; } |
