mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00

After hitting `Ctrl+D` or keeping pressing `Ctrl+Alt`, VNote will enter Vim normal pending mode. 1. Support <num>h,j,k,l to move cursor around; TODO: Design a finite state machine to handle more Vim commands elegantly. Signed-off-by: Le Tan <tamlokveer@gmail.com>
39 lines
1.0 KiB
C++
39 lines
1.0 KiB
C++
#include <QTextCursor>
|
|
#include <QTextDocument>
|
|
#include <QFontMetrics>
|
|
#include "vedit.h"
|
|
#include "veditoperations.h"
|
|
#include "vconfigmanager.h"
|
|
|
|
extern VConfigManager vconfig;
|
|
|
|
VEditOperations::VEditOperations(VEdit *p_editor, VFile *p_file)
|
|
: QObject(p_editor), m_editor(p_editor), m_file(p_file), m_expandTab(false),
|
|
m_keyState(KeyState::Normal), m_pendingTime(2)
|
|
{
|
|
updateTabSettings();
|
|
}
|
|
|
|
void VEditOperations::insertTextAtCurPos(const QString &p_text)
|
|
{
|
|
QTextCursor cursor = m_editor->textCursor();
|
|
cursor.insertText(p_text);
|
|
m_editor->setTextCursor(cursor);
|
|
}
|
|
|
|
VEditOperations::~VEditOperations()
|
|
{
|
|
}
|
|
|
|
void VEditOperations::updateTabSettings()
|
|
{
|
|
if (vconfig.getTabStopWidth() > 0) {
|
|
QFontMetrics metrics(vconfig.getMdEditFont());
|
|
m_editor->setTabStopWidth(vconfig.getTabStopWidth() * metrics.width(' '));
|
|
}
|
|
m_expandTab = vconfig.getIsExpandTab();
|
|
if (m_expandTab && (vconfig.getTabStopWidth() > 0)) {
|
|
m_tabSpaces = QString(vconfig.getTabStopWidth(), ' ');
|
|
}
|
|
}
|