summary refs log tree commit diff
path: root/resources/qml/MessageInput.qml
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-11-20 02:38:08 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2020-11-25 19:05:12 +0100
commitadd5903fb0abc76d77ce4369c4679a95be03b433 (patch)
tree0c0bbebd80f3f404daaffa2695244578dc4254db /resources/qml/MessageInput.qml
parentadd per-room user model (diff)
downloadnheko-add5903fb0abc76d77ce4369c4679a95be03b433.tar.xz
Working User completer
Diffstat (limited to 'resources/qml/MessageInput.qml')
-rw-r--r--resources/qml/MessageInput.qml20
1 files changed, 16 insertions, 4 deletions
diff --git a/resources/qml/MessageInput.qml b/resources/qml/MessageInput.qml
index a4a47a3e..50ff7324 100644
--- a/resources/qml/MessageInput.qml
+++ b/resources/qml/MessageInput.qml
@@ -77,14 +77,13 @@ Rectangle {
                 onTextChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
                 onCursorPositionChanged: {
                     TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text);
-                    if (cursorPosition < completerTriggeredAt) {
+                    if (cursorPosition <= completerTriggeredAt) {
                         completerTriggeredAt = -1;
                         popup.close();
                     }
                 }
                 onSelectionStartChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
                 onSelectionEndChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
-                // Ensure that we get escape key press events first.
                 Keys.onShortcutOverride: event.accepted = (completerTriggeredAt != -1 && (event.key === Qt.Key_Escape || event.key === Qt.Key_Tab || event.key === Qt.Key_Enter))
                 Keys.onPressed: {
                     if (event.matches(StandardKey.Paste)) {
@@ -97,18 +96,20 @@ Rectangle {
                     } else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_N) {
                         textArea.text = TimelineManager.timeline.input.nextText();
                     } else if (event.key == Qt.Key_At) {
-                        completerTriggeredAt = cursorPosition + 1;
+                        completerTriggeredAt = cursorPosition;
                         popup.completerName = "user";
                         popup.open();
                     } else if (event.key == Qt.Key_Escape && popup.opened) {
                         completerTriggeredAt = -1;
+                        popup.completerName = "";
                         event.accepted = true;
                         popup.close();
                     } else if (event.matches(StandardKey.InsertParagraphSeparator) && popup.opened) {
                         var currentCompletion = popup.currentCompletion();
+                        popup.completerName = "";
                         popup.close();
                         if (currentCompletion) {
-                            textArea.remove(completerTriggeredAt - 1, cursorPosition);
+                            textArea.remove(completerTriggeredAt, cursorPosition);
                             textArea.insert(cursorPosition, currentCompletion);
                             event.accepted = true;
                             return ;
@@ -129,6 +130,17 @@ Rectangle {
                     }
                 }
 
+                Connections {
+                    onTimelineChanged: {
+                        textArea.clear();
+                        textArea.append(TimelineManager.timeline.input.text());
+                        textArea.completerTriggeredAt = -1;
+                        popup.completerName = "";
+                    }
+                    target: TimelineManager
+                }
+                // Ensure that we get escape key press events first.
+
                 Completer {
                     id: popup