From 2dd3197beb13596162a4f8559405e430dd2cc14f Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 20 Feb 2023 18:24:00 +0000 Subject: [PATCH] Inline Edit Fixes - Make sure the connection to the room's chatBoxEditIdChanged signal is made so that the edit box gets filled. - Make sure the minimum height and preferred width are available to the loader so they can be set and dynamically updated. BUG: 465934 --- .../Component/Timeline/MessageDelegate.qml | 3 ++ .../Timeline/MessageEditComponent.qml | 31 +++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/qml/Component/Timeline/MessageDelegate.qml b/src/qml/Component/Timeline/MessageDelegate.qml index d69f9b40b..f6a0b39f8 100644 --- a/src/qml/Component/Timeline/MessageDelegate.qml +++ b/src/qml/Component/Timeline/MessageDelegate.qml @@ -26,9 +26,12 @@ TimelineContainer { } Loader { Layout.fillWidth: true + Layout.minimumHeight: item ? item.minimumHeight : -1 + Layout.preferredWidth: item ? item.preferredWidth : -1 visible: currentRoom.chatBoxEditId === model.eventId active: visible sourceComponent: MessageEditComponent { + room: currentRoom messageId: model.eventId } } diff --git a/src/qml/Component/Timeline/MessageEditComponent.qml b/src/qml/Component/Timeline/MessageEditComponent.qml index d583b6701..c76b5d0b2 100644 --- a/src/qml/Component/Timeline/MessageEditComponent.qml +++ b/src/qml/Component/Timeline/MessageEditComponent.qml @@ -11,11 +11,13 @@ import org.kde.neochat 1.0 QQC2.TextArea { id: root + property var room + onRoomChanged: room.chatBoxEditIdChanged.connect(updateEditText) + property string messageId - Layout.fillWidth: true - Layout.minimumHeight: editButtons.height + topPadding + bottomPadding - Layout.preferredWidth: editTextMetrics.advanceWidth + rightPadding + Kirigami.Units.smallSpacing + Kirigami.Units.gridUnit + property var minimumHeight: editButtons.height + topPadding + bottomPadding + property var preferredWidth: editTextMetrics.advanceWidth + rightPadding + Kirigami.Units.smallSpacing + Kirigami.Units.gridUnit rightPadding: editButtons.width + editButtons.anchors.rightMargin * 2 color: Kirigami.Theme.textColor @@ -29,7 +31,7 @@ QQC2.TextArea { } } onTextChanged: { - currentRoom.editText = text + room.editText = text } Keys.onEnterPressed: { @@ -91,7 +93,7 @@ QQC2.TextArea { text: i18nc("@action:button", "Cancel edit") icon.name: "dialog-close" onTriggered: { - currentRoom.chatBoxEditId = ""; + room.chatBoxEditId = ""; } shortcut: "Escape" } @@ -100,15 +102,6 @@ QQC2.TextArea { } } - Connections { - target: currentRoom - function onChatBoxEditIdChanged() { - if (currentRoom.chatBoxEditId == messageId && currentRoom.chatBoxEditMessage.length > 0) { - root.text = currentRoom.chatBoxEditMessage - } - } - } - CompletionMenu { id: completionMenu height: implicitHeight @@ -131,7 +124,7 @@ QQC2.TextArea { cursorPosition: root.cursorPosition selectionStart: root.selectionStart selectionEnd: root.selectionEnd - room: currentRoom // We don't care about saving for edits so this is OK. + room: root.room // We don't care about saving for edits so this is OK. } TextMetrics { @@ -142,7 +135,13 @@ QQC2.TextArea { function postEdit() { actionsHandler.handleEdit(); root.clear(); - currentRoom.chatBoxEditId = ""; + room.chatBoxEditId = ""; + } + + function updateEditText() { + if (room.chatBoxEditId == messageId && room.chatBoxEditMessage.length > 0) { + root.text = room.chatBoxEditMessage + } } }