8#include "globalstate.h"
9#include "katedocument.h"
10#include "kateglobal.h"
11#include "macrorecorder.h"
13#include <vimode/inputmodemanager.h>
14#include <vimode/keymapper.h>
15#include <vimode/keyparser.h>
19using namespace KateVi;
22 : m_viInputModeManager(kateViInputModeManager)
25 m_mappingTimer =
new QTimer(
this);
26 m_doNotExpandFurtherMappings =
false;
28 m_doNotMapNextKeypress =
false;
29 m_numMappingsBeingExecuted = 0;
30 m_isPlayingBackRejectedKeys =
false;
31 connect(m_mappingTimer, &
QTimer::timeout,
this, &KeyMapper::mappingTimerTimeOut);
34void KeyMapper::executeMapping()
36 m_mappingKeys.clear();
37 m_mappingTimer->stop();
38 m_numMappingsBeingExecuted++;
39 const QString mappedKeypresses =
40 m_viInputModeManager->globalState()->mappings()->get(Mappings::mappingModeForCurrentViMode(m_viInputModeManager->inputAdapter()),
44 if (!m_viInputModeManager->globalState()->mappings()->isRecursive(Mappings::mappingModeForCurrentViMode(m_viInputModeManager->inputAdapter()),
45 m_fullMappingMatch)) {
46 m_doNotExpandFurtherMappings =
true;
49 m_viInputModeManager->feedKeyPresses(mappedKeypresses);
50 m_doNotExpandFurtherMappings =
false;
52 m_numMappingsBeingExecuted--;
55void KeyMapper::playBackRejectedKeys()
57 m_isPlayingBackRejectedKeys =
true;
58 const QString mappingKeys = m_mappingKeys;
59 m_mappingKeys.clear();
60 m_viInputModeManager->feedKeyPresses(mappingKeys);
61 m_isPlayingBackRejectedKeys =
false;
64void KeyMapper::setMappingTimeout(
int timeoutMS)
66 m_timeoutlen = timeoutMS;
69void KeyMapper::mappingTimerTimeOut()
71 if (!m_fullMappingMatch.isNull()) {
74 playBackRejectedKeys();
76 m_mappingKeys.clear();
79bool KeyMapper::handleKeypress(QChar key)
81 if (!m_doNotExpandFurtherMappings && !m_doNotMapNextKeypress && !m_isPlayingBackRejectedKeys) {
82 m_mappingKeys.append(key);
84 bool isPartialMapping =
false;
85 bool isFullMapping =
false;
86 m_fullMappingMatch.clear();
87 const auto mappingMode = Mappings::mappingModeForCurrentViMode(m_viInputModeManager->inputAdapter());
88 const auto mappings = m_viInputModeManager->globalState()->mappings()->getAll(mappingMode,
false,
true);
89 for (
const QString &mapping : mappings) {
90 if (mapping.startsWith(m_mappingKeys)) {
91 if (mapping == m_mappingKeys) {
93 m_fullMappingMatch = mapping;
95 isPartialMapping =
true;
99 if (isFullMapping && !isPartialMapping) {
105 if (isPartialMapping) {
108 m_mappingTimer->start(m_timeoutlen);
109 m_mappingTimer->setSingleShot(
true);
114 Q_ASSERT(!isPartialMapping && !isFullMapping);
115 const bool isUserKeypress = !m_viInputModeManager->macroRecorder()->isReplaying() && !isExecutingMapping();
116 if (isUserKeypress && m_mappingKeys.size() == 1) {
133 m_mappingKeys.clear();
136 playBackRejectedKeys();
140 m_doNotMapNextKeypress =
false;
144void KeyMapper::setDoNotMapNextKeypress()
146 m_doNotMapNextKeypress =
true;
149bool KeyMapper::isExecutingMapping()
const
151 return m_numMappingsBeingExecuted > 0;
154bool KeyMapper::isPlayingBackRejectedKeys()
const
156 return m_isPlayingBackRejectedKeys;
Backend of KTextEditor::Document related public KTextEditor interfaces.