Input field fixes

* Message with multiple mentions are not broken in IRC. Fix #267
* Editing a message won't remove mentions anymore
This commit is contained in:
Carl Schwan
2021-02-22 19:09:56 +00:00
parent 1234132a05
commit bb3b3bc088
8 changed files with 57 additions and 18 deletions

View File

@@ -318,6 +318,11 @@ ToolBar {
property real progress: 0
property bool autoAppeared: false
// store each user we autoComplete here, this will be helpful later to generate
// the matrix.to links.
// This use an hack to define: https://doc.qt.io/qt-5/qml-var.html#property-value-initialization-semantics
property var userAutocompleted: ({})
ChatDocumentHandler {
id: documentHandler
document: inputField.textDocument
@@ -471,7 +476,7 @@ ToolBar {
function postMessage() {
roomManager.actionsHandler.postMessage(inputField.text.trim(), attachmentPath,
replyEventID, editEventId);
replyEventID, editEventId, inputField.userAutocompleted);
clearAttachment();
currentRoom.markAllMessagesAsRead();
clear();
@@ -482,6 +487,10 @@ ToolBar {
function autoComplete() {
documentHandler.replaceAutoComplete(autoCompleteListView.currentItem.displayText)
if (!autoCompleteListView.currentItem.isEmoji) {
inputField.userAutocompleted[autoCompleteListView.currentItem.displayText] = autoCompleteListView.currentItem.userId;
}
}
}
}
@@ -573,15 +582,14 @@ ToolBar {
}
function clear() {
inputField.clear()
inputField.clear();
inputField.userAutocompleted = {};
}
function clearEditReply() {
isReply = false;
replyUser = null;
if (root.editEventId.length > 0) {
clear();
}
clear();
root.replyContent = "";
root.replyEventID = "";
root.editEventId = "";
@@ -592,9 +600,26 @@ ToolBar {
inputField.forceActiveFocus()
}
function edit(editContent, editEventId) {
function edit(editContent, editFormatedContent, editEventId) {
console.log("Editing ", editContent, "html:", editFormatedContent)
// Set the input field in edit mode
inputField.text = editContent;
root.editEventId = editEventId
// clean autocompletion list
inputField.userAutocompleted = {};
// Fill autocompletion list with values extracted from message.
// We can't just iterate on every user in the list and try to
// find matching display name since some users have display name
// matching frequent words and this will marks too many words as
// mentions.
const regex = /<a href=\"https:\/\/matrix.to\/#\/(@[a-zA-Z09]*:[a-zA-Z09.]*)\">([^<]*)<\/a>/g;
let match;
while ((match = regex.exec(editFormatedContent.toString())) !== null) {
inputField.userAutocompleted[match[2]] = match[1];
}
}
function closeAll() {