Skip to content

Commit

Permalink
Merge PR #6570: FIX(client): Prevent sending plain text on fast CTRL+…
Browse files Browse the repository at this point in the history
…V + ENTER
  • Loading branch information
Hartmnt authored Sep 28, 2024
2 parents 5782f61 + 3d1a1af commit fcd105c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/mumble/CustomElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ ChatbarTextEdit::ChatbarTextEdit(QWidget *p) : QTextEdit(p), iHistoryIndex(-1) {
bDefaultVisible = true;
setDefaultText(tr("<center>Type chat message here</center>"));
setAcceptDrops(true);

m_justPasted = false;
}

QSize ChatbarTextEdit::minimumSizeHint() const {
Expand Down Expand Up @@ -233,11 +235,12 @@ bool ChatbarTextEdit::event(QEvent *evt) {
const QString msg = toPlainText();
if (!msg.isEmpty()) {
addToHistory(msg);
if (kev->modifiers() & Qt::ControlModifier) {
if ((kev->modifiers() & Qt::ControlModifier) && !m_justPasted) {
emit ctrlEnterPressed(msg);
} else {
emit entered(msg);
}
m_justPasted = false;
}
return true;
}
Expand All @@ -256,12 +259,27 @@ bool ChatbarTextEdit::event(QEvent *evt) {
} else if (kev->key() == Qt::Key_Down && kev->modifiers() == Qt::ControlModifier) {
historyDown();
return true;
} else if (kev->key() == Qt::Key_V && (kev->modifiers() & Qt::ControlModifier)
&& (kev->modifiers() & Qt::ShiftModifier)) {
pasteAndSend_triggered();
return true;
} else if (kev->key() == Qt::Key_V && (kev->modifiers() & Qt::ControlModifier)) {
if (kev->modifiers() & Qt::ShiftModifier) {
pasteAndSend_triggered();
return true;
} else {
// Remember that we just pasted into the chat field
// and allow CTRL+Enter only when we are sure it was
// released for at least one GUI cycle.
// See #6568
m_justPasted = true;
}
}
}

if (evt->type() == QEvent::KeyRelease) {
QKeyEvent *kev = static_cast< QKeyEvent * >(evt);
if (kev->key() == Qt::Key_Control) {
m_justPasted = false;
}
}

return QTextEdit::event(evt);
}

Expand Down
1 change: 1 addition & 0 deletions src/mumble/CustomElements.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ChatbarTextEdit : public QTextEdit {
QString qsHistoryTemp;
int iHistoryIndex;
static const int MAX_HISTORY = 50;
bool m_justPasted;

protected:
QString qsDefaultText;
Expand Down
1 change: 1 addition & 0 deletions src/mumble/GlobalShortcut_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public slots:
// if left defined
#undef None
#undef KeyPress
#undef KeyRelease
#undef FontChange

#endif

0 comments on commit fcd105c

Please sign in to comment.