Verified Commit 0852fff3 authored by ivan tkachenko's avatar ivan tkachenko
Browse files

applets/notes: Save/restore scrolling and cursor position

Makes scrolling position persistent, and takes some care to
1. delay restoring until the text is laid out,
2. throttle storage a little, so that we don't use too much I/O.

Component.onDestruction correctly saves the position on exit. It can be
tested via D-Bus by calling method quit() at:

- Session bus: org.kde.plasmashell
- Object path: /MainApplication
- Interface: org.qtproject.Qt.QCoreApplication

Cursor position restoration can be tested by assigning a global shortcut
to an applet, so that it can become focused without actually clicking
on it with a mouse and messing with cursor position. Text selection is
not handled, and I don't think we should even bother with it.

BUG: 449150
parent b6c318c0
Pipeline #197181 passed with stage
in 1 minute and 55 seconds
......@@ -17,5 +17,18 @@
<entry name="noteId" type="String">
<default></default>
</entry>
<entry name="scrollX" type="Double">
<default>0</default>
</entry>
<entry name="scrollY" type="Double">
<default>0</default>
</entry>
<entry name="cursorPosition" type="Int">
<default>0</default>
</entry>
</group>
</kcfg>
......@@ -320,6 +320,51 @@ PlasmaCore.SvgItem {
}
}
}
// Save scrolling position when it changes, but throttle to avoid
// killing a storage disk.
Connections {
target: scrollview.contentItem
function onContentXChanged() {
throttedScrollSaver.restart();
}
function onContentYChanged() {
throttedScrollSaver.restart();
}
}
Connections {
target: mainTextArea
function onCursorPositionChanged() {
throttedScrollSaver.restart();
}
}
Timer {
id: throttedScrollSaver
interval: PlasmaCore.Units.humanMoment
repeat: false
running: false
onTriggered: scrollview.saveScroll()
}
function saveScroll() {
const flickable = scrollview.contentItem;
Plasmoid.configuration.scrollX = flickable.contentX;
Plasmoid.configuration.scrollY = flickable.contentY;
Plasmoid.configuration.cursorPosition = mainTextArea.cursorPosition;
}
function restoreScroll() {
const flickable = scrollview.contentItem;
flickable.contentX = Plasmoid.configuration.scrollX;
flickable.contentY = Plasmoid.configuration.scrollY;
mainTextArea.cursorPosition = Plasmoid.configuration.cursorPosition;
}
// Give it some time to lay out the text, because at this
// point in time content size is not reliable yet.
Component.onCompleted: Qt.callLater(restoreScroll)
Component.onDestruction: saveScroll()
}
DragDrop.DropArea {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment