From eaa91b4e5649837b93d73833e31bd67dfdeafbae Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 15 Apr 2021 23:21:50 +0200 Subject: [PATCH] Fix cursor positioning on edits fixes #502 --- resources/qml/MessageInput.qml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/resources/qml/MessageInput.qml b/resources/qml/MessageInput.qml index 5aae18b0..5bb699dd 100644 --- a/resources/qml/MessageInput.qml +++ b/resources/qml/MessageInput.qml @@ -105,6 +105,14 @@ Rectangle { popup.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition)); } + function positionCursorAtEnd() { + cursorPosition = messageInput.length; + } + + function positionCursorAtStart() { + cursorPosition = 0; + } + selectByMouse: true placeholderText: qsTr("Write a message...") placeholderTextColor: colors.buttonText @@ -220,29 +228,31 @@ Rectangle { if (!id || TimelineManager.timeline.getDump(id, "").isEditable) { TimelineManager.timeline.edit = id; cursorPosition = 0; + Qt.callLater(positionCursorAtEnd); break; } idx++; } - } else if (cursorPosition == messageInput.length) { + } else if (positionAt(0, cursorRectangle.y) === 0) { event.accepted = true; - cursorPosition = 0; + positionCursorAtStart(); } } else if (event.key == Qt.Key_Down && event.modifiers == Qt.NoModifier) { - if (cursorPosition == 0) { - event.accepted = true; - cursorPosition = messageInput.length; - } else if (cursorPosition == messageInput.length && TimelineManager.timeline.edit) { + if (cursorPosition == messageInput.length && TimelineManager.timeline.edit) { event.accepted = true; var idx = TimelineManager.timeline.idToIndex(TimelineManager.timeline.edit) - 1; while (true) { var id = TimelineManager.timeline.indexToId(idx); if (!id || TimelineManager.timeline.getDump(id, "").isEditable) { TimelineManager.timeline.edit = id; + Qt.callLater(positionCursorAtStart); break; } idx--; } + } else if (positionAt(width, cursorRectangle.y + 2) === messageInput.length) { + event.accepted = true; + positionCursorAtEnd(); } } }