[#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:
parent
ecb2bac6e5
commit
c1a6e57ca6
|
@ -59,25 +59,13 @@ Item {
|
|||
color: Style.current.textColor
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: inputRectangle
|
||||
height: customHeight
|
||||
color: bgColor
|
||||
radius: Style.current.radius
|
||||
anchors.top: inputBox.hasLabel ? inputLabel.bottom : parent.top
|
||||
anchors.topMargin: inputBox.hasLabel ? inputBox.labelMargin : 0
|
||||
Item {
|
||||
id: inputField
|
||||
anchors.right: parent.right
|
||||
anchors.left: parent.left
|
||||
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
|
||||
}
|
||||
height: customHeight
|
||||
anchors.top: inputBox.hasLabel ? inputLabel.bottom : parent.top
|
||||
anchors.topMargin: inputBox.hasLabel ? inputBox.labelMargin : 0
|
||||
|
||||
StyledTextField {
|
||||
id: inputValue
|
||||
|
@ -97,7 +85,20 @@ Item {
|
|||
font.pixelSize: fontPixelSize
|
||||
readOnly: inputBox.readOnly
|
||||
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)
|
||||
onTextEdited: inputBox.textEdited(inputBox.text)
|
||||
|
|
|
@ -231,10 +231,6 @@ Rectangle {
|
|||
return htmlText.replace(/\:asterisk\:/gim, "*")
|
||||
}
|
||||
|
||||
function parseBackText(plainText) {
|
||||
return parseMarkdown(Emoji.parse(plainText.replace(/\n/g, "<br />")))
|
||||
}
|
||||
|
||||
function getFormattedText(start, end) {
|
||||
start = start || 0
|
||||
end = end || messageInputField.length
|
||||
|
@ -311,26 +307,18 @@ Rectangle {
|
|||
if (event.key === Qt.Key_Backspace && textFormatMenu.opened) {
|
||||
textFormatMenu.close()
|
||||
}
|
||||
|
||||
// the text doesn't get registered to the textarea fast enough
|
||||
// we can only get it in the `released` event
|
||||
if (paste) {
|
||||
paste = false;
|
||||
interrogateMessage();
|
||||
// TODO use the new formatInputMessage function instead
|
||||
const plainText = getPlainText()
|
||||
const newText = parseBackText(plainText)
|
||||
const finalText = newText.replace("<", "<")
|
||||
|
||||
messageInputField.remove(0, messageInputField.length)
|
||||
insertInTextInput(0, finalText)
|
||||
} else {
|
||||
if (event.key === Qt.Key_Asterisk ||
|
||||
event.key === Qt.Key_QuoteLeft ||
|
||||
event.key === Qt.Key_Space ||
|
||||
event.key === Qt.Key_AsciiTilde) {
|
||||
formatInputMessage()
|
||||
}
|
||||
const plainText = messageInputField.getText(0, messageInputField.length);
|
||||
messageInputField.remove(0, messageInputField.length);
|
||||
insertInTextInput(0, plainText);
|
||||
} else if (event.key === Qt.Key_Asterisk ||
|
||||
event.key === Qt.Key_QuoteLeft ||
|
||||
event.key === Qt.Key_Space ||
|
||||
event.key === Qt.Key_AsciiTilde) {
|
||||
formatInputMessage()
|
||||
}
|
||||
|
||||
if (event.key !== Qt.Key_Escape) {
|
||||
|
@ -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(' ')));
|
||||
}
|
||||
}
|
||||
|
||||
// since emoji length is not 1 we need to match that position that TextArea returns
|
||||
// to the actual position in the string.
|
||||
function extrapolateCursorPosition() {
|
||||
|
|
Loading…
Reference in New Issue