vnote/src/veditoperations.cpp
Le Tan d2f61bc605 add shortcuts
1. `Ctrl + W`, `Ctrl + R`, `Ctrl + Q`, `Ctrl + S` for edit and view mode;
2. `Ctrl + E` to toggle expand view;
3. `Ctrl + N` to create note in current directory;
4. `Ctrl + H` in edit mode to delete previous char;
5. `Ctrl + W` in edit mode to delete till the start of previous word;
6. `Ctrl + U` in edit mode to delete till the start of current line;
7. `Tab`, `Shift + Tab` to indent or unindent selected lines;
8. `Ctrl + B`, `Ctrl + I` to make selected text bold or italic;

Signed-off-by: Le Tan <tamlokveer@gmail.com>
2016-12-18 22:26:01 +08:00

39 lines
1002 B
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)
: m_editor(p_editor), m_file(p_file), m_expandTab(false),
m_keyState(KeyState::Normal)
{
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(), ' ');
}
}