From 99ae075bb48382e0afd844c8fa5fd98bc5af7f34 Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 3 Sep 2020 18:30:36 -0400 Subject: [PATCH] Reset composer when recycling chat page --- src/gui/Base/HTextArea.qml | 8 +++++--- src/gui/Base/HTextField.qml | 8 +++++--- src/gui/Pages/Chat/Composer/MessageArea.qml | 9 +++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/gui/Base/HTextArea.qml b/src/gui/Base/HTextArea.qml index 0b85c97e..81d51ae5 100644 --- a/src/gui/Base/HTextArea.qml +++ b/src/gui/Base/HTextArea.qml @@ -38,6 +38,10 @@ TextArea { text = Qt.binding(() => defaultText || "") } + function loadState() { + if (! text) insertAtCursor(window.getState(this, "text", "")) + } + function insertAtCursor(text) { insert(cursorPosition, text) } @@ -87,9 +91,7 @@ TextArea { Component.onCompleted: { // Break binding previousDefaultText = previousDefaultText - - // Set it only on component creation to avoid binding loops - if (! text) insertAtCursor(window.getState(this, "text", "")) + loadState() } onTextChanged: window.saveState(this) diff --git a/src/gui/Base/HTextField.qml b/src/gui/Base/HTextField.qml index b90479ca..3a55e776 100644 --- a/src/gui/Base/HTextField.qml +++ b/src/gui/Base/HTextField.qml @@ -34,6 +34,10 @@ TextField { text = Qt.binding(() => defaultText || "") } + function loadState() { + if (! text) insertAtCursor(window.getState(this, "text", "")) + } + function insertAtCursor(text) { insert(cursorPosition, text) } @@ -74,9 +78,7 @@ TextField { Component.onCompleted: { // Break binding previousDefaultText = previousDefaultText - - // Set it only on component creation to avoid binding loops - if (! text) insertAtCursor(window.getState(this, "text", "")) + loadState() } onTextChanged: window.saveState(this) diff --git a/src/gui/Pages/Chat/Composer/MessageArea.qml b/src/gui/Pages/Chat/Composer/MessageArea.qml index 39ca37d0..6db561f1 100644 --- a/src/gui/Pages/Chat/Composer/MessageArea.qml +++ b/src/gui/Pages/Chat/Composer/MessageArea.qml @@ -245,4 +245,13 @@ HTextArea { // ) // } } + + Connections { + target: pageLoader + + function onRecycled() { + area.reset() + area.loadState() + } + } }