Skip to content

Commit

Permalink
Making it so mouse interaction only tracks one mouse button at a time.
Browse files Browse the repository at this point in the history
So if you the user is dragging with a middle mouse button, then right and left clicks are ignored.
Fixes (long standing) issue #192 ... I hope!
  • Loading branch information
eteran committed Jul 10, 2024
1 parent c51fcc0 commit a2f869f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/TextArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -1350,6 +1379,7 @@ void TextArea::mouseReleaseEvent(QMouseEvent *event) {
break;
}
break;

default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/TextArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a2f869f

Please sign in to comment.