diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2020-02-07 12:08:20 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-02-07 14:01:23 -0800 |
commit | 102f3bf295cdd2debd3ce462ec4fbe84463406c7 (patch) | |
tree | ea0f469b025eae3f021ef14ffc1b40022e95a3d5 | |
parent | 074dcfb656c579c068e4e298f086535c027ff305 (diff) | |
download | subsurface-102f3bf295cdd2debd3ce462ec4fbe84463406c7.tar.gz |
mobile/notes-edit: ensure cursor stays visible editing dive notes
This seems to work much more reliably as it specifically compares the cursor
position to the visible bottom and top of the screen.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | mobile-widgets/qml/DiveDetailsEdit.qml | 22 |
2 files changed, 17 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c7e3dd1c9..1880c2515 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +Mobile: automatically scroll the dive edit screen so that the notes edit cursor stays visible Desktop: ignore dive sites without location in proximity search Mobile: add personalized option for units Mobile: add Dive Summary page diff --git a/mobile-widgets/qml/DiveDetailsEdit.qml b/mobile-widgets/qml/DiveDetailsEdit.qml index 67aad6386..9d10772e4 100644 --- a/mobile-widgets/qml/DiveDetailsEdit.qml +++ b/mobile-widgets/qml/DiveDetailsEdit.qml @@ -716,11 +716,22 @@ Item { selectByMouse: true wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere property bool firstTime: true + property int visibleTop: detailsEditFlickable.contentY + property int visibleBottom: visibleTop + detailsEditFlickable.height - 4 * Kirigami.Units.gridUnit onPressed: waitForKeyboard.start() + onCursorRectangleChanged: { + ensureVisible(y + cursorRectangle.y) + } + onContentHeightChanged: { + console.log("content height changed") + } - // we repeat the Timer / Function from the SsrfTextField here (no point really in creating a matching customized TextArea) + // ensure that the y coordinate is inside the visible part of the detailsEditFlickable (our flickable) function ensureVisible(yDest) { - detailsEditFlickable.contentY = yDest + if (yDest > visibleBottom) + detailsEditFlickable.contentY += yDest - visibleBottom + if (yDest < visibleTop) + detailsEditFlickable.contentY -= visibleTop - yDest } // give the OS enough time to actually resize the flickable @@ -729,15 +740,14 @@ Item { interval: 300 // 300ms seems like FOREVER onTriggered: { if (!Qt.inputMethod.visible) { - if (firstTime) { - firstTime = false + if (txtNotes.firstTime) { + txtNotes.firstTime = false restart() } return } // make sure at least half the Notes field is visible - if (txtNotes.y + txtNotes.height / 2 > detailsEditFlickable.contentY + detailsEditFlickable.height - 3 * Kirigami.Units.gridUnit || txtNotes.y < detailsEditFlickable.contentY) - txtNotes.ensureVisible(Math.max(0, 3 * Kirigami.Units.gridUnit + txtNotes.y + txtNotes.height / 2 - detailsEditFlickable.height)) + txtNotes.ensureVisible(txtNotes.y + txtNotes.cursorRectangle.y) } } } |