Browse Source

minor-fix

- Support repeat in title jump in read mode;
- Trim input in VInsertLinkDialog;
- Rename VLineEdit to VMetaWordLineEdit;
Le Tan 8 years ago
parent
commit
b19b1d8079

+ 2 - 2
src/dialog/vdirinfodialog.cpp

@@ -2,7 +2,7 @@
 #include "vdirinfodialog.h"
 #include "vdirectory.h"
 #include "vconfigmanager.h"
-#include "vlineedit.h"
+#include "vmetawordlineedit.h"
 #include "utils/vutils.h"
 
 extern VConfigManager *g_config;
@@ -29,7 +29,7 @@ void VDirInfoDialog::setupUI()
         infoLabel = new QLabel(info);
     }
 
-    m_nameEdit = new VLineEdit(m_directory->getName());
+    m_nameEdit = new VMetaWordLineEdit(m_directory->getName());
     QValidator *validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp),
                                                  m_nameEdit);
     m_nameEdit->setValidator(validator);

+ 2 - 2
src/dialog/vdirinfodialog.h

@@ -4,7 +4,7 @@
 #include <QDialog>
 
 class QLabel;
-class VLineEdit;
+class VMetaWordLineEdit;
 class QDialogButtonBox;
 class QString;
 class VDirectory;
@@ -27,7 +27,7 @@ private slots:
 private:
     void setupUI();
 
-    VLineEdit *m_nameEdit;
+    VMetaWordLineEdit *m_nameEdit;
     QLabel *m_warnLabel;
     QDialogButtonBox *m_btnBox;
 

+ 2 - 2
src/dialog/veditsnippetdialog.cpp

@@ -2,7 +2,7 @@
 #include <QtWidgets>
 
 #include "utils/vutils.h"
-#include "vlineedit.h"
+#include "vmetawordlineedit.h"
 #include "vconfigmanager.h"
 #include "utils/vmetawordmanager.h"
 
@@ -33,7 +33,7 @@ void VEditSnippetDialog::setupUI(const QString &p_title, const QString &p_info)
     }
 
     // Name.
-    m_nameEdit = new VLineEdit(m_snippet.getName());
+    m_nameEdit = new VMetaWordLineEdit(m_snippet.getName());
     QValidator *validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp),
                                                  m_nameEdit);
     m_nameEdit->setValidator(validator);

+ 2 - 2
src/dialog/veditsnippetdialog.h

@@ -6,7 +6,7 @@
 
 #include "vsnippet.h"
 
-class VLineEdit;
+class VMetaWordLineEdit;
 class QLineEdit;
 class QLabel;
 class QDialogButtonBox;
@@ -51,7 +51,7 @@ private:
 
     QVector<QChar> getAvailableShortcuts() const;
 
-    VLineEdit *m_nameEdit;
+    VMetaWordLineEdit *m_nameEdit;
     QComboBox *m_typeCB;
     QComboBox *m_shortcutCB;
     QLineEdit *m_cursorMarkEdit;

+ 2 - 2
src/dialog/vfileinfodialog.cpp

@@ -4,7 +4,7 @@
 #include "vnotefile.h"
 #include "vconfigmanager.h"
 #include "utils/vutils.h"
-#include "vlineedit.h"
+#include "vmetawordlineedit.h"
 
 extern VConfigManager *g_config;
 
@@ -31,7 +31,7 @@ void VFileInfoDialog::setupUI(const QString &p_title, const QString &p_info)
 
     // File name.
     QString name = m_file->getName();
-    m_nameEdit = new VLineEdit(name);
+    m_nameEdit = new VMetaWordLineEdit(name);
     QValidator *validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp),
                                                  m_nameEdit);
     m_nameEdit->setValidator(validator);

+ 2 - 2
src/dialog/vfileinfodialog.h

@@ -4,7 +4,7 @@
 #include <QDialog>
 
 class QLabel;
-class VLineEdit;
+class VMetaWordLineEdit;
 class QDialogButtonBox;
 class QString;
 class VDirectory;
@@ -29,7 +29,7 @@ private slots:
 private:
     void setupUI(const QString &p_title, const QString &p_info);
 
-    VLineEdit *m_nameEdit;
+    VMetaWordLineEdit *m_nameEdit;
     QLabel *m_warnLabel;
     QDialogButtonBox *m_btnBox;
 

+ 2 - 2
src/dialog/vinsertimagedialog.cpp

@@ -5,7 +5,7 @@
 #include <QTimer>
 #include "vinsertimagedialog.h"
 #include "utils/vutils.h"
