mobile/edit: fix broken screen repositioning

In commit 622e5aab69 ("mobile/cleanup: remove more noisy debug output")
I had good intentions, but missed the fact that in order to access the
'verbose' variable from QML I needed to use manager.verboseEnabled. The
resulting syntax error went unnoticed and broke the screen repositioning
when the keyboard opens on mobile devices.

Worse, I called a non existing method to do the logging of debug
information.

And to top it all off, when I fixed the positioning algorithm in commit
765c4f9704 ("mobile/UI: fix the logic to keep input visible"), I forgot
to fix the near identical logic for the TextArea for the notes.

Fail on so many levels.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2021-01-16 08:59:22 -08:00
parent f29534e07f
commit e1c269f54c
2 changed files with 18 additions and 13 deletions

View file

@ -788,21 +788,26 @@ 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)
ensureVisible()
}
// ensure that the y coordinate is inside the visible part of the detailsEditFlickable (our flickable)
function ensureVisible(yDest) {
if (yDest > visibleBottom)
detailsEditFlickable.contentY += yDest - visibleBottom
if (yDest < visibleTop)
detailsEditFlickable.contentY -= visibleTop - yDest
function ensureVisible() {
// make sure there's enough space for the TextArea above the keyboard and action button
// and that it's not too far up, either
var flickable = detailsEditFlickable
var positionInFlickable = txtNotes.mapToItem(flickable.contentItem, 0, 0)
var taY = positionInFlickable.y + cursorRectangle.y
if (manager.verboseEnabled)
manager.appendTextToLog("position check: lower edge of view is " +
(0 + flickable.contentY + flickable.height) +
" and text area is at " + taY)
if (taY > flickable.contentY + flickable.height - 4 * Kirigami.Units.gridUnit)
flickable.contentY = Math.max(0, 4 * Kirigami.Units.gridUnit + taY - flickable.height)
while (taY < flickable.contentY)
flickable.contentY -= 2 * Kirigami.Units.gridUnit
}
// give the OS enough time to actually resize the flickable
Timer {
id: waitForKeyboard
@ -816,7 +821,7 @@ Item {
return
}
// make sure at least half the Notes field is visible
txtNotes.ensureVisible(txtNotes.y + txtNotes.cursorRectangle.y)
txtNotes.ensureVisible()
}
}
}

View file

@ -65,8 +65,8 @@ Controls.TextField {
// make sure there's enough space for the input field above the keyboard and action button (and that it's not too far up, either)
var positionInFlickable = stf.mapToItem(flickable.contentItem, 0, 0)
var stfY = positionInFlickable.y
if (verbose)
manager.appendTextToLogFile("position check: lower edge of view is " + (0 + flickable.contentY + flickable.height) + " and text field is at " + stfY)
if (manager.verboseEnabebled)
manager.appendTextToLog("position check: lower edge of view is " + (0 + flickable.contentY + flickable.height) + " and text field is at " + stfY)
if (stfY + stf.height > flickable.contentY + flickable.height - 3 * Kirigami.Units.gridUnit || stfY < flickable.contentY)
flickable.contentY = Math.max(0, 3 * Kirigami.Units.gridUnit + stfY + stf.height - flickable.height)
}