@@ -133,6 +133,7 @@ ToolBar {
|
|||||||
keyNavigationWraps: true
|
keyNavigationWraps: true
|
||||||
|
|
||||||
delegate: Control {
|
delegate: Control {
|
||||||
|
property string autoCompleteText: modelData.displayName ? ("[" + modelData.displayName + "](https://matrix.to/#/" + modelData.id + "):") : modelData.unicode
|
||||||
property string displayText: modelData.displayName ?? modelData.unicode
|
property string displayText: modelData.displayName ?? modelData.unicode
|
||||||
property bool isEmoji: modelData.unicode != null
|
property bool isEmoji: modelData.unicode != null
|
||||||
readonly property bool highlighted: autoCompleteListView.currentIndex == index
|
readonly property bool highlighted: autoCompleteListView.currentIndex == index
|
||||||
@@ -176,7 +177,7 @@ ToolBar {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
autoCompleteListView.currentIndex = index
|
autoCompleteListView.currentIndex = index
|
||||||
documentHandler.replaceAutoComplete(displayText)
|
inputField.autoComplete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,6 +304,7 @@ ToolBar {
|
|||||||
|
|
||||||
wrapMode: Text.Wrap
|
wrapMode: Text.Wrap
|
||||||
placeholderText: i18n("Write your message...")
|
placeholderText: i18n("Write your message...")
|
||||||
|
textFormat: TextEdit.MarkdownText
|
||||||
topPadding: 0
|
topPadding: 0
|
||||||
bottomPadding: 0
|
bottomPadding: 0
|
||||||
leftPadding: Kirigami.Units.smallSpacing
|
leftPadding: Kirigami.Units.smallSpacing
|
||||||
@@ -342,7 +344,8 @@ ToolBar {
|
|||||||
|
|
||||||
Keys.onReturnPressed: {
|
Keys.onReturnPressed: {
|
||||||
if (isAutoCompleting) {
|
if (isAutoCompleting) {
|
||||||
documentHandler.replaceAutoComplete(autoCompleteListView.currentItem.displayText)
|
inputField.autoComplete();
|
||||||
|
|
||||||
isAutoCompleting = false;
|
isAutoCompleting = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -397,7 +400,7 @@ ToolBar {
|
|||||||
autoAppeared = false;
|
autoAppeared = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
documentHandler.replaceAutoComplete(autoCompleteListView.currentItem.displayText)
|
inputField.autoComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
@@ -434,10 +437,33 @@ ToolBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function postMessage() {
|
function postMessage() {
|
||||||
documentHandler.postMessage(inputField.text, attachmentPath, replyEventID);
|
// Qt wraps lines so we need to use a small hack
|
||||||
|
// to remove the wrapped lines but not break the empty
|
||||||
|
// lines.
|
||||||
|
const updatedText = inputField.text.trim()
|
||||||
|
.replace(/\n{2,}/g, '<br /><br />')
|
||||||
|
.replace(/\n/g, '')
|
||||||
|
documentHandler.postMessage(updatedText, attachmentPath, replyEventID);
|
||||||
clearAttachment();
|
clearAttachment();
|
||||||
currentRoom.markAllMessagesAsRead();
|
currentRoom.markAllMessagesAsRead();
|
||||||
clear();
|
clear();
|
||||||
|
text = Qt.binding(function() {
|
||||||
|
return currentRoom != null ? currentRoom.cachedInput : "";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// HACK apply markdown, we are setting the text attribute to
|
||||||
|
// force the text field to rerender. Because the cursor position
|
||||||
|
// will be reset, we save the old one and substract the now hidden
|
||||||
|
// markdown markup.
|
||||||
|
function autoComplete() {
|
||||||
|
documentHandler.replaceAutoComplete(autoCompleteListView.currentItem.autoCompleteText)
|
||||||
|
const oldCursorPosition = cursorPosition;
|
||||||
|
const oldText = text;
|
||||||
|
const oldLength = inputField.length;
|
||||||
|
text = "";
|
||||||
|
text = oldText;
|
||||||
|
cursorPosition = oldCursorPosition - (oldLength - inputField.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -467,6 +467,8 @@ QString NeoChatRoom::markdownToHTML(const QString &markdown)
|
|||||||
|
|
||||||
auto result = QString::fromStdString(html).trimmed();
|
auto result = QString::fromStdString(html).trimmed();
|
||||||
|
|
||||||
|
result.replace("<!-- raw HTML omitted -->", "<br />");
|
||||||
|
result.replace(QRegularExpression("(<br />)*$"), "");
|
||||||
result.replace("<p>", "");
|
result.replace("<p>", "");
|
||||||
result.replace("</p>", "");
|
result.replace("</p>", "");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user