-#include "vlineedit.h"
+#include "vmetawordlineedit.h"
 #include "vdownloader.h"
 
 VInsertImageDialog::VInsertImageDialog(const QString &p_title,
@@ -71,7 +71,7 @@ void VInsertImageDialog::setupUI(const QString &p_title,
     browseBtn->setEnabled(m_browsable);
 
     QLabel *imageTitleLabel = new QLabel(tr("&Image title:"));
-    m_imageTitleEdit = new VLineEdit(p_imageTitle);
+    m_imageTitleEdit = new VMetaWordLineEdit(p_imageTitle);
     m_imageTitleEdit->selectAll();
     imageTitleLabel->setBuddy(m_imageTitleEdit);
     QValidator *validator = new QRegExpValidator(QRegExp(VUtils::c_imageTitleRegExp),

+ 2 - 2
src/dialog/vinsertimagedialog.h

@@ -8,7 +8,7 @@
 
 class QLabel;
 class QLineEdit;
-class VLineEdit;
+class VMetaWordLineEdit;
 class QPushButton;
 class QDialogButtonBox;
 class QTimer;
@@ -58,7 +58,7 @@ private:
 
     void fetchImageFromClipboard();
 
-    VLineEdit *m_imageTitleEdit;
+    VMetaWordLineEdit *m_imageTitleEdit;
     QLineEdit *m_pathEdit;
     QPushButton *browseBtn;
     QDialogButtonBox *m_btnBox;

+ 3 - 2
src/dialog/vinsertlinkdialog.cpp

@@ -2,7 +2,7 @@
 
 #include <QtWidgets>
 
-#include "vlineedit.h"
+#include "vmetawordlineedit.h"
 
 VInsertLinkDialog::VInsertLinkDialog(const QString &p_title,
                                      const QString &p_text,
@@ -37,7 +37,7 @@ void VInsertLinkDialog::setupUI(const QString &p_title,
         infoLabel->setWordWrap(true);
     }
 
-    m_linkTextEdit = new VLineEdit(p_linkText);
+    m_linkTextEdit = new VMetaWordLineEdit(p_linkText);
     m_linkTextEdit->selectAll();
 
     m_linkUrlEdit = new QLineEdit(p_linkUrl);
@@ -108,6 +108,7 @@ void VInsertLinkDialog::fetchLinkFromClipboard()
     }
 
     QString text = mimeData->text();
+    text = text.trimmed();
     if (text.isEmpty()) {
         return;
     }

+ 2 - 2
src/dialog/vinsertlinkdialog.h

@@ -4,7 +4,7 @@
 #include <QDialog>
 #include <QString>
 
-class VLineEdit;
+class VMetaWordLineEdit;
 class QLineEdit;
 class QDialogButtonBox;
 class QShowEvent;
@@ -40,7 +40,7 @@ private:
     // Infer link text/url from clipboard only when text and url are both empty.
     void fetchLinkFromClipboard();
 
-    VLineEdit *m_linkTextEdit;
+    VMetaWordLineEdit *m_linkTextEdit;
 
     QLineEdit *m_linkUrlEdit;
 

+ 2 - 2
src/dialog/vnewdirdialog.cpp

@@ -2,7 +2,7 @@
 #include "vnewdirdialog.h"
 #include "vdirectory.h"
 #include "vconfigmanager.h"
-#include "vlineedit.h"
+#include "vmetawordlineedit.h"
 #include "utils/vutils.h"
 
 extern VConfigManager *g_config;
@@ -31,7 +31,7 @@ void VNewDirDialog::setupUI()
     }
 
     QLabel *nameLabel = new QLabel(tr("Folder &name:"));
-    m_nameEdit = new VLineEdit(defaultName);
+    m_nameEdit = new VMetaWordLineEdit(defaultName);
     QValidator *validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp),
                                                  m_nameEdit);
     m_nameEdit->setValidator(validator);

+ 2 - 2
src/dialog/vnewdirdialog.h

@@ -4,7 +4,7 @@
 #include <QDialog>
 
 class QLabel;
-class VLineEdit;
+class VMetaWordLineEdit;
 class QDialogButtonBox;
 class QString;
 class VDirectory;
@@ -27,7 +27,7 @@ private slots:
 private:
     void setupUI();
 
-    VLineEdit *m_nameEdit;
+    VMetaWordLineEdit *m_nameEdit;
     QDialogButtonBox *m_btnBox;
 
     QLabel *m_warnLabel;

+ 3 - 3
src/dialog/vnewfiledialog.cpp

