feat(@desktop/chat): add textformat quote option functionality
Adjust text format popup position Fixes #6988 Requires https://github.com/status-im/StatusQ/pull/876
This commit is contained in:
parent
c16b0762ae
commit
a01e0822b7
|
@ -1 +1 @@
|
|||
Subproject commit 803a7637bf42702bb113c51728bf30cec207d51d
|
||||
Subproject commit 80a9cc9b3face23df65e7630afe5339a8acf8072
|
|
@ -321,6 +321,31 @@ Rectangle {
|
|||
}
|
||||
}
|
||||
|
||||
function getLineStartPosition(selectionStart) {
|
||||
const text = getPlainText()
|
||||
const lastNewLinePos = text.lastIndexOf("\n\n", messageInputField.selectionStart)
|
||||
return lastNewLinePos === -1 ? 0 : lastNewLinePos + 2
|
||||
}
|
||||
|
||||
function prefixSelectedLine(prefix) {
|
||||
const selectedLinePosition = getLineStartPosition(messageInputField.selectionStart)
|
||||
insertInTextInput(selectedLinePosition, prefix)
|
||||
}
|
||||
|
||||
function unprefixSelectedLine(prefix) {
|
||||
if( isSelectedLinePrefixedBy(messageInputField.selectionStart, prefix) ) {
|
||||
const selectedLinePosition = getLineStartPosition(messageInputField.selectionStart)
|
||||
messageInputField.remove(selectedLinePosition, selectedLinePosition + prefix.length)
|
||||
}
|
||||
}
|
||||
|
||||
function isSelectedLinePrefixedBy(selectionStart, prefix) {
|
||||
const selectedLinePosition = getLineStartPosition(selectionStart)
|
||||
const text = getPlainText()
|
||||
const selectedLine = text.substring(selectedLinePosition)
|
||||
return selectedLine.startsWith(prefix)
|
||||
}
|
||||
|
||||
function wrapSelection(wrapWith) {
|
||||
if (messageInputField.selectionStart - messageInputField.selectionEnd === 0) return
|
||||
|
||||
|
@ -1069,7 +1094,7 @@ Rectangle {
|
|||
(messageInputField.cursorRectangle.x + event.x) / 2
|
||||
x -= textFormatMenu.width / 2
|
||||
|
||||
textFormatMenu.popup(x, -messageInputField.height-2)
|
||||
textFormatMenu.popup(x, messageInputField.y - textFormatMenu.height - 5)
|
||||
messageInputField.forceActiveFocus();
|
||||
}
|
||||
lastClick = now
|
||||
|
@ -1139,6 +1164,16 @@ Rectangle {
|
|||
unwrapSelection(wrapper, RootStore.getSelectedTextWithFormationChars(messageInputField)) :
|
||||
wrapSelection(wrapper)
|
||||
}
|
||||
StatusChatInputTextFormationAction {
|
||||
wrapper: "> "
|
||||
icon.name: "quote"
|
||||
text: qsTr("Quote")
|
||||
checked: messageInputField.selectedText && isSelectedLinePrefixedBy(messageInputField.selectionStart, wrapper)
|
||||
|
||||
onActionTriggered: checked
|
||||
? unprefixSelectedLine(wrapper)
|
||||
: prefixSelectedLine(wrapper)
|
||||
}
|
||||
onClosed: {
|
||||
messageInputField.deselect();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import utils 1.0
|
|||
|
||||
Menu {
|
||||
id: root
|
||||
width: 132
|
||||
width: 165
|
||||
height: 36
|
||||
|
||||
background: Item {
|
||||
|
|
Loading…
Reference in New Issue