feat: autofocus on the textArea when the reply / edit is triggered

automatically focus on the textArea when reply, edit is pressed. Also
move the cursor to the end of the text content, for example, when the edit button
is pressed
This commit is contained in:
Srevin Saju
2021-04-07 19:40:23 +03:00
parent 25a8a8b011
commit 66545dbc31
4 changed files with 18 additions and 2 deletions

View File

@@ -33,7 +33,11 @@ ToolBar {
property alias isCompleting: completionMenu.visible property alias isCompleting: completionMenu.visible
onInputFieldForceActiveFocusTriggered: inputField.forceActiveFocus() onInputFieldForceActiveFocusTriggered: {
inputField.forceActiveFocus();
// set the cursor to the end of the text
inputField.cursorPosition = inputField.length;
}
position: ToolBar.Footer position: ToolBar.Footer

View File

@@ -100,6 +100,9 @@ Item {
easing.type: Easing.OutCubic easing.type: Easing.OutCubic
} }
} }
onReplyCancelled: {
root.focusInputField()
}
} }
Kirigami.Separator { Kirigami.Separator {

View File

@@ -16,6 +16,8 @@ Loader {
property var user: null property var user: null
property string avatarMediaUrl: user ? "image://mxc/" + user.avatarMediaId : "" property string avatarMediaUrl: user ? "image://mxc/" + user.avatarMediaId : ""
signal replyCancelled()
active: visible active: visible
sourceComponent: Pane { sourceComponent: Pane {
id: replyPane id: replyPane
@@ -99,7 +101,10 @@ Loader {
icon.name: "dialog-cancel" icon.name: "dialog-cancel"
text: i18n("Cancel") text: i18n("Cancel")
display: AbstractButton.IconOnly display: AbstractButton.IconOnly
onClicked: ChatBoxHelper.clearEditReply() onClicked: {
ChatBoxHelper.clearEditReply();
root.replyCancelled();
}
ToolTip.text: text ToolTip.text: text
ToolTip.visible: hovered ToolTip.visible: hovered
} }

View File

@@ -167,6 +167,7 @@ Kirigami.ScrollablePage {
id: emojiDialog id: emojiDialog
onReact: { onReact: {
page.currentRoom.toggleReaction(hoverActions.event.eventId, emoji); page.currentRoom.toggleReaction(hoverActions.event.eventId, emoji);
chatBox.focusInputField();
} }
} }
} }
@@ -179,6 +180,7 @@ Kirigami.ScrollablePage {
if (hoverActions.showEdit) { if (hoverActions.showEdit) {
ChatBoxHelper.edit(hoverActions.event.message, hoverActions.event.formattedBody, hoverActions.event.eventId) ChatBoxHelper.edit(hoverActions.event.message, hoverActions.event.formattedBody, hoverActions.event.eventId)
} }
chatBox.focusInputField();
} }
} }
QQC2.Button { QQC2.Button {
@@ -187,6 +189,7 @@ Kirigami.ScrollablePage {
icon.name: "mail-replied-symbolic" icon.name: "mail-replied-symbolic"
onClicked: { onClicked: {
ChatBoxHelper.replyToMessage(hoverActions.event.eventId, hoverActions.event.message, hoverActions.event.author); ChatBoxHelper.replyToMessage(hoverActions.event.eventId, hoverActions.event.message, hoverActions.event.author);
chatBox.focusInputField();
} }
} }
} }
@@ -668,6 +671,7 @@ Kirigami.ScrollablePage {
const targetMessage = messageEventModel.getLastLocalUserMessageEventId(); const targetMessage = messageEventModel.getLastLocalUserMessageEventId();
if (targetMessage) { if (targetMessage) {
ChatBoxHelper.edit(targetMessage["body"], targetMessage["body"], targetMessage["event_id"]); ChatBoxHelper.edit(targetMessage["body"], targetMessage["body"], targetMessage["event_id"]);
chatBox.focusInputField();
} }
} }
onReplyPreviousUserMessage: { onReplyPreviousUserMessage: {