diff options
| -rwxr-xr-x | menuconfig.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/menuconfig.py b/menuconfig.py index ad3c175..029b145 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -1000,7 +1000,7 @@ def _prefer_toggle(item): (isinstance(item, Choice) and len(item.assignable) > 1) def _enter_menu(menu): - # Makes 'menu' the currently displayed menu + # Makes 'menu' the currently displayed menu. "Menu" here includes choices. global _cur_menu global _shown @@ -1019,6 +1019,25 @@ def _enter_menu(menu): _shown = shown_sub _sel_node_i = _menu_scroll = 0 + if isinstance(menu.item, Choice): + _select_selected_choice_sym() + +def _select_selected_choice_sym(): + # Puts the cursor on the currently selected (y-valued) choice symbol, if + # any. Do nothing if if the choice has no selection (is not visible/in y + # mode). + + global _sel_node_i + + choice = _cur_menu.item + if choice.selection: + # Search through all menu nodes to handle choice symbols being defined + # in multiple locations + for node in choice.selection.nodes: + if node in _shown: + _sel_node_i = _shown.index(node) + _center_vertically() + def _jump_to(node): # Jumps directly to the menu node 'node' @@ -1062,6 +1081,11 @@ def _jump_to(node): _center_vertically() + # If we're jumping to a non-empty choice, jump to the selected symbol, if + # any + if jump_into and isinstance(_cur_menu.item, Choice): + _select_selected_choice_sym() + def _leave_menu(): # Jumps to the parent menu of the current menu. Does nothing if we're in # the top menu. @@ -1196,7 +1220,8 @@ def _center_vertically(): global _menu_scroll - _menu_scroll = max(_sel_node_i - _menu_win_height()//2, 0) + _menu_scroll = min(max(_sel_node_i - _menu_win_height()//2, 0), + _max_scroll(_shown, _menu_win)) def _draw_main(): # Draws the "main" display, with the list of symbols, the header, and the |
