You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 (wraps cosmic_text::Editor) around the existing cosmic_text::Buffer,
Apply any changes to the TempEditor and it will be reflected in the Buffer
Extract and store any state that needs to be persisted between frames in EditorState (Cursor, Selection) and drop the TempEditor
Working backwards, update the bevy Text component from the updated Buffer
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.
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 of Editor which might also serve my purposes but no examples of how that might be used.
The text was updated successfully, but these errors were encountered:
I implemented Option 1 as it was fairly straightforward, but saving/resume the internal state wasn't the issue as far as my implementation went: I've resolved that now. (It turns out there is some nuance with BufferLine's AttrsList::spans that I wasn't aware of. I think this could benefit from some documentation, so I'll submit a PR for that.)
Cursor and Selection (which are already accessible) is possibly enough state to save.
However, I still think these ideas of saving/resuming editor state, or mutating external state in response to editor actions, could be generally useful though, especially when something else owns the buffer, but I don't have a clear suggestion of what that API or implementation looks like.
Another option here is to make all Editor/Edit methods take a &mut Buffer as a parameter, and have a BorrowedWithBuffer helper, in the same way we made the split between Buffer and FontSystem and have BorrowedWithFontSystem.
Possibly related to #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 reimplementEditor
, which already contains all of the behaviours I need. Currently my workaround is:TempEditor
(wrapscosmic_text::Editor
) around the existingcosmic_text::Buffer
,TempEditor
and it will be reflected in theBuffer
EditorState
(Cursor
,Selection
) and drop theTempEditor
Text
component from the updatedBuffer
See https://github.com/tigregalis/bevy_spans_ent/blob/main/examples/editor.rs#L128
There's a few possibilities:
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.Editor
.Change
list that was part ofEditor
which might also serve my purposes but no examples of how that might be used.The text was updated successfully, but these errors were encountered: