7#include "macrorecorder.h"
8#include "completionrecorder.h"
9#include "completionreplayer.h"
10#include "globalstate.h"
12#include "lastchangerecorder.h"
14#include <vimode/inputmodemanager.h>
15#include <vimode/keymapper.h>
22using namespace KateVi;
24MacroRecorder::MacroRecorder(InputModeManager *viInputModeManager)
25 : m_viInputModeManager(viInputModeManager)
26 , m_isRecording(false)
27 , m_macrosBeingReplayedCount(0)
28 , m_lastPlayedMacroRegister(
QChar::Null)
32void MacroRecorder::start(
const QChar ¯oRegister)
34 Q_ASSERT(!m_isRecording);
36 m_register = macroRegister;
37 m_viInputModeManager->globalState()->macros()->remove(macroRegister);
39 m_viInputModeManager->completionRecorder()->start();
42void MacroRecorder::stop()
44 Q_ASSERT(m_isRecording);
45 m_isRecording =
false;
46 CompletionList completions = m_viInputModeManager->completionRecorder()->stop();
47 m_viInputModeManager->globalState()->macros()->store(m_register, m_eventsLog, completions);
50bool MacroRecorder::isRecording()
const
55void MacroRecorder::record(
const QKeyEvent &event)
57 if (isRepeatOfLastShortcutOverrideAsKeyPress(event, m_eventsLog)) {
60 m_eventsLog.append(KeyEvent::fromQKeyEvent(event));
63void MacroRecorder::dropLast()
66 Q_ASSERT(!m_eventsLog.isEmpty());
67 m_eventsLog.pop_back();
71void MacroRecorder::replay(
const QChar ¯oRegister)
73 const QChar reg = (macroRegister == LastPlayedRegister) ? m_lastPlayedMacroRegister : macroRegister;
75 m_lastPlayedMacroRegister = reg;
76 const QString macroAsFeedableKeypresses = m_viInputModeManager->globalState()->macros()->get(reg);
78 std::shared_ptr<KeyMapper> mapper(
new KeyMapper(m_viInputModeManager, m_viInputModeManager->view()->doc()));
79 CompletionList completions = m_viInputModeManager->globalState()->macros()->getCompletions(reg);
81 m_macrosBeingReplayedCount++;
82 m_viInputModeManager->completionReplayer()->start(completions);
83 m_viInputModeManager->pushKeyMapper(mapper);
84 m_viInputModeManager->feedKeyPresses(macroAsFeedableKeypresses);
85 m_viInputModeManager->popKeyMapper();
86 m_viInputModeManager->completionReplayer()->stop();
87 m_macrosBeingReplayedCount--;
90bool MacroRecorder::isReplaying()
const
92 return m_macrosBeingReplayedCount > 0;