summary refs log tree commit diff
path: root/resources
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
parentadd per-room user model (diff)
downloadnheko-add5903fb0abc76d77ce4369c4679a95be03b433.tar.xz
Working User completer
Diffstat (limited to 'resources')
-rw-r--r--resources/qml/Completer.qml8
-rw-r--r--resources/qml/MessageInput.qml20
2 files changed, 23 insertions, 5 deletions
diff --git a/resources/qml/Completer.qml b/resources/qml/Completer.qml
index d53eae62..2c520dec 100644
--- a/resources/qml/Completer.qml
+++ b/resources/qml/Completer.qml
@@ -34,11 +34,17 @@ Popup {
     onCompleterNameChanged: {
         if (completerName)
             completer = TimelineManager.timeline.input.completerFor(completerName);
-
+        else
+            completer = undefined;
     }
     padding: 0
     onAboutToShow: currentIndex = -1
 
+    Connections {
+        onTimelineChanged: completer = null
+        target: TimelineManager
+    }
+
     ColumnLayout {
         anchors.fill: parent
         spacing: 0
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