From 094d82088280b8808a9d317001c8416a4f09e09f Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Fri, 27 Sep 2019 16:12:02 -0400 Subject: [PATCH] Prevent escape key from being captured. --- TransmitTextEdit.cpp | 13 +++++++++++++ TransmitTextEdit.h | 1 + mainwindow.cpp | 21 +++++++++++++++++---- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/TransmitTextEdit.cpp b/TransmitTextEdit.cpp index f879250..38ebd00 100644 --- a/TransmitTextEdit.cpp +++ b/TransmitTextEdit.cpp @@ -131,6 +131,15 @@ void TransmitTextEdit::replaceUnsentText(const QString &text){ c.insertText(text); } +// +void TransmitTextEdit::replacePlainText(const QString &text){ + auto c = textCursor(); + c.movePosition(QTextCursor::Start); + c.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); + c.removeSelectedText(); + c.insertText(text); +} + // void TransmitTextEdit::setFont(QFont f){ m_font = f; @@ -351,7 +360,11 @@ bool TransmitTextEdit::eventFilter(QObject */*o*/, QEvent *e){ return false; } + // -1. don't filter the escape key QKeyEvent *k = static_cast(e); + if(k->key() == Qt::Key_Escape){ + return false; + } auto c = textCursor(); diff --git a/TransmitTextEdit.h b/TransmitTextEdit.h index c1148e5..447a15d 100644 --- a/TransmitTextEdit.h +++ b/TransmitTextEdit.h @@ -35,6 +35,7 @@ public: QString toPlainText() const; void setPlainText(const QString &text); void replaceUnsentText(const QString &text); + void replacePlainText(const QString &text); void setFont(QFont f); void setFont(QFont f, QColor fg, QColor bg); diff --git a/mainwindow.cpp b/mainwindow.cpp index 5212ec5..4099500 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6354,15 +6354,28 @@ bool MainWindow::prepareNextMessageFrame() // typeahead static QString lastText; - if(lastText == "" || lastText != ui->extFreeTextMsgEdit->toPlainText()){ + auto text = ui->extFreeTextMsgEdit->toPlainText(); + if(lastText == "" || lastText != text){ +#if 1 auto sent = ui->extFreeTextMsgEdit->sentText(); auto unsent = ui->extFreeTextMsgEdit->unsentText(); qDebug() << "text dirty for typeahead\n" << sent << "\n" << unsent; m_txFrameQueue.clear(); m_txFrameCount = 0; - auto newUnsent = appendMessage(unsent); - ui->extFreeTextMsgEdit->replaceUnsentText(newUnsent); - lastText = ui->extFreeTextMsgEdit->toPlainText(); + auto newText = appendMessage(unsent); + ui->extFreeTextMsgEdit->replaceUnsentText(newText); +#else + m_txFrameQueue.clear(); + auto newText = appendMessage(text); + for(int i = 0; i < m_txFrameCount; i++){ + if(m_txFrameQueue.isEmpty()){ + break; + } + m_txFrameQueue.removeFirst(); + } + ui->extFreeTextMsgEdit->replacePlainText(newText); +#endif + lastText = text; } QPair f = popMessageFrame();