[TemplateScript] support VisualEditor
Add support for editing VisualEditor content. TemplateScript already supports the #wpTextbox1 wikitext editor and CodeEditor (since 2.0).
VisualEditor support is tricky:
- There's no official interface to VisualEditor, though we can hack it using an undocumented internal interface. This interface is subject to change, though.
- VisualEditor doesn't use a text paradigm like CodeEditor and the standard wikitext editor. Content is represented as a data structure instead.
This raises a few issues for TemplateScript:
- TemplateScript assumes all content can be manipulated through a text representation. That isn't true for VisualEditor. For example, with some work it could edit the text but it couldn't manipulate links which are non-textual.
- Scripts that deal with wikitext won't work as expected (for example,
'''bold text'''won't match bold text). - Search & replace across format boundaries need to resolve the boundaries somehow. (For example, do we bold the replace if half the match is bold?)
If I remember correctly, there is a way to get the wikitext which corresponds to the current VisualEditor representation the user is seeing in a page (no idea what is the command for that though), and this could be used so that users can apply the usual search/replace to this representation before saving the page (but if I'm not mistaken, this would have to be saved through the usual ways instead of using VE - that is, it would only be useful if the replacements are done after the user finished using VE for changing the page).
It is likely the same principle which allows one to switch to wikitext while editing with VE, but not to switch back to VE once the user is using wikitext.