cosmic-text icon indicating copy to clipboard operation
cosmic-text copied to clipboard

Save and resume editor state / handle external

Open tigregalis opened this issue 7 months ago • 1 comments

Possibly related to https://github.com/pop-os/cosmic-text/issues/283

I'd like to use Editor actions to drive changes to "editor state" that lives "outside" so to speak. Without having to impl Edit for MyType and reimplement Editor, which already contains all of the behaviours I need. Currently my workaround is:

  1. Construct an ephemeral TempEditor (wraps cosmic_text::Editor) around the existing cosmic_text::Buffer,
  2. Apply any changes to the TempEditor and it will be reflected in the Buffer
  3. Extract and store any state that needs to be persisted between frames in EditorState (Cursor, Selection) and drop the TempEditor
  4. Working backwards, update the bevy Text component from the updated Buffer

See https://github.com/tigregalis/bevy_spans_ent/blob/main/examples/editor.rs#L128

There's a few possibilities:

  1. I'm running into several bugs with this so it might not be the right solution, but it may be that I'm not getting enough information out of the Editor, so one possibility would be to provide a method to save and resume editor state (i.e. basically everything that Editor currently holds, except the BufferRef: it would be up to the owner to make sure they resume Editor with the same effective Buffer) - I think this could be generally useful.
  2. Have some means (e.g. by passing "handlers") to operate on "external" state in response to Editor actions, but ideally without having to reimplement all of Editor.
  3. I noticed there was a Change list that was part of Editor which might also serve my purposes but no examples of how that might be used.

tigregalis avatar Jul 10 '24 13:07 tigregalis