Browse Source

add VLineEdit which supports Ctrl+H/W/U shortcuts

Le Tan 8 years ago
parent
commit
044b3d3c29

+ 0 - 1
src/dialog/vdeletenotebookdialog.h

@@ -5,7 +5,6 @@
 #include <QMessageBox>
 
 class QLabel;
-class QLineEdit;
 class QString;
 class QCheckBox;
 class QDialogButtonBox;

+ 1 - 1
src/dialog/vdirinfodialog.cpp

@@ -17,7 +17,7 @@ VDirInfoDialog::VDirInfoDialog(const QString &title,
 {
     setupUI();
 
-    connect(m_nameEdit, &QLineEdit::textChanged, this, &VDirInfoDialog::handleInputChanged);
+    connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VDirInfoDialog::handleInputChanged);
 
     handleInputChanged();
 }

+ 6 - 5
src/dialog/veditsnippetdialog.cpp

@@ -5,6 +5,7 @@
 #include "vmetawordlineedit.h"
 #include "vconfigmanager.h"
 #include "utils/vmetawordmanager.h"
+#include "vlineedit.h"
 
 extern VMetaWordManager *g_mwMgr;
 
@@ -65,11 +66,11 @@ void VEditSnippetDialog::setupUI(const QString &p_title, const QString &p_info)
     }
 
     // Cursor mark.
-    m_cursorMarkEdit = new QLineEdit(m_snippet.getCursorMark());
+    m_cursorMarkEdit = new VLineEdit(m_snippet.getCursorMark());
     m_cursorMarkEdit->setToolTip(tr("String in the content to mark the cursor position"));
 
     // Selection mark.
-    m_selectionMarkEdit = new QLineEdit(m_snippet.getSelectionMark());
+    m_selectionMarkEdit = new VLineEdit(m_snippet.getSelectionMark());
     m_selectionMarkEdit->setToolTip(tr("String in the content to be replaced with selected text"));
 
     // Auto Indent.
@@ -117,16 +118,16 @@ void VEditSnippetDialog::setupUI(const QString &p_title, const QString &p_info)
 
     setWindowTitle(p_title);
 
-    connect(m_nameEdit, &QLineEdit::textChanged,
+    connect(m_nameEdit, &VMetaWordLineEdit::textChanged,
             this, &VEditSnippetDialog::handleInputChanged);
 
     connect(m_typeCB, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
             this, &VEditSnippetDialog::handleInputChanged);
 
-    connect(m_cursorMarkEdit, &QLineEdit::textChanged,
+    connect(m_cursorMarkEdit, &VLineEdit::textChanged,
             this, &VEditSnippetDialog::handleInputChanged);
 
-    connect(m_selectionMarkEdit, &QLineEdit::textChanged,
+    connect(m_selectionMarkEdit, &VLineEdit::textChanged,
             this, &VEditSnippetDialog::handleInputChanged);
 
     connect(m_contentEdit, &QTextEdit::textChanged,

+ 3 - 3
src/dialog/veditsnippetdialog.h

@@ -7,7 +7,7 @@
 #include "vsnippet.h"
 
 class VMetaWordLineEdit;
-class QLineEdit;
+class VLineEdit;
 class QLabel;
 class QDialogButtonBox;
 class QComboBox;
@@ -54,8 +54,8 @@ private:
     VMetaWordLineEdit *m_nameEdit;
     QComboBox *m_typeCB;
     QComboBox *m_shortcutCB;
-    QLineEdit *m_cursorMarkEdit;
-    QLineEdit *m_selectionMarkEdit;
+    VLineEdit *m_cursorMarkEdit;
+    VLineEdit *m_selectionMarkEdit;
     QCheckBox *m_autoIndentCB;
     QTextEdit *m_contentEdit;
 

+ 2 - 2
src/dialog/vfileinfodialog.cpp

@@ -17,7 +17,7 @@ VFileInfoDialog::VFileInfoDialog(const QString &title,
 {
     setupUI(title, info);
 
-    connect(m_nameEdit, &QLineEdit::textChanged, this, &VFileInfoDialog::handleInputChanged);
+    connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VFileInfoDialog::handleInputChanged);
 
     handleInputChanged();
 }
@@ -45,7 +45,7 @@ void VFileInfoDialog::setupUI(const QString &p_title, const QString &p_info)
     m_nameEdit->setSelection(baseStart, baseLength);
 
     // Attachment folder.
-    QLineEdit *attachmentFolderEdit = new QLineEdit(m_file->getAttachmentFolder());
+    VLineEdit *attachmentFolderEdit = new VLineEdit(m_file->getAttachmentFolder());
     attachmentFolderEdit->setPlaceholderText(tr("Will be assigned when adding attachments"));
     attachmentFolderEdit->setToolTip(tr("The folder to hold attachments of this note"));
     attachmentFolderEdit->setReadOnly(true);

+ 4 - 3
src/dialog/vfindreplacedialog.cpp

@@ -2,6 +2,7 @@
 #include <QtWidgets>
 
 #include "utils/viconutils.h"
+#include "vlineedit.h"
 
 VFindReplaceDialog::VFindReplaceDialog(QWidget *p_parent)
     : QWidget(p_parent), m_options(0), m_replaceAvailable(true)
@@ -28,7 +29,7 @@ void VFindReplaceDialog::setupUI()
 
     // Find
     QLabel *findLabel = new QLabel(tr("Find:"));
-    m_findEdit = new QLineEdit();
+    m_findEdit = new VLineEdit();
     m_findEdit->setPlaceholderText(tr("Enter text to search"));
     findLabel->setBuddy(m_findEdit);
     m_findNextBtn = new QPushButton(tr("Find &Next"));
@@ -39,7 +40,7 @@ void VFindReplaceDialog::setupUI()
 
     // Replace
     QLabel *replaceLabel = new QLabel(tr("&Replace with:"));
-    m_replaceEdit = new QLineEdit();
+    m_replaceEdit = new VLineEdit();
     m_replaceEdit->setPlaceholderText(tr("Enter text to replace with"));
     replaceLabel->setBuddy(m_replaceEdit);
     m_replaceBtn = new QPushButton(tr("Replace"));
@@ -121,7 +122,7 @@ void VFindReplaceDialog::setupUI()
     // Signals
     connect(m_closeBtn, &QPushButton::clicked,
             this, &VFindReplaceDialog::closeDialog);
-    connect(m_findEdit, &QLineEdit::textChanged,
+    connect(m_findEdit, &VLineEdit::textChanged,
             this, &VFindReplaceDialog::handleFindTextChanged);
     connect(m_advancedBtn, &QPushButton::toggled,
             this, &VFindReplaceDialog::advancedBtnToggled);

+ 3 - 3
src/dialog/vfindreplacedialog.h

@@ -5,7 +5,7 @@
 #include <QString>
 #include "vconstants.h"
 
-class QLineEdit;
+class VLineEdit;
 class QPushButton;
 class QCheckBox;
 
@@ -52,8 +52,8 @@ private:
     uint m_options;
     bool m_replaceAvailable;
 
-    QLineEdit *m_findEdit;
-    QLineEdit *m_replaceEdit;
+    VLineEdit *m_findEdit;
+    VLineEdit *m_replaceEdit;
     QPushButton *m_findNextBtn;
     QPushButton *m_findPrevBtn;
     QPushButton *m_replaceBtn;

+ 4 - 3
src/dialog/vinsertimagedialog.cpp

@@ -7,6 +7,7 @@
 #include "utils/vutils.h"
 #include "vmetawordlineedit.h"
 #include "vdownloader.h"
+#include "vlineedit.h"
 
 VInsertImageDialog::VInsertImageDialog(const QString &p_title,
                                        const QString &p_imageTitle,
@@ -20,7 +21,7 @@ VInsertImageDialog::VInsertImageDialog(const QString &p_title,
 {
     setupUI(p_title, p_imageTitle, p_imagePath);
 
-    connect(m_imageTitleEdit, &QLineEdit::textChanged,
+    connect(m_imageTitleEdit, &VMetaWordLineEdit::textChanged,
             this, &VInsertImageDialog::handleInputChanged);
 
     if (m_browsable) {
@@ -30,7 +31,7 @@ VInsertImageDialog::VInsertImageDialog(const QString &p_title,
         connect(m_timer, &QTimer::timeout,
                 this, &VInsertImageDialog::handlePathEditChanged);
 
-        connect(m_pathEdit, &QLineEdit::textChanged,
+        connect(m_pathEdit, &VLineEdit::textChanged,
                 this, [this]() {
                     m_timer->stop();
 
@@ -64,7 +65,7 @@ void VInsertImageDialog::setupUI(const QString &p_title,
                                  const QString &p_imagePath)
 {
     QLabel *pathLabel = new QLabel(tr("&From:"));
-    m_pathEdit = new QLineEdit(p_imagePath);
+    m_pathEdit = new VLineEdit(p_imagePath);
     pathLabel->setBuddy(m_pathEdit);
     browseBtn = new QPushButton(tr("&Browse"));
     m_pathEdit->setReadOnly(!m_browsable);

+ 2 - 2
src/dialog/vinsertimagedialog.h

@@ -7,7 +7,7 @@
 #include <QByteArray>
 
 class QLabel;
-class QLineEdit;
+class VLineEdit;
 class VMetaWordLineEdit;
 class QPushButton;
 class QDialogButtonBox;
@@ -59,7 +59,7 @@ private:
     void fetchImageFromClipboard();
 
     VMetaWordLineEdit *m_imageTitleEdit;
-    QLineEdit *m_pathEdit;
+    VLineEdit *m_pathEdit;
     QPushButton *browseBtn;
     QDialogButtonBox *m_btnBox;
     QLabel *imagePreviewLabel;

+ 3 - 3
src/dialog/vinsertlinkdialog.cpp

@@ -40,7 +40,7 @@ void VInsertLinkDialog::setupUI(const QString &p_title,
     m_linkTextEdit = new VMetaWordLineEdit(p_linkText);
     m_linkTextEdit->selectAll();
 
-    m_linkUrlEdit = new QLineEdit(p_linkUrl);
+    m_linkUrlEdit = new VLineEdit(p_linkUrl);
     m_linkUrlEdit->setToolTip(tr("Absolute or relative path of the link"));
 
     QFormLayout *inputLayout = new QFormLayout();
@@ -71,9 +71,9 @@ void VInsertLinkDialog::setupUI(const QString &p_title,
     setLayout(mainLayout);
     setWindowTitle(p_title);
 
-    connect(m_linkTextEdit, &QLineEdit::textChanged,
+    connect(m_linkTextEdit, &VMetaWordLineEdit::textChanged,
             this, &VInsertLinkDialog::handleInputChanged);
-    connect(m_linkUrlEdit, &QLineEdit::textChanged,
+    connect(m_linkUrlEdit, &VLineEdit::textChanged,
             this, &VInsertLinkDialog::handleInputChanged);
 }
 

+ 2 - 2
src/dialog/vinsertlinkdialog.h

@@ -5,7 +5,7 @@
 #include <QString>
 
 class VMetaWordLineEdit;
-class QLineEdit;
+class VLineEdit;
 class QDialogButtonBox;
 class QShowEvent;
 
@@ -42,7 +42,7 @@ private:
 
     VMetaWordLineEdit *m_linkTextEdit;
 
-    QLineEdit *m_linkUrlEdit;
+    VLineEdit *m_linkUrlEdit;
 
     QDialogButtonBox *m_btnBox;
 };

+ 1 - 1
src/dialog/vnewdirdialog.cpp

@@ -17,7 +17,7 @@ VNewDirDialog::VNewDirDialog(const QString &title,
 {
     setupUI();
 
-    connect(m_nameEdit, &QLineEdit::textChanged, this, &VNewDirDialog::handleInputChanged);
+    connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VNewDirDialog::handleInputChanged);
 
     handleInputChanged();
 }

+ 5 - 5
src/dialog/vnewnotebookdialog.cpp

@@ -19,8 +19,8 @@ VNewNotebookDialog::VNewNotebookDialog(const QString &title, const QString &info
 {
     setupUI(title, info);
 
-    connect(m_nameEdit, &QLineEdit::textChanged, this, &VNewNotebookDialog::handleInputChanged);
-    connect(pathEdit, &QLineEdit::textChanged, this, &VNewNotebookDialog::handleInputChanged);
+    connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VNewNotebookDialog::handleInputChanged);
+    connect(pathEdit, &VLineEdit::textChanged, this, &VNewNotebookDialog::handleInputChanged);
     connect(browseBtn, &QPushButton::clicked, this, &VNewNotebookDialog::handleBrowseBtnClicked);
 
     handleInputChanged();
@@ -42,12 +42,12 @@ void VNewNotebookDialog::setupUI(const QString &p_title, const QString &p_info)
     nameLabel->setBuddy(m_nameEdit);
 
     QLabel *pathLabel = new QLabel(tr("Notebook &root folder:"));
-    pathEdit = new QLineEdit(defaultPath);
+    pathEdit = new VLineEdit(defaultPath);
     pathLabel->setBuddy(pathEdit);
     browseBtn = new QPushButton(tr("&Browse"));
 
     QLabel *imageFolderLabel = new QLabel(tr("&Image folder:"));
-    m_imageFolderEdit = new QLineEdit();
+    m_imageFolderEdit = new VLineEdit();
     imageFolderLabel->setBuddy(m_imageFolderEdit);
     m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
                                             .arg(g_config->getImageFolder()));
@@ -58,7 +58,7 @@ void VNewNotebookDialog::setupUI(const QString &p_title, const QString &p_info)
     m_imageFolderEdit->setValidator(validator);
 
     QLabel *attachmentFolderLabel = new QLabel(tr("&Attachment folder:"));
-    m_attachmentFolderEdit = new QLineEdit();
+    m_attachmentFolderEdit = new VLineEdit();
     attachmentFolderLabel->setBuddy(m_attachmentFolderEdit);
     m_attachmentFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
                                                  .arg(g_config->getAttachmentFolder()));

+ 4 - 4
src/dialog/vnewnotebookdialog.h

@@ -5,7 +5,7 @@
 #include <QVector>
 
 class QLabel;
-class QLineEdit;
+class VLineEdit;
 class VMetaWordLineEdit;
 class QPushButton;
 class QDialogButtonBox;
@@ -54,11 +54,11 @@ private:
     bool autoComplete();
 
     VMetaWordLineEdit *m_nameEdit;
-    QLineEdit *pathEdit;
+    VLineEdit *pathEdit;
     QPushButton *browseBtn;
     QLabel *m_warnLabel;
-    QLineEdit *m_imageFolderEdit;
-    QLineEdit *m_attachmentFolderEdit;
+    VLineEdit *m_imageFolderEdit;
+    VLineEdit *m_attachmentFolderEdit;
     QDialogButtonBox *m_btnBox;
 
     QString defaultName;

+ 5 - 5
src/dialog/vnotebookinfodialog.cpp

@@ -17,7 +17,7 @@ VNotebookInfoDialog::VNotebookInfoDialog(const QString &p_title,
 {
     setupUI(p_title, p_info);
 
-    connect(m_nameEdit, &QLineEdit::textChanged,
+    connect(m_nameEdit, &VMetaWordLineEdit::textChanged,
             this, &VNotebookInfoDialog::handleInputChanged);
 
     handleInputChanged();
@@ -36,11 +36,11 @@ void VNotebookInfoDialog::setupUI(const QString &p_title, const QString &p_info)
     m_nameEdit->setValidator(validator);
     m_nameEdit->selectAll();
 
-    m_pathEdit = new QLineEdit(m_notebook->getPath());
+    m_pathEdit = new VLineEdit(m_notebook->getPath());
     m_pathEdit->setReadOnly(true);
 
     // Image folder.
-    m_imageFolderEdit = new QLineEdit(m_notebook->getImageFolderConfig());
+    m_imageFolderEdit = new VLineEdit(m_notebook->getImageFolderConfig());
     m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
                                             .arg(g_config->getImageFolder()));
     m_imageFolderEdit->setToolTip(tr("Set the name of the folder to hold images of all the notes in this notebook "
@@ -50,14 +50,14 @@ void VNotebookInfoDialog::setupUI(const QString &p_title, const QString &p_info)
 
     // Attachment folder.
     Q_ASSERT(!m_notebook->getAttachmentFolder().isEmpty());
-    m_attachmentFolderEdit = new QLineEdit(m_notebook->getAttachmentFolder());
+    m_attachmentFolderEdit = new VLineEdit(m_notebook->getAttachmentFolder());
     m_attachmentFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
                                                  .arg(g_config->getAttachmentFolder()));
     m_attachmentFolderEdit->setToolTip(tr("The folder to hold attachments of all the notes in this notebook"));
     m_attachmentFolderEdit->setReadOnly(true);
 
     // Recycle bin folder.
-    QLineEdit *recycleBinFolderEdit = new QLineEdit(m_notebook->getRecycleBinFolder());
+    VLineEdit *recycleBinFolderEdit = new VLineEdit(m_notebook->getRecycleBinFolder());
     recycleBinFolderEdit->setReadOnly(true);
     recycleBinFolderEdit->setToolTip(tr("The folder to hold deleted files from within VNote of all the notes in this notebook"));
 

+ 4 - 4
src/dialog/vnotebookinfodialog.h

@@ -5,7 +5,7 @@
 #include <QVector>
 
 class QLabel;
-class QLineEdit;
+class VLineEdit;
 class VMetaWordLineEdit;
 class QDialogButtonBox;
 class QString;
@@ -40,10 +40,10 @@ private:
     const VNotebook *m_notebook;
 
     VMetaWordLineEdit *m_nameEdit;
-    QLineEdit *m_pathEdit;
-    QLineEdit *m_imageFolderEdit;
+    VLineEdit *m_pathEdit;
+    VLineEdit *m_imageFolderEdit;
     // Read-only.
-    QLineEdit *m_attachmentFolderEdit;
+    VLineEdit *m_attachmentFolderEdit;
     QLabel *m_warnLabel;
     QDialogButtonBox *m_btnBox;
     const QVector<VNotebook *> &m_notebooks;

+ 3 - 2
src/dialog/vorphanfileinfodialog.cpp

@@ -4,6 +4,7 @@
 #include "vorphanfile.h"
 #include "vconfigmanager.h"
 #include "utils/vutils.h"
+#include "vlineedit.h"
 
 extern VConfigManager *g_config;
 
@@ -12,7 +13,7 @@ VOrphanFileInfoDialog::VOrphanFileInfoDialog(const VOrphanFile *p_file, QWidget
 {
     setupUI();
 
-    connect(m_imageFolderEdit, &QLineEdit::textChanged,
+    connect(m_imageFolderEdit, &VLineEdit::textChanged,
             this, &VOrphanFileInfoDialog::handleInputChanged);
 
     handleInputChanged();
@@ -25,7 +26,7 @@ void VOrphanFileInfoDialog::setupUI()
     QLabel *fileLabel = new QLabel(m_file->fetchPath());
     topLayout->addRow(tr("File:"), fileLabel);
 
-    m_imageFolderEdit = new QLineEdit(m_file->getImageFolder());
+    m_imageFolderEdit = new VLineEdit(m_file->getImageFolder());
     m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)")
                                             .arg(g_config->getImageFolderExt()));
     QString imgFolderTip = tr("Set the path of the image folder to store images "

+ 2 - 2
src/dialog/vorphanfileinfodialog.h

@@ -5,7 +5,7 @@
 
 class VOrphanFile;
 class QDialogButtonBox;
-class QLineEdit;
+class VLineEdit;
 
 class VOrphanFileInfoDialog : public QDialog
 {
@@ -28,7 +28,7 @@ private:
     const VOrphanFile *m_file;
 
     QDialogButtonBox *m_btnBox;
-    QLineEdit *m_imageFolderEdit;
+    VLineEdit *m_imageFolderEdit;
 };
 
 #endif // VORPHANFILEINFODIALOG_H

+ 5 - 4
src/dialog/vsettingsdialog.cpp

@@ -4,6 +4,7 @@
 #include "vconfigmanager.h"
 #include "utils/vutils.h"
 #include "vconstants.h"
+#include "vlineedit.h"
 
 extern VConfigManager *g_config;
 
@@ -440,7 +441,7 @@ VNoteManagementTab::VNoteManagementTab(QWidget *p_parent)
     connect(m_customImageFolder, &QCheckBox::stateChanged,
             this, &VNoteManagementTab::customImageFolderChanged);
 
-    m_imageFolderEdit = new QLineEdit(this);
+    m_imageFolderEdit = new VLineEdit(this);
     m_imageFolderEdit->setPlaceholderText(tr("Name of the image folder"));
     m_imageFolderEdit->setToolTip(m_customImageFolder->toolTip());
     QValidator *validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp), this);
@@ -457,7 +458,7 @@ VNoteManagementTab::VNoteManagementTab(QWidget *p_parent)
     connect(m_customAttachmentFolder, &QCheckBox::stateChanged,
             this, &VNoteManagementTab::customAttachmentFolderChanged);
 
-    m_attachmentFolderEdit = new QLineEdit(this);
+    m_attachmentFolderEdit = new VLineEdit(this);
     m_attachmentFolderEdit->setPlaceholderText(tr("Name of the attachment folder"));
     m_attachmentFolderEdit->setToolTip(m_customAttachmentFolder->toolTip());
     validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp), this);
@@ -483,7 +484,7 @@ VNoteManagementTab::VNoteManagementTab(QWidget *p_parent)
     connect(m_customImageFolderExt, &QCheckBox::stateChanged,
             this, &VNoteManagementTab::customImageFolderExtChanged);
 
-    m_imageFolderEditExt = new QLineEdit(this);
+    m_imageFolderEditExt = new VLineEdit(this);
     m_imageFolderEditExt->setToolTip(m_customImageFolderExt->toolTip());
     m_imageFolderEditExt->setPlaceholderText(tr("Name of the image folder"));
 
@@ -689,7 +690,7 @@ VMarkdownTab::VMarkdownTab(QWidget *p_parent)
     zoomFactorLayout->addWidget(m_webZoomFactorSpin);
 
     // Color column.
-    m_colorColumnEdit = new QLineEdit();
+    m_colorColumnEdit = new VLineEdit();
     m_colorColumnEdit->setToolTip(tr("Specify the screen column in fenced code block "
                                      "which will be highlighted"));
     QValidator *validator = new QRegExpValidator(QRegExp("\\d+"), this);

+ 5 - 5
src/dialog/vsettingsdialog.h

@@ -10,7 +10,7 @@ class QComboBox;
 class QGroupBox;
 class QDoubleSpinBox;
 class QCheckBox;
-class QLineEdit;
+class VLineEdit;
 class QStackedLayout;
 class QListWidget;
 class QPlainTextEdit;
@@ -79,15 +79,15 @@ public:
 
     // Image folder.
     QCheckBox *m_customImageFolder;
-    QLineEdit *m_imageFolderEdit;
+    VLineEdit *m_imageFolderEdit;
 
     // Image folder of External File.
     QCheckBox *m_customImageFolderExt;
-    QLineEdit *m_imageFolderEditExt;
+    VLineEdit *m_imageFolderEditExt;
 
     // Attachment folder.
     QCheckBox *m_customAttachmentFolder;
-    QLineEdit *m_attachmentFolderEdit;
+    VLineEdit *m_attachmentFolderEdit;
 
 private slots:
     void customImageFolderChanged(int p_state);
@@ -125,7 +125,7 @@ public:
     QDoubleSpinBox *m_webZoomFactorSpin;
 
     // Color column in code block.
-    QLineEdit *m_colorColumnEdit;
+    VLineEdit *m_colorColumnEdit;
 
 private:
     bool loadOpenMode();

+ 4 - 4
src/lineeditdelegate.cpp

@@ -1,6 +1,6 @@
 #include "lineeditdelegate.h"
 
-#include <QLineEdit>
+#include "vlineedit.h"
 
 
 LineEditDelegate::LineEditDelegate(QObject *p_parent)
@@ -15,7 +15,7 @@ QWidget *LineEditDelegate::createEditor(QWidget *p_parent,
     Q_UNUSED(p_option);
     Q_UNUSED(p_index);
 
-    QLineEdit *edit = new QLineEdit(p_parent);
+    VLineEdit *edit = new VLineEdit(p_parent);
     return edit;
 }
 
@@ -23,7 +23,7 @@ void LineEditDelegate::setEditorData(QWidget *p_editor, const QModelIndex &p_ind
 {
     QString text = p_index.model()->data(p_index, Qt::EditRole).toString();
 
-    QLineEdit *edit = static_cast<QLineEdit *>(p_editor);
+    VLineEdit *edit = static_cast<VLineEdit *>(p_editor);
     edit->setText(text);
 }
 
@@ -31,7 +31,7 @@ void LineEditDelegate::setModelData(QWidget *p_editor,
                                     QAbstractItemModel *p_model,
                                     const QModelIndex &p_index) const
 {
-    QLineEdit *edit = static_cast<QLineEdit *>(p_editor);
+    VLineEdit *edit = static_cast<VLineEdit *>(p_editor);
 
     p_model->setData(p_index, edit->text(), Qt::EditRole);
 }

+ 4 - 2
src/src.pro

@@ -105,7 +105,8 @@ SOURCES += main.cpp\
     dialog/vtipsdialog.cpp \
     dialog/vcopytextashtmldialog.cpp \
     vwaitingwidget.cpp \
-    utils/vwebutils.cpp
+    utils/vwebutils.cpp \
+    vlineedit.cpp
 
 HEADERS  += vmainwindow.h \
     vdirectorytree.h \
@@ -197,7 +198,8 @@ HEADERS  += vmainwindow.h \
     dialog/vtipsdialog.h \
     dialog/vcopytextashtmldialog.h \
     vwaitingwidget.h \
-    utils/vwebutils.h
+    utils/vwebutils.h \
+    vlineedit.h
 
 RESOURCES += \
     vnote.qrc \

+ 2 - 1
src/vattachmentlist.cpp

@@ -10,6 +10,7 @@
 #include "dialog/vsortdialog.h"
 #include "utils/vimnavigationforwidget.h"
 #include "utils/viconutils.h"
+#include "vlineedit.h"
 
 extern VConfigManager *g_config;
 extern VMainWindow *g_mainWin;
@@ -413,7 +414,7 @@ void VAttachmentList::sortItems()
 
 void VAttachmentList::handleListItemCommitData(QWidget *p_itemEdit)
 {
-    QString text = reinterpret_cast<QLineEdit *>(p_itemEdit)->text();
+    QString text = reinterpret_cast<VLineEdit *>(p_itemEdit)->text();
     QListWidgetItem *item = m_attachmentList->currentItem();
     Q_ASSERT(item && item->text() == text);
 

+ 2 - 1
src/vexporter.cpp

@@ -22,6 +22,7 @@
 #include "vnote.h"
 #include "vmarkdownconverter.h"
 #include "vdocument.h"
+#include "vlineedit.h"
 
 extern VConfigManager *g_config;
 
@@ -51,7 +52,7 @@ void VExporter::setupUI()
 
     // Target file path.
     QLabel *pathLabel = new QLabel(tr("Target &path:"));
-    m_pathEdit = new QLineEdit();
+    m_pathEdit = new VLineEdit();
     pathLabel->setBuddy(m_pathEdit);
     m_browseBtn = new QPushButton(tr("&Browse"));
     connect(m_browseBtn, &QPushButton::clicked,

+ 2 - 2
src/vexporter.h

@@ -8,7 +8,7 @@
 
 class VWebView;
 class VFile;
-class QLineEdit;
+class VLineEdit;
 class QLabel;
 class QDialogButtonBox;
 class QPushButton;
@@ -99,7 +99,7 @@ private:
     ExportState m_state;
 
     QLabel *m_infoLabel;
-    QLineEdit *m_pathEdit;
+    VLineEdit *m_pathEdit;
     QPushButton *m_browseBtn;
     QLabel *m_layoutLabel;
     QPushButton *m_layoutBtn;

+ 74 - 0
src/vlineedit.cpp

@@ -0,0 +1,74 @@
+#include "vlineedit.h"
+
+#include <QKeyEvent>
+
+#include "utils/vutils.h"
+
+VLineEdit::VLineEdit(QWidget *p_parent)
+    : QLineEdit(p_parent)
+{
+}
+
+VLineEdit::VLineEdit(const QString &p_contents, QWidget *p_parent)
+    : QLineEdit(p_contents, p_parent)
+{
+}
+
+void VLineEdit::keyPressEvent(QKeyEvent *p_event)
+{
+    // Note that QKeyEvent starts with isAccepted() == true, so you do not
+    // need to call QKeyEvent::accept() - just do not call the base class
+    // implementation if you act upon the key.
+
+    bool accept = false;
+    int modifiers = p_event->modifiers();
+    switch (p_event->key()) {
+    case Qt::Key_H:
+        // Backspace.
+        if (VUtils::isControlModifierForVim(modifiers)) {
+            backspace();
+            accept = true;
+        }
+
+        break;
+
+    case Qt::Key_W:
+        // Delete one word backward.
+        if (VUtils::isControlModifierForVim(modifiers)) {
+            if (!hasSelectedText()) {
+                cursorWordBackward(true);
+            }
+
+            backspace();
+            accept = true;
+        }
+
+        break;
+
+    case Qt::Key_U:
+    {
+        if (VUtils::isControlModifierForVim(modifiers)) {
+            if (hasSelectedText()) {
+                backspace();
+            } else {
+                int pos = cursorPosition();
+                if (pos > 0) {
+                    cursorBackward(true, pos);
+                    backspace();
+                }
+            }
+
+            accept = true;
+        }
+
+        break;
+    }
+
+    default:
+        break;
+    }
+
+    if (!accept) {
+        QLineEdit::keyPressEvent(p_event);
+    }
+}

+ 19 - 0
src/vlineedit.h

@@ -0,0 +1,19 @@
+#ifndef VLINEEDIT_H
+#define VLINEEDIT_H
+
+#include <QLineEdit>
+
+
+class VLineEdit : public QLineEdit
+{
+    Q_OBJECT
+public:
+    explicit VLineEdit(QWidget *p_parent = nullptr);
+
+    VLineEdit(const QString &p_contents, QWidget *p_parent = nullptr);
+
+protected:
+    void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;
+};
+
+#endif // VLINEEDIT_H

+ 3 - 3
src/vmetawordlineedit.cpp

@@ -9,13 +9,13 @@ extern VMetaWordManager *g_mwMgr;
 
 
 VMetaWordLineEdit::VMetaWordLineEdit(QWidget *p_parent)
-    : QLineEdit(p_parent)
+    : VLineEdit(p_parent)
 {
     init();
 }
 
 VMetaWordLineEdit::VMetaWordLineEdit(const QString &p_contents, QWidget *p_parent)
-    : QLineEdit(p_contents, p_parent)
+    : VLineEdit(p_contents, p_parent)
 {
     init();
 }
@@ -37,7 +37,7 @@ void VMetaWordLineEdit::init()
 {
     m_evaluatedText = g_mwMgr->evaluate(text());
 
-    connect(this, &QLineEdit::textChanged,
+    connect(this, &VLineEdit::textChanged,
             this, &VMetaWordLineEdit::handleTextChanged);
 }
 

+ 3 - 3
src/vmetawordlineedit.h

@@ -1,11 +1,11 @@
 #ifndef VMETAWORDLINEEDIT_H
 #define VMETAWORDLINEEDIT_H
 
-#include <QLineEdit>
+#include "vlineedit.h"
 
 
-// QLineEdit with meta word support.
-class VMetaWordLineEdit : public QLineEdit
+// VLineEdit with meta word support.
+class VMetaWordLineEdit : public VLineEdit
 {
     Q_OBJECT
 public:

+ 3 - 3
src/vvimindicator.cpp

@@ -341,7 +341,7 @@ void VVimIndicator::triggerCommandLine(VVim::CommandLineType p_type)
 }
 
 VVimCmdLineEdit::VVimCmdLineEdit(QWidget *p_parent)
-    : QLineEdit(p_parent), m_type(VVim::CommandLineType::Invalid),
+    : VLineEdit(p_parent), m_type(VVim::CommandLineType::Invalid),
       m_registerPending(false), m_enableInputMethod(true)
 {
     // When user delete all the text, cancel command input.
@@ -432,7 +432,7 @@ QVariant VVimCmdLineEdit::inputMethodQuery(Qt::InputMethodQuery p_query) const
         return m_enableInputMethod;
     }
 
-    return QLineEdit::inputMethodQuery(p_query);
+    return VLineEdit::inputMethodQuery(p_query);
 }
 
 // See if @p_modifiers is Control which is different on macOs and Windows.
@@ -531,7 +531,7 @@ void VVimCmdLineEdit::keyPressEvent(QKeyEvent *p_event)
     }
 
 exit:
-    QLineEdit::keyPressEvent(p_event);
+    VLineEdit::keyPressEvent(p_event);
 }
 
 void VVimCmdLineEdit::focusOutEvent(QFocusEvent *p_event)

+ 2 - 2
src/vvimindicator.h

@@ -2,9 +2,9 @@
 #define VVIMINDICATOR_H
 
 #include <QWidget>
-#include <QLineEdit>
 #include <QPointer>
 #include "utils/vvim.h"
+#include "vlineedit.h"
 
 class QLabel;
 class VButtonWithWidget;
@@ -12,7 +12,7 @@ class QKeyEvent;
 class QFocusEvent;
 class VEditTab;
 
-class VVimCmdLineEdit : public QLineEdit
+class VVimCmdLineEdit : public VLineEdit
 {
     Q_OBJECT