Merge pull request #1005 from maltee1/fix_input_method

Fix input method
This commit is contained in:
DeepBlueV7.X 2022-03-22 03:56:01 +01:00 committed by GitHub
commit dfb34a6c96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -124,7 +124,7 @@ Rectangle {
completerTriggeredAt = pos; completerTriggeredAt = pos;
completer.completerName = type; completer.completerName = type;
popup.open(); popup.open();
completer.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition)); completer.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition)+messageInput.preeditText);
} }
function positionCursorAtEnd() { function positionCursorAtEnd() {
@ -147,11 +147,24 @@ Rectangle {
bottomPadding: 8 bottomPadding: 8
leftPadding: inputBar.showAllButtons? 0 : 8 leftPadding: inputBar.showAllButtons? 0 : 8
focus: true focus: true
property string lastChar
onTextChanged: { onTextChanged: {
if (room) if (room)
room.input.updateState(selectionStart, selectionEnd, cursorPosition, text); room.input.updateState(selectionStart, selectionEnd, cursorPosition, text);
forceActiveFocus(); forceActiveFocus();
if (cursorPosition > 0)
lastChar = text.charAt(cursorPosition-1)
else
lastChar = ''
if (lastChar == '@') {
messageInput.openCompleter(selectionStart-1, "user");
} else if (lastChar == ':') {
messageInput.openCompleter(selectionStart-1, "emoji");
} else if (lastChar == '#') {
messageInput.openCompleter(selectionStart-1, "roomAliases");
} else if (lastChar == "~") {
messageInput.openCompleter(selectionStart-1, "customEmoji");
}
} }
onCursorPositionChanged: { onCursorPositionChanged: {
if (!room) if (!room)
@ -162,9 +175,13 @@ Rectangle {
popup.close(); popup.close();
if (popup.opened) 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) onSelectionStartChanged: room.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
onSelectionEndChanged: room.input.updateState(selectionStart, selectionEnd, cursorPosition, text) onSelectionEndChanged: room.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
// Ensure that we get escape key press events first. // Ensure that we get escape key press events first.
@ -187,14 +204,6 @@ Rectangle {
messageInput.text = room.input.previousText(); messageInput.text = room.input.previousText();
} else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_N) { } else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_N) {
messageInput.text = room.input.nextText(); 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) { } else if (event.key == Qt.Key_Escape && popup.opened) {
completer.completerName = ""; completer.completerName = "";
popup.close(); popup.close();
@ -215,8 +224,10 @@ Rectangle {
return; return;
} }
} }
room.input.send(); if (!Qt.inputMethod.visible) {
event.accepted = true; room.input.send();
event.accepted = true;
}
} else if (event.key == Qt.Key_Tab && (event.modifiers == Qt.NoModifier || event.modifiers == Qt.ShiftModifier)) { } else if (event.key == Qt.Key_Tab && (event.modifiers == Qt.NoModifier || event.modifiers == Qt.ShiftModifier)) {
event.accepted = true; event.accepted = true;
if (popup.opened) { if (popup.opened) {