appDisplay: Don't have goToPage clamp to negative page index

The nPages property can be 0, which is the case in a stripped down CI
image without a single app to be listed, which means we can't clamp to
`nPages - 1`, since that'll give us a negative index and the following
error:

(gnome-shell:266): Gjs-CRITICAL **: 16:48:56.633: JS ERROR: Error: Page -2 does not exist at IconGrid
getItemsAtPage@resource:///org/gnome/shell/ui/iconGrid.js:1383:19
_translatePreviousPageIcons@resource:///org/gnome/shell/ui/appDisplay.js:323:34
_syncPageIndicators@resource:///org/gnome/shell/ui/appDisplay.js:396:14
goToPage@resource:///org/gnome/shell/ui/appDisplay.js:445:14
goToPage@resource:///org/gnome/shell/ui/appDisplay.js:1236:29
goToPage@resource:///org/gnome/shell/ui/appDisplay.js:1582:15
_init/<@resource:///org/gnome/shell/ui/appDisplay.js:499:18
_init/pagesChangedId<@resource:///org/gnome/shell/ui/iconGrid.js:1137:24
_removePage@resource:///org/gnome/shell/ui/iconGrid.js:454:14
_removeItemData@resource:///org/gnome/shell/ui/iconGrid.js:495:18
moveItem@resource:///org/gnome/shell/ui/iconGrid.js:854:14
moveItem@resource:///org/gnome/shell/ui/iconGrid.js:1277:29
_moveItem@resource:///org/gnome/shell/ui/appDisplay.js:1194:20
_redisplay/<@resource:///org/gnome/shell/ui/appDisplay.js:1085:22
_redisplay@resource:///org/gnome/shell/ui/appDisplay.js:1080:17
_redisplay@resource:///org/gnome/shell/ui/appDisplay.js:1370:15
_init/<@resource:///org/gnome/shell/ui/appDisplay.js:633:24
_initializeManager@resource:///org/gnome/shell/misc/parentalControlsManager.js:95:14
async*_init@resource:///org/gnome/shell/misc/parentalControlsManager.js:63:14
ParentalControlsManager@resource:///org/gnome/shell/misc/parentalControlsManager.js:55:4
getDefault@resource:///org/gnome/shell/misc/parentalControlsManager.js:42:22
start@resource:///org/gnome/shell/ui/main.js:184:29
@resource:///org/gnome/shell/ui/init.js:6:17

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1349>
This commit is contained in:
Jonas Ådahl 2022-08-18 21:34:41 +02:00
parent fa47a7576d
commit 367d40d31b

View File

@ -1228,7 +1228,7 @@ var BaseAppView = GObject.registerClass({
} }
goToPage(pageNumber, animate = true) { goToPage(pageNumber, animate = true) {
pageNumber = Math.clamp(pageNumber, 0, this._grid.nPages - 1); pageNumber = Math.clamp(pageNumber, 0, Math.max(this._grid.nPages - 1, 0));
if (this._grid.currentPage === pageNumber) if (this._grid.currentPage === pageNumber)
return; return;
@ -1573,7 +1573,7 @@ class AppDisplay extends BaseAppView {
} }
goToPage(pageNumber, animate = true) { goToPage(pageNumber, animate = true) {
pageNumber = Math.clamp(pageNumber, 0, this._grid.nPages - 1); pageNumber = Math.clamp(pageNumber, 0, Math.max(this._grid.nPages - 1, 0));
if (this._grid.currentPage === pageNumber && if (this._grid.currentPage === pageNumber &&
this._displayingDialog && this._displayingDialog &&