Browse Source

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

Le Tan 7 years ago
parent
commit
43fcdd502a
4 changed files with 37 additions and 0 deletions
  1. 2 0
      src/resources/vnote.ini
  2. 24 0
      src/veditor.cpp
  3. 3 0
      src/veditor.h
  4. 8 0
      src/vmdeditor.cpp

+ 2 - 0
src/resources/vnote.ini

@@ -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.

+ 24 - 0
src/veditor.cpp

@@ -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);
+}

+ 3 - 0
src/veditor.h

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

+ 8 - 0
src/vmdeditor.cpp

@@ -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()) {