fix(StatusChatInput): Remove formatting when pasting, pasting on selection fixed
Fixes #7015 Fixes #7097
This commit is contained in:
parent
037937a04f
commit
dfc7a6a951
|
@ -39,9 +39,8 @@ Rectangle {
|
||||||
property bool emojiPopupOpened: false
|
property bool emojiPopupOpened: false
|
||||||
property bool closeGifPopupAfterSelection: true
|
property bool closeGifPopupAfterSelection: true
|
||||||
|
|
||||||
property bool emojiEvent: false;
|
property bool emojiEvent: false
|
||||||
property bool paste: false;
|
property bool isColonPressed: false
|
||||||
property bool isColonPressed: false;
|
|
||||||
property bool isReply: false
|
property bool isReply: false
|
||||||
property string replyMessageId: replyArea.messageId
|
property string replyMessageId: replyArea.messageId
|
||||||
|
|
||||||
|
@ -53,7 +52,6 @@ Rectangle {
|
||||||
property var recentStickers
|
property var recentStickers
|
||||||
property var stickerPackList
|
property var stickerPackList
|
||||||
|
|
||||||
property int extraHeightFactor: calculateExtraHeightFactor()
|
|
||||||
property int messageLimit: 2000
|
property int messageLimit: 2000
|
||||||
property int messageLimitVisible: 200
|
property int messageLimitVisible: 200
|
||||||
|
|
||||||
|
@ -124,9 +122,16 @@ Rectangle {
|
||||||
|
|
||||||
color: Style.current.transparent
|
color: Style.current.transparent
|
||||||
|
|
||||||
function calculateExtraHeightFactor() {
|
QtObject {
|
||||||
const factor = (messageInputField.length / 500) + 1;
|
id: d
|
||||||
return (factor > 5) ? 5 : factor;
|
|
||||||
|
//mentions helper properties
|
||||||
|
property string copiedTextPlain: ""
|
||||||
|
property string copiedTextFormatted: ""
|
||||||
|
property int copyTextStart: 0
|
||||||
|
|
||||||
|
// set to true when pasted text comes from this component (was copied within this component)
|
||||||
|
property bool internalPaste: false
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertInTextInput(start, text) {
|
function insertInTextInput(start, text) {
|
||||||
|
@ -190,7 +195,7 @@ Rectangle {
|
||||||
// It reset to 0 for some reason, go back to the end
|
// It reset to 0 for some reason, go back to the end
|
||||||
messageInputField.cursorPosition = messageInputField.length
|
messageInputField.cursorPosition = messageInputField.length
|
||||||
}
|
}
|
||||||
mentionsPos.push({"name": aliasName,"leftIndex": lastAtPosition, "rightIndex": (lastAtPosition+aliasName.length+1)});
|
mentionsPos.push({name: aliasName, leftIndex: lastAtPosition, rightIndex: (lastAtPosition+aliasName.length + 1)});
|
||||||
}
|
}
|
||||||
|
|
||||||
function isUploadFilePressed(event) {
|
function isUploadFilePressed(event) {
|
||||||
|
@ -262,18 +267,26 @@ Rectangle {
|
||||||
|
|
||||||
if ((event.key === Qt.Key_C) && (event.modifiers & Qt.ControlModifier)) {
|
if ((event.key === Qt.Key_C) && (event.modifiers & Qt.ControlModifier)) {
|
||||||
if (messageInputField.selectedText !== "") {
|
if (messageInputField.selectedText !== "") {
|
||||||
copiedTextPlain = messageInputField.getText(messageInputField.selectionStart, messageInputField.selectionEnd);
|
d.copiedTextPlain = messageInputField.getText(
|
||||||
copiedTextFormatted = messageInputField.getFormattedText(messageInputField.selectionStart, messageInputField.selectionEnd);
|
messageInputField.selectionStart, messageInputField.selectionEnd)
|
||||||
|
d.copiedTextFormatted = messageInputField.getFormattedText(
|
||||||
|
messageInputField.selectionStart, messageInputField.selectionEnd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((event.key === Qt.Key_V) && (event.modifiers & Qt.ControlModifier)) {
|
if ((event.key === Qt.Key_V) && (event.modifiers & Qt.ControlModifier)) {
|
||||||
if (copiedTextPlain === QClipboardProxy.text) {
|
messageInputField.remove(messageInputField.selectionStart, messageInputField.selectionEnd)
|
||||||
copyTextStart = messageInputField.cursorPosition;
|
|
||||||
paste = true;
|
// cursor position must be stored in a helper property because setting readonly to true causes change
|
||||||
|
// of the cursor position to the end of the input
|
||||||
|
d.copyTextStart = messageInputField.cursorPosition
|
||||||
|
messageInputField.readOnly = true
|
||||||
|
|
||||||
|
if (d.copiedTextPlain === QClipboardProxy.text) {
|
||||||
|
d.internalPaste = true
|
||||||
} else {
|
} else {
|
||||||
copiedTextPlain = "";
|
d.copiedTextPlain = ""
|
||||||
copiedTextFormatted = "";
|
d.copiedTextFormatted = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,11 +438,6 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//mentions helper properties
|
|
||||||
property int copyTextStart: 0
|
|
||||||
property string copiedTextPlain: ""
|
|
||||||
property string copiedTextFormatted: ""
|
|
||||||
|
|
||||||
Instantiator {
|
Instantiator {
|
||||||
id: dummyContactList
|
id: dummyContactList
|
||||||
model: control.usersStore ? control.usersStore.usersModel : []
|
model: control.usersStore ? control.usersStore.usersModel : []
|
||||||
|
@ -446,25 +454,37 @@ Rectangle {
|
||||||
// the text doesn't get registered to the textarea fast enough
|
// the text doesn't get registered to the textarea fast enough
|
||||||
// we can only get it in the `released` event
|
// we can only get it in the `released` event
|
||||||
|
|
||||||
if (paste) {
|
messageInputField.readOnly = false
|
||||||
if (copiedTextPlain.includes("@")) {
|
|
||||||
copiedTextFormatted = copiedTextFormatted.replace(/underline/g, "none").replace(/span style="/g, "span style=\" text-decoration:none;")
|
if (d.internalPaste) {
|
||||||
|
if (d.copiedTextPlain.includes("@")) {
|
||||||
|
d.copiedTextFormatted = d.copiedTextFormatted.replace(/underline/g, "none").replace(/span style="/g, "span style=\" text-decoration:none;")
|
||||||
for (let j = 0; j < dummyContactList.count; j++) {
|
for (let j = 0; j < dummyContactList.count; j++) {
|
||||||
const name = dummyContactList.objectAt(j).contactName
|
const name = dummyContactList.objectAt(j).contactName
|
||||||
|
|
||||||
if (copiedTextPlain.indexOf(name) > -1) {
|
if (d.copiedTextPlain.indexOf(name) > -1) {
|
||||||
const subStr = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
const subStr = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||||
const regex = new RegExp(subStr, 'gi')
|
const regex = new RegExp(subStr, 'gi')
|
||||||
let result = null
|
let result = null
|
||||||
while ((result = regex.exec(copiedTextPlain))) {
|
while ((result = regex.exec(d.copiedTextPlain))) {
|
||||||
mentionsPos.push({"name": name, "leftIndex": (result.index + copyTextStart - 1), "rightIndex": (result.index + copyTextStart + name.length)})
|
const mention = {
|
||||||
|
name: name,
|
||||||
|
leftIndex: (result.index + d.copyTextStart - 1),
|
||||||
|
rightIndex: (result.index + d.copyTextStart + name.length)
|
||||||
|
}
|
||||||
|
mentionsPos.push(mention)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messageInputField.remove(copyTextStart, (copyTextStart + copiedTextPlain.length))
|
|
||||||
insertInTextInput(copyTextStart, copiedTextFormatted)
|
const prevLength = messageInputField.length
|
||||||
paste = false
|
insertInTextInput(d.copyTextStart, d.copiedTextFormatted)
|
||||||
|
messageInputField.cursorPosition = d.copyTextStart + messageInputField.length - prevLength
|
||||||
|
d.internalPaste = false
|
||||||
|
} else if ((event.key === Qt.Key_V) && (event.modifiers & Qt.ControlModifier)) {
|
||||||
|
insertInTextInput(d.copyTextStart, QClipboardProxy.text)
|
||||||
|
messageInputField.cursorPosition = d.copyTextStart + QClipboardProxy.text.length
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key !== Qt.Key_Escape) {
|
if (event.key !== Qt.Key_Escape) {
|
||||||
|
@ -549,7 +569,7 @@ Rectangle {
|
||||||
if (index2 >= 0 && message.cursor > 0) {
|
if (index2 >= 0 && message.cursor > 0) {
|
||||||
const emojiPart = message.data.substr(index2, message.cursor);
|
const emojiPart = message.data.substr(index2, message.cursor);
|
||||||
if (emojiPart.length > 2) {
|
if (emojiPart.length > 2) {
|
||||||
const emojis = EmojiJSON.emoji_json.filter(function (emoji) {
|
const emojis = StatusQUtils.Emoji.emojiJSON.emoji_json.filter(function (emoji) {
|
||||||
return emoji.name.includes(emojiPart) ||
|
return emoji.name.includes(emojiPart) ||
|
||||||
emoji.shortname.includes(emojiPart) ||
|
emoji.shortname.includes(emojiPart) ||
|
||||||
emoji.aliases.some(a => a.includes(emojiPart))
|
emoji.aliases.some(a => a.includes(emojiPart))
|
||||||
|
|
Loading…
Reference in New Issue