1 | /* |
---|---|
2 | SPDX-FileCopyrightText: KDE Developers |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #include "completionrecorder.h" |
8 | #include "katepartdebug.h" |
9 | #include "lastchangerecorder.h" |
10 | #include "macrorecorder.h" |
11 | #include "vimode/definitions.h" |
12 | #include <vimode/inputmodemanager.h> |
13 | |
14 | #include <QKeyEvent> |
15 | |
16 | using namespace KateVi; |
17 | |
18 | CompletionRecorder::CompletionRecorder(InputModeManager *viInputModeManager) |
19 | : m_viInputModeManager(viInputModeManager) |
20 | { |
21 | } |
22 | |
23 | CompletionRecorder::~CompletionRecorder() = default; |
24 | |
25 | void CompletionRecorder::logCompletionEvent(const Completion &completion) |
26 | { |
27 | // Ctrl-space is a special code that means: if you're replaying a macro, fetch and execute |
28 | // the next logged completion. |
29 | static const QKeyEvent CompletionEvent(QKeyEvent::KeyPress, Qt::Key_Space, CONTROL_MODIFIER, QStringLiteral(" ")); |
30 | |
31 | if (m_viInputModeManager->macroRecorder()->isRecording()) { |
32 | m_viInputModeManager->macroRecorder()->record(event: CompletionEvent); |
33 | m_currentMacroCompletionsLog.append(t: completion); |
34 | } |
35 | |
36 | m_viInputModeManager->lastChangeRecorder()->record(event: CompletionEvent); |
37 | m_currentChangeCompletionsLog.append(t: completion); |
38 | } |
39 | |
40 | void CompletionRecorder::start() |
41 | { |
42 | m_currentMacroCompletionsLog.clear(); |
43 | } |
44 | |
45 | CompletionList CompletionRecorder::stop() |
46 | { |
47 | return m_currentMacroCompletionsLog; |
48 | } |
49 | |
50 | void CompletionRecorder::clearCurrentChangeCompletionsLog() |
51 | { |
52 | m_currentChangeCompletionsLog.clear(); |
53 | } |
54 | |
55 | CompletionList CompletionRecorder::currentChangeCompletionsLog() |
56 | { |
57 | return m_currentChangeCompletionsLog; |
58 | } |
59 |