@@ -2,7 +2,7 @@
 #include "vnewfiledialog.h"
 #include "vconfigmanager.h"
 #include "vdirectory.h"
-#include "vlineedit.h"
+#include "vmetawordlineedit.h"
 #include "utils/vutils.h"
 #include "utils/vmetawordmanager.h"
 #include "utils/viconutils.h"
@@ -25,7 +25,7 @@ VNewFileDialog::VNewFileDialog(const QString &p_title,
 {
     setupUI(p_title, p_info, p_defaultName);
 
-    connect(m_nameEdit, &VLineEdit::textChanged, this, &VNewFileDialog::handleInputChanged);
+    connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VNewFileDialog::handleInputChanged);
 
     connect(m_templateCB, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
             this, &VNewFileDialog::handleCurrentTemplateChanged);
@@ -45,7 +45,7 @@ void VNewFileDialog::setupUI(const QString &p_title,
     }
 
     // Name.
-    m_nameEdit = new VLineEdit(p_defaultName);
+    m_nameEdit = new VMetaWordLineEdit(p_defaultName);
     QValidator *validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp),
                                                  m_nameEdit);
     m_nameEdit->setValidator(validator);

+ 2 - 2
src/dialog/vnewfiledialog.h

@@ -6,7 +6,7 @@
 #include "vconstants.h"
 
 class QLabel;
-class VLineEdit;
+class VMetaWordLineEdit;
 class QDialogButtonBox;
 class QCheckBox;
 class VDirectory;
@@ -50,7 +50,7 @@ private:
 
     void tryToSelectLastTemplate();
 
-    VLineEdit *m_nameEdit;
+    VMetaWordLineEdit *m_nameEdit;
 
     QComboBox *m_templateCB;
 

+ 2 - 2
src/dialog/vnewnotebookdialog.cpp

@@ -4,7 +4,7 @@
 #include "vconfigmanager.h"
 #include "utils/vutils.h"
 #include "vnotebook.h"
-#include "vlineedit.h"
+#include "vmetawordlineedit.h"
 
 extern VConfigManager *g_config;
 
@@ -35,7 +35,7 @@ void VNewNotebookDialog::setupUI(const QString &p_title, const QString &p_info)
     }
 
     QLabel *nameLabel = new QLabel(tr("Notebook &name:"));
-    m_nameEdit = new VLineEdit(defaultName);
+    m_nameEdit = new VMetaWordLineEdit(defaultName);
     QValidator *validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp),
                                                  m_nameEdit);
     m_nameEdit->setValidator(validator);

+ 2 - 2
src/dialog/vnewnotebookdialog.h

@@ -6,7 +6,7 @@
 
 class QLabel;
 class QLineEdit;
-class VLineEdit;
+class VMetaWordLineEdit;
 class QPushButton;
 class QDialogButtonBox;
 class VNotebook;
@@ -53,7 +53,7 @@ private:
     // Returns true if name or path is modified.
     bool autoComplete();
 
-    VLineEdit *m_nameEdit;
+    VMetaWordLineEdit *m_nameEdit;
     QLineEdit *pathEdit;
     QPushButton *browseBtn;
     QLabel *m_warnLabel;

+ 2 - 2
src/dialog/vnotebookinfodialog.cpp

@@ -3,7 +3,7 @@
 #include "vnotebook.h"
 #include "utils/vutils.h"
 #include "vconfigmanager.h"
-#include "vlineedit.h"
+#include "vmetawordlineedit.h"
 
 extern VConfigManager *g_config;
 
@@ -30,7 +30,7 @@ void VNotebookInfoDialog::setupUI(const QString &p_title, const QString &p_info)
         infoLabel = new QLabel(p_info);
     }
 
-    m_nameEdit = new VLineEdit(m_notebook->getName());
+    m_nameEdit = new VMetaWordLineEdit(m_notebook->getName());
     QValidator *validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp),
                                                  m_nameEdit);
     m_nameEdit->setValidator(validator);

+ 2 - 2
src/dialog/vnotebookinfodialog.h

@@ -6,7 +6,7 @@
 
 class QLabel;
 class QLineEdit;
-class VLineEdit;
+class VMetaWordLineEdit;
 class QDialogButtonBox;
 class QString;
 class VNotebook;
@@ -39,7 +39,7 @@ private:
 
     const VNotebook *m_notebook;
 
-    VLineEdit *m_nameEdit;
+    VMetaWordLineEdit *m_nameEdit;
     QLineEdit *m_pathEdit;
     QLineEdit *m_imageFolderEdit;
     // Read-only.

+ 76 - 13
src/resources/markdown_template.js

