From 7aff060ec7854b8320d1d158c56fe822d5f9975e Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Thu, 26 Sep 2019 20:29:05 -0400 Subject: [PATCH] Protect function drops the selected sent text to make it easier to replace the next frames --- TransmitTextEdit.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/TransmitTextEdit.cpp b/TransmitTextEdit.cpp index 780d1e0..57b206b 100644 --- a/TransmitTextEdit.cpp +++ b/TransmitTextEdit.cpp @@ -176,6 +176,17 @@ void TransmitTextEdit::on_selectionChanged(){ auto protect = cursorShouldBeProtected(c); + if(protect){ + blockSignals(true); + { + int end = c.selectionEnd(); + c.setPosition(m_sent); + c.setPosition(end, QTextCursor::KeepAnchor); + setTextCursor(c); + } + blockSignals(false); + } + setProtected(protect); // TODO: when protected and text is selected, remove protected region from selection @@ -382,10 +393,16 @@ bool TransmitTextEdit::eventFilter(QObject */*o*/, QEvent *e){ // 2. if on the edge, do not filter if not a backspace int start = qMin(c.selectionStart(), c.selectionEnd()); + int end = qMax(c.selectionStart(), c.selectionEnd()); if(start == m_sent && k->key() != Qt::Key_Backspace){ return false; } + // 3. if on the edge, do not filter if a backspace and there is text selected + if(start == m_sent && start != end && k->key() == Qt::Key_Backspace){ + return false; + } + return true; }