-
Notifications
You must be signed in to change notification settings - Fork 63
/
fake_vim_wrapper.cpp
54 lines (47 loc) · 1.86 KB
/
fake_vim_wrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "fake_vim_wrapper.h"
#include "fakevimactions.h"
#include "fakevimsavedaction.h"
#include <QStandardPaths>
#include "plog/Log.h"
FakeVimWrapper CreateFakeVimWrapper(PlainTextEdit *editor, QMainWindow *mainWindow)
{
FakeVimWrapper retVal;
// Create FakeVimHandler instance which will emulate Vim behavior in editor widget.
retVal.handler.reset(new FakeVim::Internal::FakeVimHandler(editor, 0));
auto *handlerPtr = retVal.handler.get();
retVal.proxy.reset(connectSignals(handlerPtr, mainWindow, editor));
QObject::connect(retVal.proxy.get(), &Proxy::handleInput,
retVal.handler.get(), [handlerPtr] (const QString &text) {
handlerPtr->handleInput(text);
});
initHandler(handlerPtr);
// Load vimrc if it exists
QString vimrc = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
#ifdef Q_OS_WIN
+ QLatin1String("/_encryptpad/vimrc");
#else
+ QLatin1String("/.encryptpad/vimrc");
#endif
if (QFile::exists(vimrc))
{
handlerPtr->handleCommand(QLatin1String("source ") + vimrc);
}
else
{
// Set some Vim options.
handlerPtr->handleCommand(QLatin1String("set expandtab"));
handlerPtr->handleCommand(QLatin1String("set shiftwidth=4"));
handlerPtr->handleCommand(QLatin1String("set tabstop=4"));
handlerPtr->handleCommand(QLatin1String("set autoindent"));
handlerPtr->handleCommand(QLatin1String("set smartindent"));
}
Utils::SavedAction *fakeVimAction = theFakeVimSetting(FakeVim::Internal::FakeVimSettingsCode::ConfigRelativeNumber);
fakeVimAction->valueChanged.connect(
[editor](const QVariant &){
LOG_INFO << "relative numbers changed";
editor->updateLineNumberAreaWidth(0);
editor->updateLineNumberArea();
});
clearUndoRedo(editor);
return retVal;
}