Переглянути джерело

[menu] Prevent separators with shortcut keys from being selected

Nothing currently prevents a menu separator from being assigned a
shortcut key, and then from being selected using that shortcut key.
This produces an inconsistency in the user interface, since separators
cannot be selected by other means of menu navigation (arrow keys, page
up/down, etc).

It would be trivial to prevent separators from being assigned shortcut
keys, but this would eliminate one potentially useful use case: having
a large menu and using shortcut keys to jump to a section within the
menu.

Fix by treating a shortcut key on a separator as equivalent to "select
the separator, then press the down arrow key".  This has the effect of
moving to the first non-separator menu item following the specified
separator, which is probably the most intuitive behaviour.  (The
existing logic for moving the selection already handles the various
nasty corner cases such as a menu ending with one or more separators.)

Reported-by: Ján ONDREJ (SAL) <ondrejj@salstar.sk>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 роки тому
джерело
коміт
c08025137b
1 змінених файлів з 12 додано та 10 видалено
  1. 12
    10
      src/hci/tui/menu_ui.c

+ 12
- 10
src/hci/tui/menu_ui.c Переглянути файл

@@ -247,13 +247,17 @@ static int menu_loop ( struct menu_ui *ui, struct menu_item **selected ) {
247 247
 				i = 0;
248 248
 				list_for_each_entry ( item, &ui->menu->items,
249 249
 						      list ) {
250
-					if ( item->shortcut &&
251
-					     ( item->shortcut == key ) ) {
252
-						ui->selected = i;
250
+					if ( ! ( item->shortcut &&
251
+						 ( item->shortcut == key ) ) ) {
252
+						i++;
253
+						continue;
254
+					}
255
+					ui->selected = i;
256
+					if ( item->label ) {
253 257
 						chosen = 1;
254
-						break;
258
+					} else {
259
+						move = +1;
255 260
 					}
256
-					i++;
257 261
 				}
258 262
 				break;
259 263
 			}
@@ -284,12 +288,10 @@ static int menu_loop ( struct menu_ui *ui, struct menu_item **selected ) {
284 288
 			draw_menu_item ( ui, ui->selected );
285 289
 		}
286 290
 
287
-		/* Refuse to choose unlabelled items (i.e. separators) */
288
-		item = menu_item ( ui->menu, ui->selected );
289
-		if ( ! item->label )
290
-			chosen = 0;
291
-
292 291
 		/* Record selection */
292
+		item = menu_item ( ui->menu, ui->selected );
293
+		assert ( item != NULL );
294
+		assert ( item->label != NULL );
293 295
 		*selected = item;
294 296
 
295 297
 	} while ( ( rc == 0 ) && ! chosen );

Завантаження…
Відмінити
Зберегти