diff --git a/src/TextArea.cpp b/src/TextArea.cpp index 3de208c6..fd81a89c 100644 --- a/src/TextArea.cpp +++ b/src/TextArea.cpp @@ -1102,6 +1102,11 @@ void TextArea::focusOutEvent(QFocusEvent *event) { * @param event */ void TextArea::contextMenuEvent(QContextMenuEvent *event) { + + if (mouseButtonState_ != Qt::MouseButton::NoButton) { + return; + } + if (event->modifiers() != Qt::ControlModifier) { Q_EMIT customContextMenuRequested(mapToGlobal(event->pos())); } @@ -1185,6 +1190,11 @@ void TextArea::keyPressEvent(QKeyEvent *event) { */ void TextArea::mouseDoubleClickEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { + + if (mouseButtonState_ != Qt::MouseButton::NoButton) { + return; + } + if (!clickTracker(event, /*inDoubleClickHandler=*/true)) { return; } @@ -1261,6 +1271,14 @@ void TextArea::mouseMoveEvent(QMouseEvent *event) { */ void TextArea::mousePressEvent(QMouseEvent *event) { + // only accept one mouse button press at a time + if (mouseButtonState_ != Qt::MouseButton::NoButton) { + return; + } + + mouseButtonState_ = event->button(); + + if (event->button() == Qt::LeftButton) { switch (event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)) { case Qt::ShiftModifier | Qt::ControlModifier: @@ -1323,13 +1341,24 @@ void TextArea::mousePressEvent(QMouseEvent *event) { */ void TextArea::mouseReleaseEvent(QMouseEvent *event) { + // ignore key ups from buttons not currently known to be pressed + if(mouseButtonState_ != event->button()) { + return; + } + + mouseButtonState_ = Qt::MouseButton::NoButton; + switch (event->button()) { case Qt::LeftButton: - endDrag(); + if(dragState_ == PRIMARY_CLICKED) { + endDrag(); + } break; + case Qt::RightButton: endDrag(); break; + case Qt::MiddleButton: switch (event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)) { case Qt::ControlModifier: @@ -1350,6 +1379,7 @@ void TextArea::mouseReleaseEvent(QMouseEvent *event) { break; } break; + default: break; } diff --git a/src/TextArea.h b/src/TextArea.h index 42e1c827..61330cce 100644 --- a/src/TextArea.h +++ b/src/TextArea.h @@ -437,6 +437,7 @@ private Q_SLOTS: int64_t rectAnchor_ = 0; // Anchor for rectangular drag operations int wrapMargin_ = 0; void *highlightCBArg_ = nullptr; // Arg to unfinishedHighlightCB + Qt::MouseButton mouseButtonState_ = Qt::MouseButton::NoButton; private: BlockDragTypes dragType_; // style of block drag operation