Revert "Revert "Implement selection across multiple MessageDelegates""

This reverts commit 3697146f44.
This commit is contained in:
Tobias Fella
2022-11-27 02:18:59 +01:00
parent 3a4f71de7f
commit be429dc25f
3 changed files with 98 additions and 2 deletions

View File

@@ -43,13 +43,18 @@ TextEdit {
*/
property bool spoilerRevealed: !hasSpoiler.test(textMessage)
property bool isDelegate: false
ListView.onReused: Qt.binding(() => !hasSpoiler.test(textMessage))
persistentSelection: true
// Work around QTBUG 93281
Component.onCompleted: if (text.includes("<img")) {
Controller.forceRefreshTextDocument(root.textDocument, root)
Component.onCompleted: {
updateSelection()
if (text.includes("<img")) {
Controller.forceRefreshTextDocument(root.textDocument, root)
}
}
text: "<style>
@@ -116,4 +121,26 @@ a{
enabled: !parent.hoveredLink && !spoilerRevealed
onTapped: spoilerRevealed = true
}
Connections {
target: selectionArea
enabled: root.isDelegate
function onSelectionChanged() {
updateSelection();
}
}
function updateSelection() {
if (index < selectionArea.lowerIndex || index > selectionArea.upperIndex) {
root.select(0, 0);
} else if (index > selectionArea.lowerIndex && index < selectionArea.upperIndex) {
root.selectAll();
} else if (index === selectionArea.selectionStartIndex && index === selectionArea.selectionEndIndex) {
root.select(selectionArea.upperPos, selectionArea.lowerPos);
} else if (index === selectionArea.upperIndex) {
root.select(selectionArea.upperPos, root.length);
} else if (index === selectionArea.lowerIndex) {
root.select(0, selectionArea.lowerPos);
}
}
}