|
|
|
@ -168,6 +168,7 @@ ColumnLayout {
|
|
|
|
|
width: rectMessage.width
|
|
|
|
|
|
|
|
|
|
property bool skipOneUpdate: false
|
|
|
|
|
property int previousCursor
|
|
|
|
|
|
|
|
|
|
Keys.onReturnPressed: { // CTRL+ENTER = LINEBREAK
|
|
|
|
|
if ((event.modifiers & Qt.ControlModifier) && gcd.os != "android") {
|
|
|
|
@ -185,8 +186,6 @@ ColumnLayout {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//console.log("onTextChanged()")
|
|
|
|
|
|
|
|
|
|
// we're taking advantage of TextEdit.getText()'s parsing capability, which means occasionally
|
|
|
|
|
// passing text into it to be filtered. this prevents recursive calls putting us into an
|
|
|
|
|
// infinite loop
|
|
|
|
@ -195,6 +194,9 @@ ColumnLayout {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
previousCursor = cursorPosition
|
|
|
|
|
//console.log("onTextChanged() at position " + previousCursor)
|
|
|
|
|
|
|
|
|
|
//console.log("1: " + txtMessage.getText(0, txtMessage.text.length))
|
|
|
|
|
|
|
|
|
|
// convert <img> tags back to their emoji form
|
|
|
|
@ -206,7 +208,11 @@ ColumnLayout {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//console.log("2: " + txtMessage.getText(0, txtMessage.text.length))
|
|
|
|
|
|
|
|
|
|
var preserveSpaces = txtMessage.text.replace(/<br \/>/g,"[:newline:]");
|
|
|
|
|
if (preserveSpaces != txtMessage.text) {
|
|
|
|
|
skipOneUpdate = true
|
|
|
|
|
txtMessage.text = preserveSpaces
|
|
|
|
|
}
|
|
|
|
|
// strip all HTML tags
|
|
|
|
|
var theText = Utils.htmlEscaped(txtMessage.getText(0, txtMessage.text.length))
|
|
|
|
|
//console.log("3: " + theText)
|
|
|
|
@ -215,19 +221,15 @@ ColumnLayout {
|
|
|
|
|
nt = parse(theText, 10)
|
|
|
|
|
//console.log("4: " + nt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// first we need to update the cursor position to be the same distance from the end
|
|
|
|
|
var oldcursor = txtMessage.cursorPosition
|
|
|
|
|
var oldlen = txtMessage.getText(0, txtMessage.text.length).length
|
|
|
|
|
// preserve double spacing
|
|
|
|
|
nt = nt.replace(/\s\s/g, " ");
|
|
|
|
|
nt = nt.replace(/\[\:newline\:\]/g, "<br/>");
|
|
|
|
|
|
|
|
|
|
// then we actually put the updated text in
|
|
|
|
|
skipOneUpdate = true
|
|
|
|
|
txtMessage.text = nt
|
|
|
|
|
|
|
|
|
|
// and then restore the cursor
|
|
|
|
|
var newlen = txtMessage.getText(0, txtMessage.text.length).length
|
|
|
|
|
txtMessage.cursorPosition = newlen - (oldlen - oldcursor)
|
|
|
|
|
|
|
|
|
|
txtMessage.cursorPosition = previousCursor
|
|
|
|
|
|
|
|
|
|
// autoscroll down only when the scrollbar is already all the way down
|
|
|
|
|
if (flkMessage.contentY + flkMessage.height >= flkMessage.contentHeight - txtMessage.height && flkMessage.contentHeight > flkMessage.height) {
|
|
|
|
@ -263,9 +265,11 @@ ColumnLayout {
|
|
|
|
|
onClicked: {
|
|
|
|
|
if (txtMessage.text != "") {
|
|
|
|
|
txtHidden.text = restoreEmoji(txtMessage.text)
|
|
|
|
|
var txt = txtHidden.getText(0, txtHidden.text.length).trim()
|
|
|
|
|
txtHidden.text = txtHidden.text.replace(/<br \/>/g,"[:newline:]");
|
|
|
|
|
var txt = txtHidden.text.trim()
|
|
|
|
|
if (txt.length > 0) {
|
|
|
|
|
var msg = JSON.stringify({"o":1, "d":txtHidden.getText(0, txtHidden.text.length)})
|
|
|
|
|
var rawText = txtHidden.getText(0, txtHidden.text.length)
|
|
|
|
|
var msg = JSON.stringify({"o":1, "d":rawText.replace(/\[\:newline\:\]/g,"\n")})
|
|
|
|
|
gcd.sendMessage(msg, nextMessageID++)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|