[#2650] Fixed pasting rich text in text box

* Text copied from clipboard that included images
  and other rich content was not visible in text
  box when pasted, modified to keep only plain
  text instead and removed unnecessary funtions
* Also removed unecessary Rectangle in Input

Closes #2650
This commit is contained in:
Alexandra Betouni 2021-07-15 13:35:15 +03:00 committed by Iuri Matias
parent ecb2bac6e5
commit c1a6e57ca6
2 changed files with 27 additions and 69 deletions

View File

@ -59,25 +59,13 @@ Item {
color: Style.current.textColor color: Style.current.textColor
} }
Rectangle { Item {
id: inputRectangle id: inputField
height: customHeight
color: bgColor
radius: Style.current.radius
anchors.top: inputBox.hasLabel ? inputLabel.bottom : parent.top
anchors.topMargin: inputBox.hasLabel ? inputBox.labelMargin : 0
anchors.right: parent.right anchors.right: parent.right
anchors.left: parent.left anchors.left: parent.left
border.width: (!!validationError || inputValue.focus) ? 1 : 0 height: customHeight
border.color: { anchors.top: inputBox.hasLabel ? inputLabel.bottom : parent.top
if (!!validationError) { anchors.topMargin: inputBox.hasLabel ? inputBox.labelMargin : 0
return validationErrorColor
}
if (!inputBox.readOnly && inputValue.focus) {
return Style.current.inputBorderFocus
}
return Style.current.transparent
}
StyledTextField { StyledTextField {
id: inputValue id: inputValue
@ -97,7 +85,20 @@ Item {
font.pixelSize: fontPixelSize font.pixelSize: fontPixelSize
readOnly: inputBox.readOnly readOnly: inputBox.readOnly
background: Rectangle { background: Rectangle {
color: Style.current.transparent id: inputRectangle
anchors.fill: parent
color: bgColor
radius: Style.current.radius
border.width: (!!validationError || inputValue.focus) ? 1 : 0
border.color: {
if (!!validationError) {
return validationErrorColor
}
if (!inputBox.readOnly && inputValue.focus) {
return Style.current.inputBorderFocus
}
return Style.current.transparent
}
} }
onEditingFinished: inputBox.editingFinished(inputBox.text) onEditingFinished: inputBox.editingFinished(inputBox.text)
onTextEdited: inputBox.textEdited(inputBox.text) onTextEdited: inputBox.textEdited(inputBox.text)

View File

@ -231,10 +231,6 @@ Rectangle {
return htmlText.replace(/\:asterisk\:/gim, "*") return htmlText.replace(/\:asterisk\:/gim, "*")
} }
function parseBackText(plainText) {
return parseMarkdown(Emoji.parse(plainText.replace(/\n/g, "<br />")))
}
function getFormattedText(start, end) { function getFormattedText(start, end) {
start = start || 0 start = start || 0
end = end || messageInputField.length end = end || messageInputField.length
@ -311,27 +307,19 @@ Rectangle {
if (event.key === Qt.Key_Backspace && textFormatMenu.opened) { if (event.key === Qt.Key_Backspace && textFormatMenu.opened) {
textFormatMenu.close() textFormatMenu.close()
} }
// 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) { if (paste) {
paste = false; paste = false;
interrogateMessage(); const plainText = messageInputField.getText(0, messageInputField.length);
// TODO use the new formatInputMessage function instead messageInputField.remove(0, messageInputField.length);
const plainText = getPlainText() insertInTextInput(0, plainText);
const newText = parseBackText(plainText) } else if (event.key === Qt.Key_Asterisk ||
const finalText = newText.replace("<", "&lt;")
messageInputField.remove(0, messageInputField.length)
insertInTextInput(0, finalText)
} else {
if (event.key === Qt.Key_Asterisk ||
event.key === Qt.Key_QuoteLeft || event.key === Qt.Key_QuoteLeft ||
event.key === Qt.Key_Space || event.key === Qt.Key_Space ||
event.key === Qt.Key_AsciiTilde) { event.key === Qt.Key_AsciiTilde) {
formatInputMessage() formatInputMessage()
} }
}
if (event.key !== Qt.Key_Escape) { if (event.key !== Qt.Key_Escape) {
emojiEvent = emojiHandler(event); emojiEvent = emojiHandler(event);
@ -341,37 +329,6 @@ Rectangle {
} }
} }
function interrogateMessage() {
// TODO change this function to use remove and insert instead of replcing the whole text
const text = chatsModel.plainText(Emoji.deparse(messageInputField.text));
var words = text.split(' ');
let madeChanges = false
let transform = true;
for (var i = 0; i < words.length; i++) {
transform = true;
if (words[i].charAt(0) === ':') {
for (var j = 0; j < words[i].length; j++) {
if (Utils.isSpace(words[i].charAt(j)) === true || Utils.isPunct(words[i].charAt(j)) === true) {
transform = false;
}
}
if (transform) {
madeChanges = true
const codePoint = Emoji.getEmojiUnicode(words[i]);
words[i] = words[i].replace(words[i], (codePoint !== undefined) ? Emoji.fromCodePoint(codePoint) : words[i]);
}
}
}
if (madeChanges) {
messageInputField.remove(0, messageInputField.length);
insertInTextInput(0, Emoji.parse(words.join('&nbsp;')));
}
}
// since emoji length is not 1 we need to match that position that TextArea returns // since emoji length is not 1 we need to match that position that TextArea returns
// to the actual position in the string. // to the actual position in the string.
function extrapolateCursorPosition() { function extrapolateCursorPosition() {