From 3c4c92dbc063abf5165dcf0ea37a9012b7abd73f Mon Sep 17 00:00:00 2001 From: miruka Date: Tue, 10 Dec 2019 17:04:03 -0400 Subject: [PATCH] Save/load composer text --- TODO.md | 4 ---- src/qml/Base/HDrawer.qml | 2 +- src/qml/Base/HScrollableTextArea.qml | 12 ++++++++++++ src/qml/Base/HTextField.qml | 8 +++++--- src/qml/Chat/Composer.qml | 3 +++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 6d47617e..81d72db1 100644 --- a/TODO.md +++ b/TODO.md @@ -76,10 +76,6 @@ but never do it again once the user hovered it long enough to show tooltip or clicked on it once - - Restoring UI state: - - Composer content - - Which element was focused - - Combine events so they take less space - After combining is implemented, no need to hide profile changes anymore. - Replies diff --git a/src/qml/Base/HDrawer.qml b/src/qml/Base/HDrawer.qml index c88fb93a..b8dd3570 100644 --- a/src/qml/Base/HDrawer.qml +++ b/src/qml/Base/HDrawer.qml @@ -25,7 +25,7 @@ Drawer { property string saveName: "" - property string saveId: "" + property var saveId: "ALL" property var saveProperties: ["preferredSize"] // diff --git a/src/qml/Base/HScrollableTextArea.qml b/src/qml/Base/HScrollableTextArea.qml index a06ea50b..7672e9d6 100644 --- a/src/qml/Base/HScrollableTextArea.qml +++ b/src/qml/Base/HScrollableTextArea.qml @@ -6,9 +6,21 @@ ScrollView { clip: true ScrollBar.vertical.visible: contentHeight > height + // Set it only on component creation to avoid binding loops + Component.onCompleted: if (! text) { + text = window.getState(this, "text", "") + textArea.cursorPosition = text.length + } + + onTextChanged: window.saveState(this) + default property alias textAreaData: textArea.data + property string saveName: "" + property var saveId: "ALL" + property var saveProperties: ["text"] + property alias backgroundColor: textAreaBackground.color property alias placeholderText: textArea.placeholderText property alias text: textArea.text diff --git a/src/qml/Base/HTextField.qml b/src/qml/Base/HTextField.qml index c7595829..9c8fad25 100644 --- a/src/qml/Base/HTextField.qml +++ b/src/qml/Base/HTextField.qml @@ -30,8 +30,10 @@ TextField { } // Set it only on component creation to avoid binding loops - Component.onCompleted: - if (! text) text = window.getState(this, "text", "") + Component.onCompleted: if (! text) { + text = window.getState(this, "text", "") + cursorPosition = text.length + } onTextChanged: window.saveState(this) @@ -42,7 +44,7 @@ TextField { property string saveName: "" - property string saveId: "" + property var saveId: "ALL" property var saveProperties: ["text"] property bool error: false diff --git a/src/qml/Chat/Composer.qml b/src/qml/Chat/Composer.qml index f9cd741d..41bf522e 100644 --- a/src/qml/Chat/Composer.qml +++ b/src/qml/Chat/Composer.qml @@ -65,6 +65,9 @@ Rectangle { HScrollableTextArea { id: areaScrollView + saveName: "composer" + saveId: [chat.roomId, writingUserId] + placeholderText: qsTr("Type a message...") backgroundColor: "transparent" area.tabStopDistance: 4 * 4 // 4 spaces