1818 to_scope_types ,
1919)
2020from .snippets_get import (
21- get_custom_insertion_snippet ,
22- get_custom_wrapper_snippet ,
2321 get_insertion_snippet ,
2422 get_wrapper_snippet ,
23+ get_list_insertion_snippet ,
24+ get_list_wrapper_snippet ,
2525)
2626
2727mod = Module ()
3434mod .list ("cursorless_insert_snippet_action" , desc = "Cursorless insert snippet action" )
3535
3636
37- def insert_snippet (
38- snippet : CustomInsertionSnippet | ListInsertionSnippet ,
39- destination : CursorlessDestination ,
40- ):
41- actions .user .private_cursorless_command_and_wait (
42- InsertSnippetAction (snippet , destination ),
43- )
44-
45-
46- def wrap_with_snippet (
47- snippet : CustomWrapperSnippet | ListWrapperSnippet ,
48- target : CursorlessTarget ,
49- ):
50- actions .user .private_cursorless_command_and_wait (
51- WrapperSnippetAction (snippet , target ),
52- )
53-
54-
55- def insert_community_snippet (
56- name : str ,
57- substitutions : dict [str , str ] | None ,
58- destination : CursorlessDestination ,
59- use_list : bool ,
60- ):
61- snippet = (
62- get_insertion_snippet (name , substitutions )
63- if use_list
64- else get_custom_insertion_snippet (name , substitutions )
65- )
66- insert_snippet (snippet , destination )
67-
68-
69- def wrap_with_community_snippet (
70- name : str ,
71- target : CursorlessTarget ,
72- use_list : bool ,
73- ):
74- snippet = (
75- get_wrapper_snippet (name ) if use_list else get_custom_wrapper_snippet (name )
76- )
77- wrap_with_snippet (snippet , target )
78-
79-
8037@ctx .action_class ("user" )
8138class UserActions :
82- # These actions use list snippets since no language mode is forced
39+ # Since we don't have a forced language mode, these actions send all the snippets.
40+ # (note that this is the default mode of action, as most of the time the user will not
41+ # have a forced language mode)
8342
8443 def insert_snippet_by_name (
8544 name : str , # pyright: ignore [reportGeneralTypeIssues]
8645 # Don't add optional; We need to match the type in community
8746 substitutions : dict [str , str ] = None ,
8847 ):
89- insert_community_snippet (
90- name ,
91- substitutions ,
48+ action = InsertSnippetAction (
49+ get_list_insertion_snippet (name , substitutions ),
9250 ImplicitDestination (),
93- use_list = True ,
9451 )
52+ actions .user .private_cursorless_command_and_wait (action )
53+
9554
9655 def private_cursorless_insert_community_snippet (
9756 name : str , # pyright: ignore [reportGeneralTypeIssues]
9857 destination : CursorlessDestination ,
9958 ):
100- insert_community_snippet (
101- name ,
102- substitutions = None ,
103- destination = destination ,
104- use_list = True ,
59+ action = InsertSnippetAction (
60+ get_list_insertion_snippet (name ),
61+ destination ,
10562 )
63+ actions .user .private_cursorless_command_and_wait (action )
10664
10765 def private_cursorless_wrap_with_community_snippet (
10866 name : str , # pyright: ignore [reportGeneralTypeIssues]
10967 target : CursorlessTarget ,
11068 ):
111- wrap_with_community_snippet (
112- name ,
69+ action = WrapperSnippetAction (
70+ get_list_wrapper_snippet ( name ) ,
11371 target ,
114- use_list = True ,
11572 )
73+ actions .user .private_cursorless_command_and_wait (action )
11674
11775
11876@mod .action_class
@@ -129,7 +87,8 @@ def cursorless_insert_snippet(
12987 languages = None ,
13088 substitutions = None ,
13189 )
132- insert_snippet (snippet , destination )
90+ action = InsertSnippetAction (snippet , destination )
91+ actions .user .private_cursorless_command_and_wait (action )
13392
13493 def cursorless_wrap_with_snippet (
13594 body : str , # pyright: ignore [reportGeneralTypeIssues]
@@ -144,7 +103,8 @@ def cursorless_wrap_with_snippet(
144103 ScopeType (scope ) if scope else None ,
145104 languages = None ,
146105 )
147- wrap_with_snippet (snippet , target )
106+ action = WrapperSnippetAction (snippet , target )
107+ actions .user .private_cursorless_command_and_wait (action )
148108
149109 # These actions use a single custom snippets since a language mode is forced
150110
@@ -153,20 +113,21 @@ def private_cursorless_insert_community_snippet(
153113 destination : CursorlessDestination ,
154114 ):
155115 """Cursorless: Insert community snippet <name>"""
156- insert_community_snippet (
157- name ,
158- substitutions = None ,
159- destination = destination ,
160- use_list = False ,
116+ action = InsertSnippetAction (
117+ CustomInsertionSnippet . create (
118+ actions . user . get_insertion_snippet ( name ) ,
119+ ) ,
120+ destination ,
161121 )
122+ actions .user .private_cursorless_command_and_wait (action )
162123
163124 def private_cursorless_wrap_with_community_snippet (
164125 name : str , # pyright: ignore [reportGeneralTypeIssues]
165126 target : CursorlessTarget ,
166127 ):
167128 """Cursorless: Wrap target with community snippet <name>"""
168- wrap_with_community_snippet (
169- name ,
129+ action = WrapperSnippetAction (
130+ get_wrapper_snippet ( name ) ,
170131 target ,
171- use_list = False ,
172132 )
133+ actions .user .private_cursorless_command_and_wait (action )
0 commit comments