@@ -27,6 +27,15 @@ class KeyGroup(HorizontalGroup):
2727 }
2828 """
2929
30+ def __init__ (
31+ self ,
32+ id : str | None = None ,
33+ classes : str | None = None ,
34+ order_group : str = "default" ,
35+ ):
36+ self .order_group = order_group
37+ super ().__init__ (id = id , classes = classes )
38+
3039
3140@rich .repr .auto
3241class FooterKey (Widget ):
@@ -87,11 +96,13 @@ def __init__(
8796 disabled : bool = False ,
8897 tooltip : str = "" ,
8998 classes = "" ,
99+ order_group : str = "default" ,
90100 ) -> None :
91101 self .key = key
92102 self .key_display = key_display
93103 self .description = description
94104 self .action = action
105+ self .order_group = order_group
95106 self ._disabled = disabled
96107 if disabled :
97108 classes += " -disabled"
@@ -284,7 +295,12 @@ def compose(self) -> ComposeResult:
284295 ):
285296 multi_bindings = list (multi_bindings_iterable )
286297 if group is not None and len (multi_bindings ) > 1 :
287- with KeyGroup (classes = "-compact" if group .compact else "" ):
298+ with KeyGroup (
299+ classes = "-compact" if group .compact else "" ,
300+ order_group = (
301+ "default" if group .order_group is None else group .order_group
302+ ),
303+ ):
288304 for multi_bindings in multi_bindings :
289305 binding , enabled , tooltip = multi_bindings [0 ]
290306 yield FooterKey (
@@ -296,7 +312,7 @@ def compose(self) -> ComposeResult:
296312 tooltip = tooltip or binding .description ,
297313 classes = "-grouped" ,
298314 ).data_bind (compact = Footer .compact )
299- yield FooterLabel (group .description )
315+ yield FooterLabel (group .description )
300316 else :
301317 for multi_bindings in multi_bindings :
302318 binding , enabled , tooltip = multi_bindings [0 ]
@@ -307,6 +323,11 @@ def compose(self) -> ComposeResult:
307323 binding .action ,
308324 disabled = not enabled ,
309325 tooltip = tooltip ,
326+ order_group = (
327+ "default"
328+ if binding .order_group is None
329+ else binding .order_group
330+ ),
310331 ).data_bind (compact = Footer .compact )
311332 if self .show_command_palette and self .app .ENABLE_COMMAND_PALETTE :
312333 try :
@@ -324,8 +345,21 @@ def compose(self) -> ComposeResult:
324345 classes = "-command-palette" ,
325346 disabled = not enabled ,
326347 tooltip = binding .tooltip or binding .description ,
348+ order_group = (
349+ "default"
350+ if binding .order_group is None
351+ else binding .order_group
352+ ),
327353 )
328354
355+ sort_order = {
356+ group : index
357+ for index , group in enumerate (self .screen .get_binding_sort_order ())
358+ }
359+ self .sort_children (
360+ key = lambda widget : sort_order .get (sort_order .get (widget .order_group , 0 ))
361+ )
362+
329363 def bindings_changed (self , screen : Screen ) -> None :
330364 self ._bindings_ready = True
331365 if not screen .app .app_focus :
0 commit comments