From 18dec96843a11a3436d96a171ed90554bf6376f8 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Sun, 10 Nov 2019 11:38:31 -0500 Subject: [PATCH] Fixed #235: only 7-bit printable ascii allowed in the text box --- TransmitTextEdit.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/TransmitTextEdit.cpp b/TransmitTextEdit.cpp index a2cf028..4f76fe5 100644 --- a/TransmitTextEdit.cpp +++ b/TransmitTextEdit.cpp @@ -1,7 +1,9 @@ #include "TransmitTextEdit.h" +#include #include + void setTextEditFont(QTextEdit *edit, QFont font){ // all uppercase font.setCapitalization(QFont::AllUppercase); @@ -235,18 +237,30 @@ void TransmitTextEdit::on_textContentsChanged(int /*pos*/, int rem, int add){ return; } - auto text = toPlainText(); - if(text != m_lastText){ - //qDebug() << "text changed" << pos << rem << add << "from" << m_lastText << "to" << text; - - highlight(); - - //qDebug() << "sent:" << sentText(); - //qDebug() << "unsent:" << unsentText(); - - m_dirty = true; - m_lastText = text; + QString text = toPlainText(); + if(text == m_lastText){ + return; } + + QString normalized = text.normalized(QString::NormalizationForm_KD); + QString result; + std::copy_if(normalized.begin(), normalized.end(), std::back_inserter(result), [](QChar& c) { + return c.toLatin1() != 0 && c > 31 && c < 128; + }); + if(result != text){ + bool blocked = signalsBlocked(); + blockSignals(true); + { + replacePlainText(result, true); + text = result; + } + blockSignals(blocked); + } + + highlight(); + + m_dirty = true; + m_lastText = text; } void TransmitTextEdit::highlightBase(){