Skip to content

Commit ea4f79a

Browse files
Use fall back
1 parent 86ff8de commit ea4f79a

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

cursorless-everywhere-talon/cursorless_everywhere_talon_browser.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
class Actions:
2222
def cursorless_everywhere_get_editor_state() -> EditorState:
2323
command = {"type": "getActiveEditor"}
24-
return actions.user.run_rpc_command_get(RPC_COMMAND, command)
24+
res = rpc_get(command)
25+
if use_fallback(res):
26+
return actions.next()
27+
return res
2528

2629
def cursorless_everywhere_set_selections(
2730
selections: list[SelectionOffsets], # pyright: ignore [reportGeneralTypeIssues]
@@ -30,13 +33,25 @@ def cursorless_everywhere_set_selections(
3033
"type": "setSelections",
3134
"selections": get_serializable_selections(selections),
3235
}
33-
actions.user.run_rpc_command_and_wait(RPC_COMMAND, command)
36+
res = rpc_get(command)
37+
if use_fallback(res):
38+
actions.next(selections)
3439

3540
def cursorless_everywhere_edit_text(
3641
edit: EditorEdit, # pyright: ignore [reportGeneralTypeIssues]
3742
):
3843
command = {"type": "setText", "text": edit["text"]}
39-
actions.user.run_rpc_command_and_wait(RPC_COMMAND, command)
44+
res = rpc_get(command)
45+
if use_fallback(res):
46+
actions.next(edit)
47+
48+
49+
def rpc_get(command: dict):
50+
return actions.user.run_rpc_command_get(RPC_COMMAND, command)
51+
52+
53+
def use_fallback(result: dict) -> bool:
54+
return result.get("fallback", False)
4055

4156

4257
# What is passed from cursorless everywhere js is a javascript object, which is not serializable for python.

0 commit comments

Comments
 (0)