diff --git a/src/gui/Pages/Chat/Composer/Composer.qml b/src/gui/Pages/Chat/Composer/Composer.qml index 1ef75187..24d3acf8 100644 --- a/src/gui/Pages/Chat/Composer/Composer.qml +++ b/src/gui/Pages/Chat/Composer/Composer.qml @@ -55,7 +55,7 @@ Rectangle { onAutoCompletePrevious: userCompletion.previous() onAutoCompleteNext: userCompletion.next() onCancelAutoCompletion: userCompletion.cancel() - onExtraCharacterCloseAutoCompletion: + onAcceptAutoCompletion: ! userCompletion.autoOpen || userCompletion.autoOpenCompleted ? userCompletion.accept() : diff --git a/src/gui/Pages/Chat/Composer/MessageArea.qml b/src/gui/Pages/Chat/Composer/MessageArea.qml index e8f5de37..326051c3 100644 --- a/src/gui/Pages/Chat/Composer/MessageArea.qml +++ b/src/gui/Pages/Chat/Composer/MessageArea.qml @@ -55,7 +55,7 @@ HTextArea { signal autoCompletePrevious() signal autoCompleteNext() - signal extraCharacterCloseAutoCompletion() + signal acceptAutoCompletion() signal cancelAutoCompletion() function setTyping(typing) { @@ -189,7 +189,7 @@ HTextArea { autoCompletionOpen ? cancelAutoCompletion() : clearReplyTo() Keys.onReturnPressed: ev => { - if (autoCompletionOpen) extraCharacterCloseAutoCompletion() + if (autoCompletionOpen) acceptAutoCompletion() ev.accepted = true ev.modifiers & Qt.ShiftModifier || @@ -202,7 +202,7 @@ HTextArea { Keys.onEnterPressed: ev => Keys.returnPressed(ev) Keys.onMenuPressed: ev => { - if (autoCompletionOpen) extraCharacterCloseAutoCompletion() + if (autoCompletionOpen) acceptAutoCompletion() if (eventList && eventList.currentItem) eventList.currentItem.openContextMenu() @@ -235,7 +235,7 @@ HTextArea { } Keys.onPressed: ev => { - if (ev.text && autoCompletionOpen) extraCharacterCloseAutoCompletion() + if (ev.text && autoCompletionOpen) acceptAutoCompletion() if (ev.matches(StandardKey.Copy) && ! area.selectedText && diff --git a/src/gui/Pages/Chat/Composer/UserAutoCompletion.qml b/src/gui/Pages/Chat/Composer/UserAutoCompletion.qml index 66b735d3..68ba002a 100644 --- a/src/gui/Pages/Chat/Composer/UserAutoCompletion.qml +++ b/src/gui/Pages/Chat/Composer/UserAutoCompletion.qml @@ -7,7 +7,6 @@ import "../../../Base" import "../../../Base/HTile" // FIXME: a b -> a @p b → @p doesn't trigger completion -// FIXME: close autocomplete when cursor moves away HListView { id: root @@ -28,13 +27,18 @@ HListView { ) : "" + function getLastWordStart() { + const lastWordMatch = /(?:^|\s)[^\s]+$/.exec(textArea.text) + if (! lastWordMatch) return textArea.length + + if (! (lastWordMatch.index === 0 && ! textArea.text[0].match(/\s/))) + return lastWordMatch.index + 1 + + return lastWordMatch.index + } + function replaceLastWord(withText) { - let lastWordStart = /(?:^|\s)[^\s]+$/.exec(textArea.text).index - - if (! (lastWordStart === 0 && ! textArea.text[0].match(/\s/))) - lastWordStart += 1 - - textArea.remove(lastWordStart, textArea.length) + textArea.remove(getLastWordStart(), textArea.length) textArea.insertAtCursor(withText) } @@ -121,6 +125,11 @@ HListView { Connections { target: root.textArea + function onCursorPositionChanged() { + if (root.open && root.textArea.cursorPosition < getLastWordStart()) + root.accept() + } + function onTextChanged() { let changed = false