mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-28 07:15:21 +00:00
feat: show formation hightlighted even when not selecting the stars
This commit is contained in:
parent
f2f2707d68
commit
0c34335d1c
@ -220,12 +220,17 @@ Rectangle {
|
|||||||
messageInputField.deselect()
|
messageInputField.deselect()
|
||||||
formatInputMessage()
|
formatInputMessage()
|
||||||
}
|
}
|
||||||
function unwrapSelection(unwrapWith) {
|
function unwrapSelection(unwrapWith, selectedTextWithFormationChars) {
|
||||||
if (messageInputField.selectionStart - messageInputField.selectionEnd === 0) return
|
if (messageInputField.selectionStart - messageInputField.selectionEnd === 0) return
|
||||||
|
|
||||||
const text = messageInputField.getText(messageInputField.selectionStart, messageInputField.selectionEnd)
|
selectedTextWithFormationChars = selectedTextWithFormationChars.trim()
|
||||||
const changedString = text.replace(unwrapWith, '').replace(unwrapWith, '')
|
// Check if the selectedTextWithFormationChars has formation chars and if so, calculate how many so we can adapt the start and end pos
|
||||||
messageInputField.remove(messageInputField.selectionStart, messageInputField.selectionEnd)
|
const selectTextDiff = (selectedTextWithFormationChars.length - messageInputField.selectedText.length) / 2
|
||||||
|
|
||||||
|
const changedString = selectedTextWithFormationChars.replace(unwrapWith, '').replace(unwrapWith, '')
|
||||||
|
|
||||||
|
messageInputField.remove(messageInputField.selectionStart - selectTextDiff, messageInputField.selectionEnd + selectTextDiff)
|
||||||
|
|
||||||
insertInTextInput(messageInputField.selectionStart, changedString)
|
insertInTextInput(messageInputField.selectionStart, changedString)
|
||||||
|
|
||||||
messageInputField.deselect()
|
messageInputField.deselect()
|
||||||
@ -852,14 +857,38 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StatusTextFormatMenu {
|
StatusTextFormatMenu {
|
||||||
|
readonly property var formationChars: (["*", "`", "~"])
|
||||||
|
property string selectedTextWithFormationChars: {
|
||||||
|
let i = 1
|
||||||
|
let text = ""
|
||||||
|
while(true) {
|
||||||
|
if (messageInputField.selectionStart - i < 0 && messageInputField.selectionEnd + i > messageInputField.length) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
text = messageInputField.getText(messageInputField.selectionStart - i, messageInputField.selectionEnd + i)
|
||||||
|
|
||||||
|
if (!formationChars.includes(text.charAt(0)) ||
|
||||||
|
!formationChars.includes(text.charAt(text.length - 1))) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
id: textFormatMenu
|
id: textFormatMenu
|
||||||
function surroundedBy(chars) {
|
function surroundedBy(chars) {
|
||||||
const firstIndex = messageInputField.selectedText.trim().indexOf(chars)
|
if (selectedTextWithFormationChars === "") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstIndex = selectedTextWithFormationChars.indexOf(chars)
|
||||||
if (firstIndex === -1) {
|
if (firstIndex === -1) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return messageInputField.selectedText.trim().lastIndexOf(chars) > firstIndex
|
return selectedTextWithFormationChars.lastIndexOf(chars) > firstIndex
|
||||||
}
|
}
|
||||||
StatusChatInputTextFormationAction {
|
StatusChatInputTextFormationAction {
|
||||||
wrapper: "**"
|
wrapper: "**"
|
||||||
|
@ -5,6 +5,8 @@ Action {
|
|||||||
property string wrapper
|
property string wrapper
|
||||||
icon.width: 12
|
icon.width: 12
|
||||||
icon.height: 16
|
icon.height: 16
|
||||||
onTriggered: textFormatMenu.surroundedBy(wrapper) ? unwrapSelection(wrapper) : wrapSelection(wrapper)
|
onTriggered: textFormatMenu.surroundedBy(wrapper) ?
|
||||||
|
unwrapSelection(wrapper, textFormatMenu.selectedTextWithFormationChars) :
|
||||||
|
wrapSelection(wrapper)
|
||||||
checked: textFormatMenu.surroundedBy(wrapper)
|
checked: textFormatMenu.surroundedBy(wrapper)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user