feat: enable unwrapping text formations with the buttons
This commit is contained in:
parent
853c23030c
commit
f2f2707d68
|
@ -412,6 +412,7 @@ DISTFILES += \
|
||||||
shared/img/loading.svg \
|
shared/img/loading.svg \
|
||||||
shared/img/status-logo.png \
|
shared/img/status-logo.png \
|
||||||
shared/qmldir \
|
shared/qmldir \
|
||||||
|
shared/status/StatusChatInputTextFormationAction.qml \
|
||||||
shared/status/StatusEmojiSuggestionPopup.qml \
|
shared/status/StatusEmojiSuggestionPopup.qml \
|
||||||
shared/status/StatusInputListPopup.qml \
|
shared/status/StatusInputListPopup.qml \
|
||||||
shared/status/StatusRadioButtonRow.qml \
|
shared/status/StatusRadioButtonRow.qml \
|
||||||
|
|
|
@ -220,6 +220,17 @@ Rectangle {
|
||||||
messageInputField.deselect()
|
messageInputField.deselect()
|
||||||
formatInputMessage()
|
formatInputMessage()
|
||||||
}
|
}
|
||||||
|
function unwrapSelection(unwrapWith) {
|
||||||
|
if (messageInputField.selectionStart - messageInputField.selectionEnd === 0) return
|
||||||
|
|
||||||
|
const text = messageInputField.getText(messageInputField.selectionStart, messageInputField.selectionEnd)
|
||||||
|
const changedString = text.replace(unwrapWith, '').replace(unwrapWith, '')
|
||||||
|
messageInputField.remove(messageInputField.selectionStart, messageInputField.selectionEnd)
|
||||||
|
insertInTextInput(messageInputField.selectionStart, changedString)
|
||||||
|
|
||||||
|
messageInputField.deselect()
|
||||||
|
formatInputMessage()
|
||||||
|
}
|
||||||
|
|
||||||
function getPlainText() {
|
function getPlainText() {
|
||||||
const textWithoutMention = messageInputField.text.replace(/<span style="[ :#0-9a-z;\-\.,\(\)]+">(@([a-z\.]+(\ ?[a-z]+\ ?[a-z]+)?))<\/span>/ig, "\[\[mention\]\]$1\[\[mention\]\]")
|
const textWithoutMention = messageInputField.text.replace(/<span style="[ :#0-9a-z;\-\.,\(\)]+">(@([a-z\.]+(\ ?[a-z]+\ ?[a-z]+)?))<\/span>/ig, "\[\[mention\]\]$1\[\[mention\]\]")
|
||||||
|
@ -843,44 +854,39 @@ Rectangle {
|
||||||
StatusTextFormatMenu {
|
StatusTextFormatMenu {
|
||||||
id: textFormatMenu
|
id: textFormatMenu
|
||||||
function surroundedBy(chars) {
|
function surroundedBy(chars) {
|
||||||
return messageInputField.selectedText.trim().startsWith(chars) &&
|
const firstIndex = messageInputField.selectedText.trim().indexOf(chars)
|
||||||
messageInputField.selectedText.trim().endsWith(chars)
|
if (firstIndex === -1) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return messageInputField.selectedText.trim().lastIndexOf(chars) > firstIndex
|
||||||
}
|
}
|
||||||
Action {
|
StatusChatInputTextFormationAction {
|
||||||
|
wrapper: "**"
|
||||||
icon.name: "format-text-bold"
|
icon.name: "format-text-bold"
|
||||||
icon.width: 12
|
|
||||||
icon.height: 16
|
|
||||||
onTriggered: wrapSelection("**")
|
|
||||||
//% "Bold"
|
//% "Bold"
|
||||||
text: qsTrId("bold")
|
text: qsTrId("bold")
|
||||||
checked: textFormatMenu.surroundedBy("**")
|
|
||||||
}
|
}
|
||||||
Action {
|
StatusChatInputTextFormationAction {
|
||||||
|
wrapper: "*"
|
||||||
icon.name: "format-text-italic"
|
icon.name: "format-text-italic"
|
||||||
icon.width: 12
|
|
||||||
icon.height: 16
|
|
||||||
onTriggered: wrapSelection("*")
|
|
||||||
//% "Italic"
|
//% "Italic"
|
||||||
text: qsTrId("italic")
|
text: qsTrId("italic")
|
||||||
checked: textFormatMenu.surroundedBy("*") && !textFormatMenu.surroundedBy("**")
|
checked: textFormatMenu.surroundedBy("*") && !textFormatMenu.surroundedBy("**")
|
||||||
}
|
}
|
||||||
Action {
|
StatusChatInputTextFormationAction {
|
||||||
|
wrapper: "~~"
|
||||||
icon.name: "format-text-strike-through"
|
icon.name: "format-text-strike-through"
|
||||||
icon.width: 20
|
|
||||||
icon.height: 18
|
icon.height: 18
|
||||||
onTriggered: wrapSelection("~~")
|
|
||||||
//% "Strikethrough"
|
//% "Strikethrough"
|
||||||
text: qsTrId("strikethrough")
|
text: qsTrId("strikethrough")
|
||||||
checked: textFormatMenu.surroundedBy("~~")
|
|
||||||
}
|
}
|
||||||
Action {
|
StatusChatInputTextFormationAction {
|
||||||
|
wrapper: "`"
|
||||||
icon.name: "format-text-code"
|
icon.name: "format-text-code"
|
||||||
icon.width: 20
|
|
||||||
icon.height: 18
|
icon.height: 18
|
||||||
onTriggered: wrapSelection("`")
|
|
||||||
//% "Code"
|
//% "Code"
|
||||||
text: qsTrId("code")
|
text: qsTrId("code")
|
||||||
checked: textFormatMenu.surroundedBy("`")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import QtQuick 2.13
|
||||||
|
import QtQuick.Controls 2.13
|
||||||
|
|
||||||
|
Action {
|
||||||
|
property string wrapper
|
||||||
|
icon.width: 12
|
||||||
|
icon.height: 16
|
||||||
|
onTriggered: textFormatMenu.surroundedBy(wrapper) ? unwrapSelection(wrapper) : wrapSelection(wrapper)
|
||||||
|
checked: textFormatMenu.surroundedBy(wrapper)
|
||||||
|
}
|
Loading…
Reference in New Issue