@@ -146,6 +146,9 @@ window.onscroll = function() {
     content.setHeader(curHeader ? curHeader : "");
 };
 
+// Used to record the repeat token of user input.
+var repeatToken = 0;
+
 document.onkeydown = function(e) {
     // Need to clear pending kyes.
     var clear = true;
@@ -174,20 +177,73 @@ document.onkeydown = function(e) {
         clear = false;
         break;
 
+    // 0 - 9.
+    case 48:
+    case 49:
+    case 50:
+    case 51:
+    case 52:
+    case 53:
+    case 54:
+    case 55:
+    case 56:
+    case 57:
+    case 96:
+    case 97:
+    case 98:
+    case 99:
+    case 100:
+    case 101:
+    case 102:
+    case 103:
+    case 104:
+    case 105:
+    {
+        if (pendingKeys.length != 0) {
+            accept = false;
+            break;
+        }
+
+        var num = key >= 96 ? key - 96 : key - 48;
+        repeatToken = repeatToken * 10 + num;
+        clear = false;
+        break;
+    }
+
     case 74: // J
-        window.scrollBy(0, 100);
+        if (!ctrl && !shift) {
+            window.scrollBy(0, 100);
+            break;
+        }
+
+        accept = false;
         break;
 
     case 75: // K
-        window.scrollBy(0, -100);
+        if (!ctrl && !shift) {
+            window.scrollBy(0, -100);
+            break;
+        }
+
+        accept = false;
         break;
 
     case 72: // H
-        window.scrollBy(-100, 0);
+        if (!ctrl && !shift) {
+            window.scrollBy(-100, 0);
+            break;
+        }
+
+        accept = false;
         break;
 
     case 76: // L
-        window.scrollBy(100, 0);
+        if (!ctrl && !shift) {
+            window.scrollBy(100, 0);
+            break;
+        }
+
+        accept = false;
         break;
 
     case 71: // G
@@ -198,7 +254,7 @@ document.onkeydown = function(e) {
                 window.scrollTo(scrollLeft, scrollHeight);
                 break;
             }
-        } else {
+        } else if (!ctrl) {
             if (pendingKeys.length == 0) {
                 // First g, pend it.
                 pendingKeys.push({
@@ -245,17 +301,19 @@ document.onkeydown = function(e) {
         break;
 
     case 219: // [ or {
+    {
+        var repeat = repeatToken < 1 ? 1 : repeatToken;
         if (shift) {
             // {
             if (pendingKeys.length == 1) {
                 var pendKey = pendingKeys[0];
                 if (pendKey.key == key && !pendKey.shift && !pendKey.ctrl) {
                     // [{, jump to previous title at a higher level.
-                    jumpTitle(false, -1, 1);
+                    jumpTitle(false, -1, repeat);
                     break;
                 }
             }
-        } else {
+        } else if (!ctrl) {
             // [
             if (pendingKeys.length == 0) {
                 // First [, pend it.
@@ -271,11 +329,11 @@ document.onkeydown = function(e) {
                 var pendKey = pendingKeys[0];
                 if (pendKey.key == key && !pendKey.shift && !pendKey.ctrl) {
                     // [[, jump to previous title.
-                    jumpTitle(false, 1, 1);
+                    jumpTitle(false, 1, repeat);
                     break;
                 } else if (pendKey.key == 221 && !pendKey.shift && !pendKey.ctrl) {
                     // ][, jump to next title at the same level.
-                    jumpTitle(true, 0, 1);
+                    jumpTitle(true, 0, repeat);
                     break;
                 }
             }
@@ -283,19 +341,22 @@ document.onkeydown = function(e) {
 
         accept = false;
         break;
+    }
 
     case 221: // ] or }
+    {
+        var repeat = repeatToken < 1 ? 1 : repeatToken;
         if (shift) {
             // }
             if (pendingKeys.length == 1) {
                 var pendKey = pendingKeys[0];
                 if (pendKey.key == key && !pendKey.shift && !pendKey.ctrl) {
                     // ]}, jump to next title at a higher level.
-                    jumpTitle(true, -1, 1);
+                    jumpTitle(true, -1, repeat);
                     break;
                 }
             }
-        } else {
+        } else if (!ctrl) {
             // ]
             if (pendingKeys.length == 0) {
                 // First ], pend it.
@@ -311,11 +372,11 @@ document.onkeydown = function(e) {
                 var pendKey = pendingKeys[0];
                 if (pendKey.key == key && !pendKey.shift && !pendKey.ctrl) {
                     // ]], jump to next title.
-                    jumpTitle(true, 1, 1);
+                    jumpTitle(true, 1, repeat);
                     break;
                 } else if (pendKey.key == 219 && !pendKey.shift && !pendKey.ctrl) {
                     // [], jump to previous title at the same level.
-                    jumpTitle(false, 0, 1);
+                    jumpTitle(false, 0, repeat);
                     break;
                 }
             }
@@ -323,6 +384,7 @@ document.onkeydown = function(e) {
 
         accept = false;
         break;
+    }
 
     default:
         accept = false;
@@ -330,6 +392,7 @@ document.onkeydown = function(e) {
     }
 
     if (clear) {
+        repeatToken = 0;
         pendingKeys = [];
     }
 

+ 2 - 2
src/src.pro

@@ -79,7 +79,7 @@ SOURCES += main.cpp\
     vfilesessioninfo.cpp \
     vtableofcontent.cpp \
     utils/vmetawordmanager.cpp \
-    vlineedit.cpp \
+    vmetawordlineedit.cpp \
     dialog/vinsertlinkdialog.cpp \
     vplaintextedit.cpp \
     vimageresourcemanager.cpp \
@@ -171,7 +171,7 @@ HEADERS  += vmainwindow.h \
     vfilesessioninfo.h \
     vtableofcontent.h \
     utils/vmetawordmanager.h \
-    vlineedit.h \
+    vmetawordlineedit.h \
     dialog/vinsertlinkdialog.h \
     vplaintextedit.h \
     vimageresourcemanager.h \

+ 7 - 8
src/vlineedit.cpp → src/vmetawordlineedit.cpp

@@ -1,4 +1,4 @@
-#include "vlineedit.h"
+#include "vmetawordlineedit.h"
 
 #include <QDebug>
 #include <QToolTip>
@@ -8,22 +8,21 @@
 extern VMetaWordManager *g_mwMgr;
 
 
-VLineEdit::VLineEdit(QWidget *p_parent)
+VMetaWordLineEdit::VMetaWordLineEdit(QWidget *p_parent)
     : QLineEdit(p_parent)
 {
     init();
 }
 
-VLineEdit::VLineEdit(const QString &p_contents, QWidget *p_parent)
+VMetaWordLineEdit::VMetaWordLineEdit(const QString &p_contents, QWidget *p_parent)
     : QLineEdit(p_contents, p_parent)
 {
     init();
 }
 
-void VLineEdit::handleTextChanged(const QString &p_text)
+void VMetaWordLineEdit::handleTextChanged(const QString &p_text)
 {
     m_evaluatedText = g_mwMgr->evaluate(p_text);
-    qDebug() << "evaluate text:" << m_evaluatedText;
 
     if (m_evaluatedText == p_text) {
         return;
@@ -34,15 +33,15 @@ void VLineEdit::handleTextChanged(const QString &p_text)
     QToolTip::showText(pos, m_evaluatedText, this);
 }
 
-void VLineEdit::init()
+void VMetaWordLineEdit::init()
 {
     m_evaluatedText = g_mwMgr->evaluate(text());
 
     connect(this, &QLineEdit::textChanged,
-            this, &VLineEdit::handleTextChanged);
+            this, &VMetaWordLineEdit::handleTextChanged);
 }
 
-const QString &VLineEdit::getEvaluatedText() const
+const QString &VMetaWordLineEdit::getEvaluatedText() const
 {
     return m_evaluatedText;
 }

+ 6 - 6
src/vlineedit.h → src/vmetawordlineedit.h

@@ -1,17 +1,17 @@
-#ifndef VLINEEDIT_H
-#define VLINEEDIT_H
+#ifndef VMETAWORDLINEEDIT_H
+#define VMETAWORDLINEEDIT_H
 
 #include <QLineEdit>
 
 
 // QLineEdit with meta word support.
-class VLineEdit : public QLineEdit
+class VMetaWordLineEdit : public QLineEdit
 {
     Q_OBJECT
 public:
-    explicit VLineEdit(QWidget *p_parent = nullptr);
+    explicit VMetaWordLineEdit(QWidget *p_parent = nullptr);
 
-    VLineEdit(const QString &p_contents, QWidget *p_parent = Q_NULLPTR);
+    VMetaWordLineEdit(const QString &p_contents, QWidget *p_parent = Q_NULLPTR);
 
     // Return the evaluated text.
     const QString &getEvaluatedText() const;
@@ -26,4 +26,4 @@ private:
     QString m_evaluatedText;
 };
 
-#endif // VLINEEDIT_H
+#endif // VMETAWORDLINEEDIT_H