cosmic-text
cosmic-text copied to clipboard
Save and resume editor state / handle external
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:
- Construct an ephemeral
TempEditor
(wrapscosmic_text::Editor
) around the existingcosmic_text::Buffer
, - Apply any changes to the
TempEditor
and it will be reflected in theBuffer
- Extract and store any state that needs to be persisted between frames in
EditorState
(Cursor
,Selection
) and drop theTempEditor
- Working backwards, update the bevy
Text
component from the updatedBuffer
See https://github.com/tigregalis/bevy_spans_ent/blob/main/examples/editor.rs#L128
There's a few possibilities:
- 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 thatEditor
currently holds, except theBufferRef
: it would be up to the owner to make sure they resumeEditor
with the same effectiveBuffer
) - I think this could be generally useful. - 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
. - I noticed there was a
Change
list that was part ofEditor
which might also serve my purposes but no examples of how that might be used.