components: Fix MarqueeLabel behaviour with new line characters

This commit is contained in:
Devin Lin 2022-10-27 20:09:46 -04:00
parent 06de6e416e
commit f4b15f922f

View file

@ -14,16 +14,17 @@ PlasmaComponents.Label {
id: root id: root
required property string inputText required property string inputText
readonly property string filteredText: inputText.replace(/\n/g, ' ') // remove new line characters
property int interval: PlasmaCore.Units.longDuration property int interval: PlasmaCore.Units.longDuration
readonly property int charactersOverflow: Math.ceil((txtMeter.advanceWidth - root.width) / (txtMeter.advanceWidth / inputText.length)) readonly property int charactersOverflow: Math.ceil((txtMeter.advanceWidth - root.width) / (txtMeter.advanceWidth / filteredText.length))
property int step: 0 property int step: 0
TextMetrics { TextMetrics {
id: txtMeter id: txtMeter
font: root.font font: root.font
text: inputText text: filteredText
} }
Timer { Timer {
@ -42,7 +43,7 @@ PlasmaComponents.Label {
paused = false; paused = false;
} }
} else { } else {
step = (step + 1) % inputText.length; step = (step + 1) % filteredText.length;
if (step === charactersOverflow) { if (step === charactersOverflow) {
interval = PlasmaCore.Units.veryLongDuration * 3; interval = PlasmaCore.Units.veryLongDuration * 3;
paused = true; paused = true;
@ -57,5 +58,5 @@ PlasmaComponents.Label {
} }
} }
text: inputText.substring(step, step + inputText.length - charactersOverflow) text: filteredText.substring(step, step + filteredText.length - charactersOverflow)
} }