From 86a81307fb3b97a346b5a82fe04d6ddb45278b3e Mon Sep 17 00:00:00 2001 From: Malte E Date: Sun, 20 Mar 2022 17:12:13 +0100 Subject: [PATCH 1/5] make completer work with input method --- resources/qml/MessageInput.qml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/resources/qml/MessageInput.qml b/resources/qml/MessageInput.qml index 8090cd99..34f35973 100644 --- a/resources/qml/MessageInput.qml +++ b/resources/qml/MessageInput.qml @@ -147,11 +147,24 @@ Rectangle { bottomPadding: 8 leftPadding: inputBar.showAllButtons? 0 : 8 focus: true + property string lastChar onTextChanged: { if (room) room.input.updateState(selectionStart, selectionEnd, cursorPosition, text); - forceActiveFocus(); + if (cursorPosition > 0) + lastChar = text.charAt(cursorPosition-1) + else + lastChar = '' + if (lastChar == '@') { + messageInput.openCompleter(selectionStart, "user"); + } else if (lastChar == ':') { + messageInput.openCompleter(selectionStart, "emoji"); + } else if (lastChar == '#') { + messageInput.openCompleter(selectionStart, "roomAliases"); + } else if (lastChar == "~") { + messageInput.openCompleter(selectionStart, "customEmoji"); + } } onCursorPositionChanged: { if (!room) @@ -187,14 +200,6 @@ Rectangle { messageInput.text = room.input.previousText(); } else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_N) { messageInput.text = room.input.nextText(); - } else if (event.key == Qt.Key_At) { - messageInput.openCompleter(selectionStart, "user"); - } else if (event.key == Qt.Key_Colon) { - messageInput.openCompleter(selectionStart, "emoji"); - } else if (event.key == Qt.Key_NumberSign) { - messageInput.openCompleter(selectionStart, "roomAliases"); - } else if (event.text == "~") { - messageInput.openCompleter(selectionStart, "customEmoji"); } else if (event.key == Qt.Key_Escape && popup.opened) { completer.completerName = ""; popup.close(); From 548063d303a97b6af159a5afa59c4efe274d7fae Mon Sep 17 00:00:00 2001 From: Malte E Date: Sun, 20 Mar 2022 17:21:59 +0100 Subject: [PATCH 2/5] attempt to include preeditText in search string --- resources/qml/MessageInput.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/qml/MessageInput.qml b/resources/qml/MessageInput.qml index 34f35973..b95d4769 100644 --- a/resources/qml/MessageInput.qml +++ b/resources/qml/MessageInput.qml @@ -124,7 +124,7 @@ Rectangle { completerTriggeredAt = pos; completer.completerName = type; popup.open(); - completer.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition)); + completer.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition)+messageInput.preeditText); } function positionCursorAtEnd() { From 0cb729cfc2447f34f95d5608921914e85d9ee8b6 Mon Sep 17 00:00:00 2001 From: Malte E Date: Sun, 20 Mar 2022 21:34:41 +0100 Subject: [PATCH 3/5] remove completer trigger characters --- resources/qml/MessageInput.qml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/qml/MessageInput.qml b/resources/qml/MessageInput.qml index b95d4769..67ca7f3c 100644 --- a/resources/qml/MessageInput.qml +++ b/resources/qml/MessageInput.qml @@ -157,13 +157,13 @@ Rectangle { else lastChar = '' if (lastChar == '@') { - messageInput.openCompleter(selectionStart, "user"); + messageInput.openCompleter(selectionStart-1, "user"); } else if (lastChar == ':') { - messageInput.openCompleter(selectionStart, "emoji"); + messageInput.openCompleter(selectionStart-1, "emoji"); } else if (lastChar == '#') { - messageInput.openCompleter(selectionStart, "roomAliases"); + messageInput.openCompleter(selectionStart-1, "roomAliases"); } else if (lastChar == "~") { - messageInput.openCompleter(selectionStart, "customEmoji"); + messageInput.openCompleter(selectionStart-1, "customEmoji"); } } onCursorPositionChanged: { From d58a4836427207716498069b5a158f26bb9c8249 Mon Sep 17 00:00:00 2001 From: Malte E Date: Sun, 20 Mar 2022 21:57:16 +0100 Subject: [PATCH 4/5] add preedit text to search --- resources/qml/MessageInput.qml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/qml/MessageInput.qml b/resources/qml/MessageInput.qml index 67ca7f3c..d8a271fe 100644 --- a/resources/qml/MessageInput.qml +++ b/resources/qml/MessageInput.qml @@ -175,9 +175,13 @@ Rectangle { popup.close(); if (popup.opened) - completer.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition)); + completer.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition)+messageInput.preeditText); } + onPreeditTextChanged: { + if (popup.opened) + completer.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition)+messageInput.preeditText); + } onSelectionStartChanged: room.input.updateState(selectionStart, selectionEnd, cursorPosition, text) onSelectionEndChanged: room.input.updateState(selectionStart, selectionEnd, cursorPosition, text) // Ensure that we get escape key press events first. From f563098e9a18d568ba388ce0c755c078d2310399 Mon Sep 17 00:00:00 2001 From: Malte E Date: Sun, 20 Mar 2022 22:17:25 +0100 Subject: [PATCH 5/5] Don't send on Enter when inputMethod.visible ( == OSK active assumed) --- resources/qml/MessageInput.qml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/qml/MessageInput.qml b/resources/qml/MessageInput.qml index d8a271fe..76c498d9 100644 --- a/resources/qml/MessageInput.qml +++ b/resources/qml/MessageInput.qml @@ -224,8 +224,10 @@ Rectangle { return; } } - room.input.send(); - event.accepted = true; + if (!Qt.inputMethod.visible) { + room.input.send(); + event.accepted = true; + } } else if (event.key == Qt.Key_Tab && (event.modifiers == Qt.NoModifier || event.modifiers == Qt.ShiftModifier)) { event.accepted = true; if (popup.opened) {