From 1fb5c0433d22a2af2b7f5b7e9045fa4703b21281 Mon Sep 17 00:00:00 2001 From: Gabriele Monaco Date: Thu, 15 Dec 2022 21:05:52 +0300 Subject: [PATCH] clkinfo: repeating selection if menu is empty --- modules/clock_info.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/clock_info.js b/modules/clock_info.js index 6f37e5d3d..643a9f6f7 100644 --- a/modules/clock_info.js +++ b/modules/clock_info.js @@ -239,10 +239,15 @@ exports.addInteractive = function(menu, options) { } else if (lr) { if (menu.length==1) return; // 1 item - can't move oldMenuItem = menu[options.menuA].items[options.menuB]; - options.menuA += lr; - if (options.menuA<0) options.menuA = menu.length-1; - if (options.menuA>=menu.length) options.menuA = 0; - options.menuB = 0; + do { + options.menuA += lr; + if (options.menuA<0) options.menuA = menu.length-1; + if (options.menuA>=menu.length) options.menuA = 0; + options.menuB = 0; + //get the next one if the menu is empty + //can happen for dynamic ones (alarms, events) + //in the worst case we come back to 0 + } while(menu[options.menuA].items.length==0); } if (oldMenuItem) { menuHideItem(oldMenuItem);