Editor: support Ctrl+Shift+V to paste as plain text

This commit is contained in:
Le Tan 2018-10-09 21:04:33 +08:00
parent 6d1830ad86
commit 43fcdd502a
4 changed files with 37 additions and 0 deletions

View File

@ -429,6 +429,8 @@ OpenViaDefaultProgram=F12
FullScreen=F11
; Universal Entry
UniversalEntry=Ctrl+G
; Paste as plain text
PastePlainText=Ctrl+Shift+V
[captain_mode_shortcuts]
; Define shortcuts in Captain mode here.

View File

@ -105,6 +105,15 @@ void VEditor::init()
m_config.init(QFontMetrics(m_editor->font()), false);
updateEditConfig();
// Init shortcuts.
QKeySequence keySeq(g_config->getShortcutKeySequence("PastePlainText"));
QShortcut *pastePlainTextShortcut = new QShortcut(keySeq, m_editor);
pastePlainTextShortcut->setContext(Qt::WidgetShortcut);
QObject::connect(pastePlainTextShortcut, &QShortcut::activated,
m_object, [this]() {
pastePlainText();
});
}
void VEditor::labelTimerTimeout()
@ -1681,3 +1690,18 @@ void VEditor::nextMatch(bool p_forward)
m_findInfo.m_end);
}
}
void VEditor::pastePlainText()
{
if (!m_file || !m_file->isModifiable()) {
return;
}
QClipboard *clipboard = QApplication::clipboard();
QString text(clipboard->text());
if (text.isEmpty()) {
return;
}
m_editOps->insertText(text);
}

View File

@ -270,6 +270,9 @@ protected:
void addTempFile(const QString &p_file);
// Paste plain text.
void pastePlainText();
QWidget *m_editor;
VEditorObject *m_object;

View File

@ -367,6 +367,14 @@ void VMdEditor::contextMenuEvent(QContextMenuEvent *p_event)
if (mimeData->hasHtml()) {
initPasteAfterParseMenu(pasteAct, menu.data());
}
QAction *pptAct = new QAction(tr("Paste As Plain Text"), menu.data());
VUtils::fixTextWithShortcut(pptAct, "PastePlainText");
connect(pptAct, &QAction::triggered,
this, [this]() {
pastePlainText();
});
insertActionAfter(pasteAct, pptAct, menu.data());
}
if (!textCursor().hasSelection()) {