Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlText.insert_embed() doesn't seem to work #220

Open
jonathon-love opened this issue Jan 19, 2025 · 2 comments
Open

XmlText.insert_embed() doesn't seem to work #220

jonathon-love opened this issue Jan 19, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@jonathon-love
Copy link

Description

Hi,

I'm trying to use pycrdt to interop with a yjs backed lexical editor, however it looks as though the insert_embed() function of the XmlText class does not work.

Reproduce

the following code:


import pycrdt

def print_events(events: list):
    for event in events:
        print(event)

doc = pycrdt.Doc()
xml_frag = pycrdt.XmlFragment()
doc['root'] = xml_frag

xml_frag.observe_deep(print_events)

xml_text = pycrdt.XmlText()
xml_frag.children.append(xml_text)
xml_text.insert(0, 'the fish was delish')

outputs:

{children_changed: True, target: , path: [], delta: [{'insert': [<pycrdt._xml.XmlText object at 0x1036850d0>]}], keys: {}}
{children_changed: None, target: the fish was delish, path: [0], delta: [{'insert': 'the fish was delish'}], keys: {}}

so far so good ... if i continue:

>>> xml_text.insert_embed(0, pycrdt.Map({"__style":"","__type":"text","__mode":0,"__detail":0,"__format":0}))
{children_changed: None, target: undefinedthe fish was delish, path: [0], delta: [{'insert': None}], keys: {}}

and:

>>> xml_text.diff()
[(None, None), ('the fish was delish', None)]

Expected behavior

the reason i expect something different is because lexical does this with yjs, calling .insertEmbed()

https://github.com/facebook/lexical/blob/main/packages/lexical-yjs/src/CollabElementNode.ts#L602

if i perform the same edit with lexical, apply those changes to the pycrdt doc with doc.apply_update(), i get

>>> xml_text.diff()
[(<builtins.Map object at 0x40260f9ad0>, None), ('the fish was delish', None)]

Context

i'm not actually sure if lexical and yjs are actually behaving correctly here ... insertEmbed() doesn't look to be a documented function ... and so i'm inferring all this from behaviour.

with thanks

@jonathon-love jonathon-love added the bug Something isn't working label Jan 19, 2025
@jonathon-love
Copy link
Author

found other people grappling with this

y-crdt/ypy#143

@davidbrochart
Copy link
Collaborator

Hmm I think that @ColonelThirtyTwo, @dmonad or @Horusiath can best answer this question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants