Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/prompt_toolkit/key_binding/defaults.py: 85%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

13 statements  

1""" 

2Default key bindings.:: 

3 

4 key_bindings = load_key_bindings() 

5 app = Application(key_bindings=key_bindings) 

6""" 

7 

8from __future__ import annotations 

9 

10from prompt_toolkit.filters import buffer_has_focus 

11from prompt_toolkit.key_binding.bindings.basic import load_basic_bindings 

12from prompt_toolkit.key_binding.bindings.cpr import load_cpr_bindings 

13from prompt_toolkit.key_binding.bindings.emacs import ( 

14 load_emacs_bindings, 

15 load_emacs_search_bindings, 

16 load_emacs_shift_selection_bindings, 

17) 

18from prompt_toolkit.key_binding.bindings.mouse import load_mouse_bindings 

19from prompt_toolkit.key_binding.bindings.vi import ( 

20 load_vi_bindings, 

21 load_vi_search_bindings, 

22) 

23from prompt_toolkit.key_binding.key_bindings import ( 

24 ConditionalKeyBindings, 

25 KeyBindingsBase, 

26 merge_key_bindings, 

27) 

28 

29__all__ = [ 

30 "load_key_bindings", 

31] 

32 

33 

34def load_key_bindings() -> KeyBindingsBase: 

35 """ 

36 Create a KeyBindings object that contains the default key bindings. 

37 """ 

38 all_bindings = merge_key_bindings( 

39 [ 

40 # Load basic bindings. 

41 load_basic_bindings(), 

42 # Load emacs bindings. 

43 load_emacs_bindings(), 

44 load_emacs_search_bindings(), 

45 load_emacs_shift_selection_bindings(), 

46 # Load Vi bindings. 

47 load_vi_bindings(), 

48 load_vi_search_bindings(), 

49 ] 

50 ) 

51 

52 return merge_key_bindings( 

53 [ 

54 # Make sure that the above key bindings are only active if the 

55 # currently focused control is a `BufferControl`. For other controls, we 

56 # don't want these key bindings to intervene. (This would break "ptterm" 

57 # for instance, which handles 'Keys.Any' in the user control itself.) 

58 ConditionalKeyBindings(all_bindings, buffer_has_focus), 

59 # Active, even when no buffer has been focused. 

60 load_mouse_bindings(), 

61 load_cpr_bindings(), 

62 ] 

63 )