diff --git a/src/utils/vvim.cpp b/src/utils/vvim.cpp index 4c73fbca..42730bd9 100644 --- a/src/utils/vvim.cpp +++ b/src/utils/vvim.cpp @@ -186,6 +186,8 @@ VVim::VVim(VEditor *p_editor) this, &VVim::handleMouseMoved); connect(m_editor->object(), &VEditorObject::mouseReleased, this, &VVim::handleMouseReleased); + connect(m_editor->object(), &VEditorObject::mouseDoubleClicked, + this, &VVim::handleMouseDoubleClicked); } void VVim::initLeaderKey() @@ -6357,12 +6359,17 @@ void VVim::amendCursorPosition() void VVim::handleMousePressed(QMouseEvent *p_event) { Q_UNUSED(p_event); - QTextCursor cursor = m_editor->textCursorW(); if ((checkMode(VimMode::Visual) || checkMode(VimMode::VisualLine)) && p_event->buttons() != Qt::RightButton) { setMode(VimMode::Normal); - } else if (checkMode(VimMode::Normal)) { - if (cursor.hasSelection()) { + } +} + +void VVim::handleMouseDoubleClicked(QMouseEvent *p_event) +{ + Q_UNUSED(p_event); + if (checkMode(VimMode::Normal)) { + if (m_editor->textCursorW().hasSelection()) { setMode(VimMode::Visual, false); maintainSelectionInVisualMode(); } diff --git a/src/utils/vvim.h b/src/utils/vvim.h index 978ac711..8ce60f69 100644 --- a/src/utils/vvim.h +++ b/src/utils/vvim.h @@ -251,6 +251,8 @@ private slots: void handleMouseReleased(QMouseEvent *p_event); + void handleMouseDoubleClicked(QMouseEvent *p_event); + // When we display cursor as block, it makes no sense to put cursor at the // end of line. void amendCursorPosition(); diff --git a/src/veditor.h b/src/veditor.h index ed0d6fe7..9baa6cd0 100644 --- a/src/veditor.h +++ b/src/veditor.h @@ -598,6 +598,8 @@ signals: void mouseReleased(QMouseEvent *p_event); + void mouseDoubleClicked(QMouseEvent *p_event); + void cursorPositionChanged(); private slots: diff --git a/src/vmdeditor.cpp b/src/vmdeditor.cpp index 18bc14c4..9893caf5 100644 --- a/src/vmdeditor.cpp +++ b/src/vmdeditor.cpp @@ -426,6 +426,13 @@ void VMdEditor::mousePressEvent(QMouseEvent *p_event) emit m_object->mousePressed(p_event); } +void VMdEditor::mouseDoubleClickEvent(QMouseEvent *p_event) +{ + VTextEdit::mouseDoubleClickEvent(p_event); + + emit m_object->mouseDoubleClicked(p_event); +} + void VMdEditor::mouseReleaseEvent(QMouseEvent *p_event) { if (handleMouseReleaseEvent(p_event)) { diff --git a/src/vmdeditor.h b/src/vmdeditor.h index 5a10d6da..a44f773b 100644 --- a/src/vmdeditor.h +++ b/src/vmdeditor.h @@ -235,6 +235,8 @@ protected: void mouseMoveEvent(QMouseEvent *p_event) Q_DECL_OVERRIDE; + void mouseDoubleClickEvent(QMouseEvent *p_event) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE; bool canInsertFromMimeData(const QMimeData *p_source) const Q_DECL_OVERRIDE;