I try to understand scripting objects in Draft.
When global draft object should be used and when editor object is better solution?
I try to understand scripting objects in Draft.
When global draft object should be used and when editor object is better solution?
If I need to be able to undo a change or work with current selections I use editor, otherwise I tend to use draft. I always try to use draft rather than editor because then I can work seamlessly with the underlying object which has a wide range of advantages when you want to work with sets of notes (drafts) and when you don’t want to directly drive the user’s UI experience on the current draft.
The note on the Editor object docs:
NOTE: Generally speaking, editor methods are best used for quick text manipulations of the type used in the extended keyboard. Most substantial updates to draft content are better applied using the
draftobject.
When you are using editor you are editing the text in the editor, and every change is updating the UI, on the main thread. Also, note that is not always the same text as in the draft. It often is when you are running an action from the app, but it’s not necessarily if the action it triggered other ways, programmatically, via Shortcuts, etc. a different draft could be loaded in the editor.