From 8da4ff158536a4c12de7758c5c30a608244c4c3b Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 24 Nov 2020 17:54:15 +0100 Subject: [PATCH] Improve autocompletion of Emojis Now it start automatically for emojis, and also the first time you use tab you jump to the first selected emoji or face. --- imports/NeoChat/Component/ChatTextInput.qml | 45 ++++++++++++--------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/imports/NeoChat/Component/ChatTextInput.qml b/imports/NeoChat/Component/ChatTextInput.qml index 37f5b1b46..3d0893f09 100644 --- a/imports/NeoChat/Component/ChatTextInput.qml +++ b/imports/NeoChat/Component/ChatTextInput.qml @@ -219,6 +219,7 @@ ToolBar { TextArea { property real progress: 0 + property bool autoAppeared: false; Layout.fillWidth: true @@ -279,24 +280,23 @@ ToolBar { Keys.onBacktabPressed: if (isAutoCompleting) autoCompleteListView.decrementCurrentIndex() Keys.onTabPressed: { - if (isAutoCompleting) { + if (isAutoCompleting && autoAppeared === false) { + autoAppeared = false; autoCompleteListView.incrementCurrentIndex() } else { + autoAppeared = false; autoCompleteBeginPosition = text.substring(0, cursorPosition).lastIndexOf(" ") + 1 - var autoCompletePrefix = text.substring(0, cursorPosition).split(" ").pop() + let autoCompletePrefix = text.substring(0, cursorPosition).split(" ").pop() if (!autoCompletePrefix) return if (autoCompletePrefix.startsWith(":")) { autoCompleteBeginPosition = text.substring(0, cursorPosition).lastIndexOf(" ") + 1 autoCompleteModel = emojiModel.filterModel(autoCompletePrefix) - if (autoCompleteModel.length === 0) return - isAutoCompleting = true - autoCompleteEndPosition = cursorPosition } else { autoCompleteModel = currentRoom.getUsers(autoCompletePrefix) - if (autoCompleteModel.length === 0) return - isAutoCompleting = true - autoCompleteEndPosition = cursorPosition } + if (autoCompleteModel.length === 0) return + isAutoCompleting = true + autoCompleteEndPosition = cursorPosition } replaceAutoComplete(autoCompleteListView.currentItem.autoCompleteText) } @@ -305,21 +305,30 @@ ToolBar { timeoutTimer.restart() repeatTimer.start() currentRoom.cachedInput = text + autoAppeared = false; if (cursorPosition !== autoCompleteBeginPosition && cursorPosition !== autoCompleteEndPosition) { - isAutoCompleting = false - autoCompleteListView.currentIndex = 0 + isAutoCompleting = false; + autoCompleteListView.currentIndex = 0; } - var autoCompletePrefix = text.substring(0, cursorPosition).split(" ").pop(); - if (!autoCompletePrefix) return - - if (autoCompletePrefix.startsWith("@")) { - autoCompletePrefix = autoCompletePrefix.substring(1); - autoCompleteBeginPosition = text.substring(0, cursorPosition).lastIndexOf(" ") + 1 // 1 = space - autoCompleteModel = currentRoom.getUsers(autoCompletePrefix) - if (autoCompleteModel.length === 0) return + let autoCompletePrefix = text.substring(0, cursorPosition).split(" ").pop(); + if (!autoCompletePrefix) { + return; + } + if (autoCompletePrefix.startsWith("@") || autoCompletePrefix.startsWith(":")) { + if (autoCompletePrefix.startsWith("@")) { + autoCompletePrefix = autoCompletePrefix.substring(1); + autoCompleteBeginPosition = text.substring(0, cursorPosition).lastIndexOf(" ") + 1 // 1 = space + autoCompleteModel = currentRoom.getUsers(autoCompletePrefix); + } else { + autoCompleteModel = emojiModel.filterModel(autoCompletePrefix); + } + if (autoCompleteModel.length === 0) { + return; + } isAutoCompleting = true + autoAppeared = true; autoCompleteEndPosition = cursorPosition } }