Fix cursor positioning on edits

fixes #502
This commit is contained in:
Nicolas Werner 2021-04-15 23:21:50 +02:00
parent 3022178334
commit eaa91b4e56
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
1 changed files with 16 additions and 6 deletions

View File

@ -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();
}
}
}