diff --git a/tests/ui/modules/Linphone/Calls/Calls.qml b/tests/ui/modules/Linphone/Calls/Calls.qml index d318b8658..4106d83a0 100644 --- a/tests/ui/modules/Linphone/Calls/Calls.qml +++ b/tests/ui/modules/Linphone/Calls/Calls.qml @@ -11,7 +11,7 @@ ListView { // --------------------------------------------------------------------------- - readonly property var selectedCall: currentIndex >= 0 ? model.data(model.index(currentIndex, 0)) : null + readonly property var selectedCall: smartConnect.selectedCall property var _mapStatusToParams @@ -156,25 +156,54 @@ ListView { } } + // --------------------------------------------------------------------------- + // Update the current selected call and the current index. // --------------------------------------------------------------------------- SmartConnect { + id: smartConnect + + property var selectedCall + Component.onCompleted: { this.connect(model, 'rowsAboutToBeRemoved', function (_, first, last) { var index = calls.currentIndex + if (index >= first && index <= last) { // Remove current call. if (model.rowCount() - (last - first + 1) <= 0) { - calls.currentIndex = -1 + selectedCall = null } else { - calls.currentIndex = 0 + if (first === 0) { + selectedCall = model.data(model.index(last + 1, 0)) + } else { + selectedCall = model.data(model.index(0, 0)) + } } - } else if (last < index) { // Remove before current call. + } + }) + + this.connect(model, 'rowsRemoved', function (_, first, last) { + var index = calls.currentIndex + + // The current call has been removed. + if (index >= first && index <= last) { + if (model.rowCount() === 0) { + calls.currentIndex = -1 // No calls. + } else { + calls.currentIndex = 0 // The first call becomes the selected call. + } + } + + // Update the current index of the selected call if it was after the removed calls. + else if (last < index) { calls.currentIndex = index - (last - first + 1) } }) + // The last inserted element become the selected call. this.connect(model, 'rowsInserted', function (_, first, last) { calls.currentIndex = first + selectedCall = model.data(model.index(first, 0)) }) } } diff --git a/tests/ui/scripts/Utils/utils.js b/tests/ui/scripts/Utils/utils.js index 38f69fdc2..be10cbdb6 100644 --- a/tests/ui/scripts/Utils/utils.js +++ b/tests/ui/scripts/Utils/utils.js @@ -39,7 +39,7 @@ function encodeTextToQmlRichFormat (text, options) { } text = text - .replace(/&/g, '&') + .replace(/&/g, '&') // TODO: deal correctly with urls and `&m` .replace(//g, '\u2063>') .replace(/\r\n|\n/g, '
')