Add a setting to send messages with Enter, Shift+Enter or Ctrl+Enter
Previously the option was just `invertEnterKey` boolean, which didn't allow any flexibility, so I replaced it with a three-choice option: Enter, Shift+Enter and Ctrl+Enter being the send message choices. Add newline combos are Shift+Enter, Enter and Shift+Enter respectively. I ended up fixing the emoji/mention pop-up behavior as a side product. If any of the three combos are pressed, the pop-up is handled and the event is accepted. This makes it impossible to accidentally send the message if a pop-up is open. If an Enter combo didn't match, it's passed to the next event handler. The old `invertEnterKey` is migrated to the new `sendMessageKey`, so this change doesn't change the existing preference.
This commit is contained in:
parent
2769642d3c
commit
451e88fe72
3 changed files with 81 additions and 42 deletions
|
|
@ -170,15 +170,13 @@ Rectangle {
|
|||
} else if (event.matches(StandardKey.SelectAll) && popup.opened) {
|
||||
completer.completerName = "";
|
||||
popup.close();
|
||||
} else if (event.matches(StandardKey.InsertLineSeparator)) {
|
||||
if (popup.opened)
|
||||
popup.close();
|
||||
if (Settings.invertEnterKey) {
|
||||
room.input.send();
|
||||
event.accepted = true;
|
||||
}
|
||||
} else if (event.matches(StandardKey.InsertParagraphSeparator)) {
|
||||
if (popup.opened) {
|
||||
} else if (event.key == Qt.Key_Enter || event.key == Qt.Key_Return) {
|
||||
// Handling popup takes priority over newline and sending message.
|
||||
if (popup.opened &&
|
||||
(event.modifiers == Qt.NoModifier
|
||||
|| event.modifiers == Qt.ShiftModifier
|
||||
|| event.modifiers == Qt.ControlModifier)
|
||||
) {
|
||||
var currentCompletion = completer.currentCompletion();
|
||||
let userid = completer.currentUserid();
|
||||
|
||||
|
|
@ -191,14 +189,26 @@ Rectangle {
|
|||
console.log(userid);
|
||||
room.input.addMention(userid, currentCompletion);
|
||||
}
|
||||
event.accepted = true;
|
||||
return;
|
||||
}
|
||||
event.accepted = true;
|
||||
}
|
||||
if (!Settings.invertEnterKey) {
|
||||
// Send message Enter key combination event.
|
||||
else if (Settings.sendMessageKey == 0 && event.modifiers == Qt.NoModifier
|
||||
|| Settings.sendMessageKey == 1 && event.modifiers == Qt.ShiftModifier
|
||||
|| Settings.sendMessageKey == 2 && event.modifiers == Qt.ControlModifier
|
||||
) {
|
||||
room.input.send();
|
||||
event.accepted = true;
|
||||
}
|
||||
// Add newline Enter key combination event.
|
||||
else if (Settings.sendMessageKey == 0 && event.modifiers == Qt.ShiftModifier
|
||||
|| Settings.sendMessageKey == 1 && event.modifiers == Qt.NoModifier
|
||||
|| Settings.sendMessageKey == 2 && event.modifiers == Qt.ShiftModifier
|
||||
) {
|
||||
messageInput.insert(messageInput.cursorPosition, "\n");
|
||||
event.accepted = true;
|
||||
}
|
||||
// Any other Enter key combo is ignored here.
|
||||
} else if (event.key == Qt.Key_Tab && (event.modifiers == Qt.NoModifier || event.modifiers == Qt.ShiftModifier)) {
|
||||
event.accepted = true;
|
||||
if (popup.opened) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue