Talk:VisualEditor/Gadgets

Can you please make this document better? This is the one resource available to build VE plugins but i can't understand this article. You didn't specify exactly how to use scripts?
 * I rewrote some of the guide so it would be easier to understand. Please follow VisualEditor gadgets. If you have more specific questions or suggestion I would like to hear. Eran (talk) 19:49, 22 March 2014 (UTC)

Breaking change for VisualEditor gadgets/scripts
From https://lists.wikimedia.org/pipermail/wikitech-ambassadors/2015-September/001256.html. HTH, --Elitre (WMF) (talk) 12:53, 9 September 2015 (UTC) 

All, A month or so ago the main access point for VisualEditor was renamed from:

ext.visualEditor.*viewPageTarget*.init ext.visualEditor.*viewPageTarget*.noscript

… to:

ext.visualEditor.*desktopArticleTarget*.init ext.visualEditor.*desktopArticleTarget*.noscript

… ​ as part of our work for merging the mobile and desktop interfaces. We temporarily retained the old names as fall-backs for cached HTML purposes and to give a moment for VisualEditor gadgets and scripts to be fixed before the breaking change to their access API was moved.

This will now be merged into master today, after the cut, and so go out to production from Tuesday 15 September as part of MediaWiki 1.26wmf23. For the few gadgets and scripts that hook into VisualEditor, please switch over now so your users aren't disrupted.

J.​ -- James D. Forrester Lead Product Manager, Editing 

Working with the underlying wikitext
I'm not sure whether someone here will be able to help me, but I just hope so. For some of my usecases it is much easier to work with the underlying wikitext rather than with the VE data, and this actually works pretty well so far.

To get the wikitext of the current document I use which works as expected.

To replace the current document with some wikitext I use which almost works as expected. It changes the document to something that has a wikitext equivalent to the one I added with the function, but spaces etc. are changed.

E.g. calling will add the template at the start as expected, but will add spaces around the equal signs.

As this doesn't happen when I switch between VE and source code editor, it must be possible to add wikitext, that will be kept in the exact form that was provided. Can someone help me to fix my code to do so? And, are there chances to include these functions as helper methods for gadgets in VE, so I don't have worry about updating the duplicated code? --Schnark (talk) 10:00, 27 February 2016 (UTC)


 * A very hacky variant, which works in most, but not in all cases:


 * Anyone with any better ideas? --Schnark (talk) 09:11, 9 March 2016 (UTC)

Examples
This guide is hard to follow because it does not have little working examples. I could not succeed adding a new dummy toolbar button to visual editor toolbar this way. I ask you to expand the guide.

Also, I would like to manipulate templates in my user script. For example, find all templates in a section and increment the value on each, then save the wikitext back. It is not clear to me how to do that from the guide.

It is also in English only. I propose to add translations.

--Gryllida 23:59, 29 November 2016 (UTC)
 * Perhaps User:Schnark may be able to help here? :) --Elitre (WMF) (talk) 09:55, 30 November 2016 (UTC)