diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-11-03 23:08:01 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-11-04 00:33:43 +0100 |
| commit | 35af0042e866eeed8eb2e05f8bbf2dd7b6d097f4 (patch) | |
| tree | 85e50dd13314ffab2457c9baa799d29b3a2fb7a9 | |
| parent | 041a3de1e2d2399f338ec9a5ea4d07736adb9ad3 (diff) | |
menuconfig: Move cursor to choice selection when entering choices
Previously, the first entry was selected, like for menus.
Also tweak _center_vertically() so that the menu is never scrolled down
when all entries fit on the screen.
| -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 |
