Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/prompt_toolkit/key_binding/bindings/open_in_editor.py: 53%

15 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-20 06:09 +0000

1""" 

2Open in editor key bindings. 

3""" 

4from __future__ import annotations 

5 

6from prompt_toolkit.filters import emacs_mode, has_selection, vi_navigation_mode 

7 

8from ..key_bindings import KeyBindings, KeyBindingsBase, merge_key_bindings 

9from .named_commands import get_by_name 

10 

11__all__ = [ 

12 "load_open_in_editor_bindings", 

13 "load_emacs_open_in_editor_bindings", 

14 "load_vi_open_in_editor_bindings", 

15] 

16 

17 

18def load_open_in_editor_bindings() -> KeyBindingsBase: 

19 """ 

20 Load both the Vi and emacs key bindings for handling edit-and-execute-command. 

21 """ 

22 return merge_key_bindings( 

23 [ 

24 load_emacs_open_in_editor_bindings(), 

25 load_vi_open_in_editor_bindings(), 

26 ] 

27 ) 

28 

29 

30def load_emacs_open_in_editor_bindings() -> KeyBindings: 

31 """ 

32 Pressing C-X C-E will open the buffer in an external editor. 

33 """ 

34 key_bindings = KeyBindings() 

35 

36 key_bindings.add("c-x", "c-e", filter=emacs_mode & ~has_selection)( 

37 get_by_name("edit-and-execute-command") 

38 ) 

39 

40 return key_bindings 

41 

42 

43def load_vi_open_in_editor_bindings() -> KeyBindings: 

44 """ 

45 Pressing 'v' in navigation mode will open the buffer in an external editor. 

46 """ 

47 key_bindings = KeyBindings() 

48 key_bindings.add("v", filter=vi_navigation_mode)( 

49 get_by_name("edit-and-execute-command") 

50 ) 

51 return key_bindings