Focus input area on room switch and reply change again

fixes #412
fixes #413
This commit is contained in:
Nicolas Werner 2021-01-25 16:17:14 +01:00
parent be49d184be
commit 2165eb8cb8
2 changed files with 41 additions and 31 deletions

View file

@ -98,29 +98,28 @@ Rectangle {
clip: true clip: true
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
flickableDirection: Flickable.VerticalFlick flickableDirection: Flickable.VerticalFlick
implicitWidth: textArea.width implicitWidth: messageInput.width
implicitHeight: textArea.height implicitHeight: messageInput.height
contentWidth: textArea.width contentWidth: messageInput.width
contentHeight: textArea.height contentHeight: messageInput.height
TextArea { TextArea {
id: textArea id: messageInput
property int completerTriggeredAt: -1 property int completerTriggeredAt: -1
function insertCompletion(completion) { function insertCompletion(completion) {
textArea.remove(completerTriggeredAt, cursorPosition); messageInput.remove(completerTriggeredAt, cursorPosition);
textArea.insert(cursorPosition, completion); messageInput.insert(cursorPosition, completion);
} }
function openCompleter(pos, type) { function openCompleter(pos, type) {
completerTriggeredAt = pos; completerTriggeredAt = pos;
popup.completerName = type; popup.completerName = type;
popup.open(); popup.open();
popup.completer.setSearchString(textArea.getText(completerTriggeredAt, cursorPosition)); popup.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition));
} }
text: "asfkajsdf"
selectByMouse: true selectByMouse: true
placeholderText: qsTr("Write a message...") placeholderText: qsTr("Write a message...")
//placeholderTextColor: colors.buttonText //placeholderTextColor: colors.buttonText
@ -152,7 +151,7 @@ Rectangle {
popup.close(); popup.close();
} }
if (popup.opened) if (popup.opened)
popup.completer.setSearchString(textArea.getText(completerTriggeredAt, cursorPosition)); popup.completer.setSearchString(messageInput.getText(completerTriggeredAt, cursorPosition));
} }
onSelectionStartChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text) onSelectionStartChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
@ -164,16 +163,16 @@ Rectangle {
TimelineManager.timeline.input.paste(false); TimelineManager.timeline.input.paste(false);
event.accepted = true; event.accepted = true;
} else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_U) { } else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_U) {
textArea.clear(); messageInput.clear();
} else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_P) { } else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_P) {
textArea.text = TimelineManager.timeline.input.previousText(); messageInput.text = TimelineManager.timeline.input.previousText();
} else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_N) { } else if (event.modifiers == Qt.ControlModifier && event.key == Qt.Key_N) {
textArea.text = TimelineManager.timeline.input.nextText(); messageInput.text = TimelineManager.timeline.input.nextText();
} else if (event.key == Qt.Key_At) { } else if (event.key == Qt.Key_At) {
textArea.openCompleter(cursorPosition, "user"); messageInput.openCompleter(cursorPosition, "user");
popup.open(); popup.open();
} else if (event.key == Qt.Key_Colon) { } else if (event.key == Qt.Key_Colon) {
textArea.openCompleter(cursorPosition, "emoji"); messageInput.openCompleter(cursorPosition, "emoji");
popup.open(); popup.open();
} else if (event.key == Qt.Key_Escape && popup.opened) { } else if (event.key == Qt.Key_Escape && popup.opened) {
completerTriggeredAt = -1; completerTriggeredAt = -1;
@ -186,13 +185,13 @@ Rectangle {
popup.completerName = ""; popup.completerName = "";
popup.close(); popup.close();
if (currentCompletion) { if (currentCompletion) {
textArea.insertCompletion(currentCompletion); messageInput.insertCompletion(currentCompletion);
event.accepted = true; event.accepted = true;
return ; return ;
} }
} }
TimelineManager.timeline.input.send(); TimelineManager.timeline.input.send();
textArea.clear(); messageInput.clear();
event.accepted = true; event.accepted = true;
} else if (event.key == Qt.Key_Tab) { } else if (event.key == Qt.Key_Tab) {
event.accepted = true; event.accepted = true;
@ -201,19 +200,19 @@ Rectangle {
} else { } else {
var pos = cursorPosition - 1; var pos = cursorPosition - 1;
while (pos > -1) { while (pos > -1) {
var t = textArea.getText(pos, pos + 1); var t = messageInput.getText(pos, pos + 1);
console.log('"' + t + '"'); console.log('"' + t + '"');
if (t == '@' || t == ' ' || t == '\t') { if (t == '@' || t == ' ' || t == '\t') {
textArea.openCompleter(pos, "user"); messageInput.openCompleter(pos, "user");
return ; return ;
} else if (t == ':') { } else if (t == ':') {
textArea.openCompleter(pos, "emoji"); messageInput.openCompleter(pos, "emoji");
return ; return ;
} }
pos = pos - 1; pos = pos - 1;
} }
// At start of input // At start of input
textArea.openCompleter(0, "user"); messageInput.openCompleter(0, "user");
} }
} else if (event.key == Qt.Key_Up && popup.opened) { } else if (event.key == Qt.Key_Up && popup.opened) {
event.accepted = true; event.accepted = true;
@ -226,33 +225,43 @@ Rectangle {
background: null background: null
Connections { Connections {
onTimelineChanged: { onActiveTimelineChanged: {
textArea.clear(); messageInput.clear();
textArea.append(TimelineManager.timeline.input.text()); messageInput.append(TimelineManager.timeline.input.text());
textArea.completerTriggeredAt = -1; messageInput.completerTriggeredAt = -1;
popup.completerName = ""; popup.completerName = "";
messageInput.forceActiveFocus();
} }
target: TimelineManager target: TimelineManager
} }
Connections { Connections {
onCompletionClicked: textArea.insertCompletion(completion) onCompletionClicked: messageInput.insertCompletion(completion)
target: popup target: popup
} }
Completer { Completer {
id: popup id: popup
x: textArea.completerTriggeredAt >= 0 ? textArea.positionToRectangle(textArea.completerTriggeredAt).x : 0 x: messageInput.completerTriggeredAt >= 0 ? messageInput.positionToRectangle(messageInput.completerTriggeredAt).x : 0
y: textArea.completerTriggeredAt >= 0 ? textArea.positionToRectangle(textArea.completerTriggeredAt).y - height : 0 y: messageInput.completerTriggeredAt >= 0 ? messageInput.positionToRectangle(messageInput.completerTriggeredAt).y - height : 0
} }
Connections { Connections {
ignoreUnknownSignals: true ignoreUnknownSignals: true
onInsertText: textArea.insert(textArea.cursorPosition, text) onInsertText: messageInput.insert(messageInput.cursorPosition, text)
target: TimelineManager.timeline ? TimelineManager.timeline.input : null target: TimelineManager.timeline ? TimelineManager.timeline.input : null
} }
Connections {
ignoreUnknownSignals: true
onReplyChanged: {
messageInput.forceActiveFocus();
console.log("sakjlsdgfjsadfglkjsdfg");
}
target: TimelineManager.timeline
}
MouseArea { MouseArea {
// workaround for wrong cursor shape on some platforms // workaround for wrong cursor shape on some platforms
anchors.fill: parent anchors.fill: parent
@ -284,7 +293,7 @@ Rectangle {
ToolTip.visible: hovered ToolTip.visible: hovered
ToolTip.text: qsTr("Emoji") ToolTip.text: qsTr("Emoji")
onClicked: emojiPopup.visible ? emojiPopup.close() : emojiPopup.show(emojiButton, function(emoji) { onClicked: emojiPopup.visible ? emojiPopup.close() : emojiPopup.show(emojiButton, function(emoji) {
textArea.insert(textArea.cursorPosition, emoji); messageInput.insert(messageInput.cursorPosition, emoji);
}) })
} }
@ -299,7 +308,7 @@ Rectangle {
ToolTip.text: qsTr("Send") ToolTip.text: qsTr("Send")
onClicked: { onClicked: {
TimelineManager.timeline.input.send(); TimelineManager.timeline.input.send();
textArea.clear(); messageInput.clear();
} }
} }

View file

@ -124,6 +124,7 @@ Page {
text: qsTr("Save as") text: qsTr("Save as")
onTriggered: TimelineManager.timeline.saveMedia(messageContextMenu.eventId) onTriggered: TimelineManager.timeline.saveMedia(messageContextMenu.eventId)
} }
MenuItem { MenuItem {
visible: messageContextMenu.eventType == MtxEvent.ImageMessage || messageContextMenu.eventType == MtxEvent.VideoMessage || messageContextMenu.eventType == MtxEvent.AudioMessage || messageContextMenu.eventType == MtxEvent.FileMessage || messageContextMenu.eventType == MtxEvent.Sticker visible: messageContextMenu.eventType == MtxEvent.ImageMessage || messageContextMenu.eventType == MtxEvent.VideoMessage || messageContextMenu.eventType == MtxEvent.AudioMessage || messageContextMenu.eventType == MtxEvent.FileMessage || messageContextMenu.eventType == MtxEvent.Sticker
height: visible ? implicitHeight : 0 height: visible ? implicitHeight : 0