@@ -279,11 +279,7 @@ class App(Generic[ReturnType], DOMNode):
279279 also the `sub_title` attribute.
280280 """
281281
282- BINDINGS = [
283- Binding ("ctrl+c" , "quit" , "Quit" , show = False , priority = True ),
284- Binding ("tab" , "focus_next" , "Focus Next" , show = False ),
285- Binding ("shift+tab" , "focus_previous" , "Focus Previous" , show = False ),
286- ]
282+ BINDINGS = [Binding ("ctrl+c" , "quit" , "Quit" , show = False , priority = True )]
287283
288284 title : Reactive [str ] = Reactive ("" , compute = False )
289285 sub_title : Reactive [str ] = Reactive ("" , compute = False )
@@ -1961,38 +1957,34 @@ def bell(self) -> None:
19611957 @property
19621958 def _binding_chain (self ) -> list [tuple [DOMNode , Bindings ]]:
19631959 """Get a chain of nodes and bindings to consider.
1960+
19641961 If no widget is focused, returns the bindings from both the screen and the app level bindings.
19651962 Otherwise, combines all the bindings from the currently focused node up the DOM to the root App.
1966-
1967- Returns:
1968- List of DOM nodes and their bindings.
19691963 """
19701964 focused = self .focused
19711965 namespace_bindings : list [tuple [DOMNode , Bindings ]]
1972- screen = self .screen
19731966
19741967 if focused is None :
1975- if screen .is_modal :
1976- namespace_bindings = [
1977- (self .screen , self .screen ._bindings ),
1978- ]
1979- else :
1980- namespace_bindings = [
1981- (self .screen , self .screen ._bindings ),
1982- (self , self ._bindings ),
1983- ]
1968+ namespace_bindings = [
1969+ (self .screen , self .screen ._bindings ),
1970+ (self , self ._bindings ),
1971+ ]
19841972 else :
1985- if screen .is_modal :
1986- namespace_bindings = [
1987- (node , node ._bindings ) for node in focused .ancestors
1988- ]
1989- else :
1990- namespace_bindings = [
1991- (node , node ._bindings ) for node in focused .ancestors_with_self
1992- ]
1973+ namespace_bindings = [
1974+ (node , node ._bindings ) for node in focused .ancestors_with_self
1975+ ]
19931976
19941977 return namespace_bindings
19951978
1979+ @property
1980+ def _modal_binding_chain (self ) -> list [tuple [DOMNode , Bindings ]]:
1981+ """The binding chain, ignoring everything before the last modal."""
1982+ binding_chain = self ._binding_chain
1983+ for index , (node , _bindings ) in enumerate (binding_chain , 1 ):
1984+ if node .is_modal :
1985+ return binding_chain [:index ]
1986+ return binding_chain
1987+
19961988 async def check_bindings (self , key : str , priority : bool = False ) -> bool :
19971989 """Handle a key press.
19981990
@@ -2004,7 +1996,7 @@ async def check_bindings(self, key: str, priority: bool = False) -> bool:
20041996 True if the key was handled by a binding, otherwise False
20051997 """
20061998 for namespace , bindings in (
2007- reversed (self ._binding_chain ) if priority else self ._binding_chain
1999+ reversed (self ._binding_chain ) if priority else self ._modal_binding_chain
20082000 ):
20092001 binding = bindings .keys .get (key )
20102002 if binding is not None and binding .priority == priority :
0 commit comments