fix: fix spaces and line breaks disappearing when pasting
This commit is contained in:
parent
d9fe903c74
commit
6fc56b5035
|
@ -26,6 +26,11 @@ Rectangle {
|
||||||
volume: appSettings.volume
|
volume: appSettings.volume
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function insertInTextInput(start, text) {
|
||||||
|
// Repace new lines with entities because `insert` gets rid of them
|
||||||
|
txtData.insert(start, text.replace(/\n/g, "<br/>"));
|
||||||
|
}
|
||||||
|
|
||||||
function interpretMessage(msg) {
|
function interpretMessage(msg) {
|
||||||
if (msg === "/shrug") {
|
if (msg === "/shrug") {
|
||||||
return "¯\\\\\\_(ツ)\\_/¯"
|
return "¯\\\\\\_(ツ)\\_/¯"
|
||||||
|
@ -58,11 +63,11 @@ Rectangle {
|
||||||
sendMsg(event);
|
sendMsg(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((event.key == Qt.Key_V) && (event.modifiers & Qt.ControlModifier)) {
|
if ((event.key === Qt.Key_V) && (event.modifiers & Qt.ControlModifier)) {
|
||||||
paste = true;
|
paste = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
isColonPressed = (event.key == Qt.Key_Colon) && (event.modifiers & Qt.ShiftModifier);
|
isColonPressed = (event.key === Qt.Key_Colon) && (event.modifiers & Qt.ShiftModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onRelease(event) {
|
function onRelease(event) {
|
||||||
|
@ -101,7 +106,7 @@ Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
txtData.remove(0, txtData.length);
|
txtData.remove(0, txtData.length);
|
||||||
txtData.insert(0, Emoji.parse(words.join(' '), '26x26'));
|
insertInTextInput(0, Emoji.parse(words.join(' '), '26x26'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function emojiHandler(event) {
|
function emojiHandler(event) {
|
||||||
|
@ -116,9 +121,13 @@ Rectangle {
|
||||||
if (index >= 0 && message.cursor > 0) {
|
if (index >= 0 && message.cursor > 0) {
|
||||||
const shortname = message.data.substr(index, message.cursor);
|
const shortname = message.data.substr(index, message.cursor);
|
||||||
const codePoint = Emoji.getEmojiUnicode(shortname);
|
const codePoint = Emoji.getEmojiUnicode(shortname);
|
||||||
const newMessage = message.data.replace(shortname, (codePoint !== undefined) ? Emoji.fromCodePoint(codePoint) : shortname);
|
if (codePoint !== undefined) {
|
||||||
txtData.remove(0, txtData.cursorPosition);
|
const newMessage = message.data
|
||||||
txtData.insert(0, Emoji.parse(newMessage, '26x26'));
|
.replace(shortname, Emoji.fromCodePoint(codePoint))
|
||||||
|
.replace(/ /g, " ");
|
||||||
|
txtData.remove(0, txtData.cursorPosition);
|
||||||
|
insertInTextInput(0, Emoji.parse(newMessage, '26x26'));
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -160,10 +169,9 @@ Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
let textBeforeCursor = Emoji.deparseFromParse(plainText.substr(0, i));
|
let textBeforeCursor = Emoji.deparseFromParse(plainText.substr(0, i));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cursor: countEmojiLengths(plainText.substr(0, i)) + txtData.cursorPosition,
|
cursor: countEmojiLengths(plainText.substr(0, i)) + txtData.cursorPosition,
|
||||||
data: chatsModel.plainText(Emoji.deparseFromParse(textBeforeCursor)),
|
data: Emoji.deparseFromParse(textBeforeCursor),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,8 +281,8 @@ Rectangle {
|
||||||
height: parent.height
|
height: parent.height
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
addToChat: function (text) {
|
addToChat: function (text, atCursor) {
|
||||||
txtData.insert(txtData.length, text)
|
insertInTextInput(atCursor ? txtData.cursorPosition :txtData.length, text)
|
||||||
}
|
}
|
||||||
onSend: function(){
|
onSend: function(){
|
||||||
sendMsg(false)
|
sendMsg(false)
|
||||||
|
|
|
@ -64,7 +64,7 @@ Popup {
|
||||||
emojiSectionsRepeater.itemAt(0).allEmojis = recentEmojis
|
emojiSectionsRepeater.itemAt(0).allEmojis = recentEmojis
|
||||||
appSettings.recentEmojis = recentEmojis
|
appSettings.recentEmojis = recentEmojis
|
||||||
|
|
||||||
popup.addToChat(Emoji.parse(encodedIcon, "26x26") + ' ') // Adding a space because otherwise, some emojis would fuse since it's just an emoji is just a string
|
popup.addToChat(Emoji.parse(encodedIcon, "26x26") + ' ', true) // Adding a space because otherwise, some emojis would fuse since it's just an emoji is just a string
|
||||||
popup.close()
|
popup.close()
|
||||||
chatInput.textInput.forceActiveFocus()
|
chatInput.textInput.forceActiveFocus()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue