Draft changes in editor without calling draft.update()

Is it expected behavior that when making changes to the draft variable within an action (e.g. changing draft.content), but not calling draft.update(), that the text visible in the editor would reflect those changes?

The docs say that calling drafts.update() is required to commit the draft, which is the case (immediately tapping on the draft in the draft list causes it to reload the original). However, the docs don’t specify what the behavior should be with the content of the editor.

In some cases, it seems it is possible for that uncommitted draft to become saved by some interactions in the editor.

I suppose I can store the modified text in a separate tag, and avoid changing draft.content, but I was really hoping to have an action that could be transparently dropped in between other action steps (using the Include Action step) to do some pre-processing of the draft in some cases without changing the other actions use of draft.content.

1 Like

The short answer is yes, the editor will reflect those changes. There have been some changes to behaviors here recently because it just caused too many issues to not keep those values in sync.

One of the main reasons Drafts 4 had separate scripting functions for keys from actions was the complexity created by the intermingling them. I was trying to get away with a more laissez-faire loose coupling, but it caused too many edge cases, so Drafts is now more aggressively pushing changes made to the active draft back to the editor when actions are run. If this is not done, you can end up with cases where the version of the draft loaded in the editor is older and can overwrite changes made in the scripts - or visa versa. Or if people intermingle steps/scripts that manipulate the editor with those that manipulate the draft, the two can get out of sync and you get confusing results.

There are other ways to create and use temporary content. As you mentioned, template tags could be used. You can also unload the draft from the editor using editor.load(d); or editor.new(); and that draft will no longer be in the editor and will not be updated.

1 Like

Thanks for the detail. That makes sense.

I was looking for something like an unload() function to complement the load() functions and didn’t consider the new() function. Thanks!