Pass individual changes to browser extension#2709
Merged
AndreasArvidsson merged 1 commit intomainfrom Jan 10, 2025
Merged
Conversation
phillco
approved these changes
Jan 10, 2025
Comment on lines
+84
to
+93
| for i in range(changes.length): # pyright: ignore [reportAttributeAccessIssue] | ||
| change = changes[i] | ||
| result.append( | ||
| { | ||
| "text": change["text"], | ||
| "rangeOffset": change["rangeOffset"], | ||
| "rangeLength": change["rangeLength"], | ||
| } | ||
| ) | ||
| return result |
Member
There was a problem hiding this comment.
We can't use a list comprehension here because changes it is not a true Python list, it's a QuickJS array which doesn't support that. We also don't have the ability to convert these JavaScript objects to Python with a one shot utility because certain reflection data is missing per Andreas.
But what we could do is make simple wrapping utilities that will convert one level of the tree:
- JavaScript array to Python list (just does a iteration like this without looking at the objects in the array)
- JavaScript dictionary to Python dictionary (you would have to pass exactly the keys you expect)
With this approach, we can contain the weirdness of the JavaScript objects to where we get them, requiring a couple of utility calls, and use proper Python code thereafter.
phillco
approved these changes
Jan 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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