Browse Source

Merge branch 'ui-tweaks' of cwtch.im/ui into master

pull/204/head
erinn 5 months ago
parent
commit
f029da4c49
2 changed files with 19 additions and 14 deletions
  1. 2
    1
      qml/main.qml
  2. 17
    13
      qml/overlays/ChatOverlay.qml

+ 2
- 1
qml/main.qml View File

@@ -37,7 +37,8 @@ ApplicationWindow {
T.twemoji.ext = ".png"
T.twemoji.size = "72x72"
T.twemoji.className = "\" height=\""+size+"\" width=\""+size
return T.twemoji.parse(Utils.htmlEscaped(text))
var retText = T.twemoji.parse(Utils.htmlEscaped(text))
return retText.replace(/\n/g,"<br/>")
}

function restoreEmoji(text) { // REPLACE <IMG> TAGS WITH EMOJI

+ 17
- 13
qml/overlays/ChatOverlay.qml View File

@@ -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, "&nbsp;&nbsp;");
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++)
}
}

Loading…
Cancel
Save