Skip to content

Commit 785a750

Browse files
Pass individual changes to browser extension (#2709)
Today we only pass the text to the browser extension. This change also passes the changes/diffs themselves so we can update editor content without messing up the scrolling position. ## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
1 parent f9a9ec1 commit 785a750

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

cursorless-everywhere-talon/cursorless_everywhere_talon_browser.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from talon import Context, Module, actions
22

3-
from .cursorless_everywhere_types import EditorEdit, EditorState, SelectionOffsets
3+
from .cursorless_everywhere_types import (
4+
EditorChange,
5+
EditorEdit,
6+
EditorState,
7+
SelectionOffsets,
8+
)
49

510
mod = Module()
611

@@ -43,8 +48,9 @@ def cursorless_everywhere_edit_text(
4348
edit: EditorEdit, # pyright: ignore [reportGeneralTypeIssues]
4449
):
4550
command = {
46-
"id": "setText",
51+
"id": "editText",
4752
"text": edit["text"],
53+
"changes": get_serializable_editor_changes(edit["changes"]),
4854
}
4955
res = rpc_get(command)
5056
if use_fallback(res):
@@ -71,3 +77,17 @@ def get_serializable_selections(selections: list[SelectionOffsets]):
7177
}
7278
)
7379
return result
80+
81+
82+
def get_serializable_editor_changes(changes: list[EditorChange]):
83+
result: list[EditorChange] = []
84+
for i in range(changes.length): # pyright: ignore [reportAttributeAccessIssue]
85+
change = changes[i]
86+
result.append(
87+
{
88+
"text": change["text"],
89+
"rangeOffset": change["rangeOffset"],
90+
"rangeLength": change["rangeLength"],
91+
}
92+
)
93+
return result

0 commit comments

Comments
 (0)