Browse Source

[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 12 years ago
parent
commit
c08025137b
1 changed files with 12 additions and 10 deletions
  1. 12
    10
      src/hci/tui/menu_ui.c

+ 12
- 10
src/hci/tui/menu_ui.c View File

247
 				i = 0;
247
 				i = 0;
248
 				list_for_each_entry ( item, &ui->menu->items,
248
 				list_for_each_entry ( item, &ui->menu->items,
249
 						      list ) {
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
 						chosen = 1;
257
 						chosen = 1;
254
-						break;
258
+					} else {
259
+						move = +1;
255
 					}
260
 					}
256
-					i++;
257
 				}
261
 				}
258
 				break;
262
 				break;
259
 			}
263
 			}
284
 			draw_menu_item ( ui, ui->selected );
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
 		/* Record selection */
291
 		/* Record selection */
292
+		item = menu_item ( ui->menu, ui->selected );
293
+		assert ( item != NULL );
294
+		assert ( item->label != NULL );
293
 		*selected = item;
295
 		*selected = item;
294
 
296
 
295
 	} while ( ( rc == 0 ) && ! chosen );
297
 	} while ( ( rc == 0 ) && ! chosen );

Loading…
Cancel
Save