Better reply UI.

This commit is contained in:
Black Hat 2018-10-21 12:50:37 +08:00
parent 872ff75d6f
commit b5713d90f1
2 changed files with 35 additions and 6 deletions

View File

@ -39,7 +39,10 @@ Menu {
onTriggered: { onTriggered: {
roomPanelInput.clear() roomPanelInput.clear()
roomPanelInput.insert("> <" + model.author.id + "><" + model.eventId + "> " + (selectedText != "" ? selectedText : model.message) + "\n\n") roomPanelInput.isReply = true
roomPanelInput.replyUserID = model.author.id
roomPanelInput.replyEventID = model.eventId
roomPanelInput.replyContent = selectedText != "" ? selectedText : model.message
} }
} }
MenuItem { MenuItem {

View File

@ -13,6 +13,11 @@ import Spectral 0.1
import "qrc:/js/md.js" as Markdown import "qrc:/js/md.js" as Markdown
Rectangle { Rectangle {
property bool isReply
property string replyUserID
property string replyEventID
property string replyContent
color: MSettings.darkTheme ? "#303030" : "#fafafa" color: MSettings.darkTheme ? "#303030" : "#fafafa"
layer.enabled: true layer.enabled: true
@ -38,6 +43,7 @@ Rectangle {
Layout.preferredHeight: 48 Layout.preferredHeight: 48
id: uploadButton id: uploadButton
visible: !isReply
contentItem: MaterialIcon { contentItem: MaterialIcon {
icon: "\ue226" icon: "\ue226"
@ -52,6 +58,20 @@ Rectangle {
} }
} }
ItemDelegate {
Layout.preferredWidth: 48
Layout.preferredHeight: 48
id: cancelReplyButton
visible: isReply
contentItem: MaterialIcon {
icon: "\ue5cd"
}
onClicked: clearReply()
}
ScrollView { ScrollView {
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: 48 Layout.preferredHeight: 48
@ -66,7 +86,7 @@ Rectangle {
id: inputField id: inputField
wrapMode: Text.Wrap wrapMode: Text.Wrap
placeholderText: "Send a Message" placeholderText: isReply ? "Reply to " + replyUserID : "Send a Message"
leftPadding: 16 leftPadding: 16
topPadding: 0 topPadding: 0
bottomPadding: 0 bottomPadding: 0
@ -127,10 +147,9 @@ Rectangle {
var PREFIX_HTML = '/html ' var PREFIX_HTML = '/html '
var PREFIX_MARKDOWN = '/md ' var PREFIX_MARKDOWN = '/md '
var replyRe = new RegExp("^> <(.*)><(.*)> (.*)\n\n(.*)") if (isReply) {
if (text.match(replyRe)) { currentRoom.sendReply(replyUserID, replyEventID, replyContent, text)
var matches = text.match(replyRe) clearReply()
currentRoom.sendReply(matches[1], matches[2], matches[3], matches[4])
return return
} }
@ -211,4 +230,11 @@ Rectangle {
function clear() { function clear() {
inputField.clear() inputField.clear()
} }
function clearReply() {
isReply = false
replyUserID = ""
replyEventID = ""
replyContent = ""
}
} }