Topic on Talk:VisualEditor/Gadgets/Add a tool

Create a tool who insert wikitext

4
Nicolas senechal (talkcontribs)

Hello, I try to insert wikitext like <br> with gadget in order to not pass by the wikitext Editor so I try this after looking in the wiki.

ve.ui.commandRegistry.register(

new ve.ui.Command(

// Command name

'myBreak',

// Type and name of the action to execute

'content', 'insert', // Calls the ve.ui.ContentAction#insert method

{

// Extra arguments for the action

args: [

// Content to insert

[

'\n',

ve.init.target.getSurface().getModel().getFragment().insertHtml('<br>')

],// Annotate content to match surrounding annotations?

false,

// Move cursor to after the new content? (otherwise - select it)

true],

supportedSelections: [ 'linear' ]
    
}));

But I have an error at the line 35 when I test my gadget here is the error in the consol.

Uncaught TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'VeDmDocument'
    |     property 'bindings' -> object with constructor 'Object'
    |     property 'transact' -> object with constructor 'Array'
    |     ...
    |     property 'context' -> object with constructor 'VeDmInternalList'
    --- property 'document' closes the circle
    at JSON.stringify (<anonymous>)
    at VeDmSurface.ve.dm.Surface.storeChanges (load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:178:921)
    at VeDmSurface.OO.EventEmitter.emit (<anonymous>:445:652)
    at VeDmSurface.ve.dm.Surface.breakpoint (load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:174:240)
ve.dm.Surface.storeChanges @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:178
OO.EventEmitter.emit @ VM3027:445
ve.dm.Surface.breakpoint @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:174
setTimeout (asynchrone)
OO.EventEmitter.emit @ VM3027:445
ve.dm.Surface.breakpoint @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:174
setInterval (asynchrone)
ve.dm.Surface.startHistoryTracking @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:161
ve.dm.Surface.resetHistoryTrackingInterval @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:162
ve.dm.Surface.breakpoint @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:173
ve.ce.Surface.handleObservedChanges @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:484
ve.ce.SurfaceObserver.pollOnceInternal @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:508
ve.ce.SurfaceObserver.pollOnce @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:508
ve.ce.Surface.afterDocumentMouseUp @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:440
setTimeout (asynchrone)
ve.ce.Surface.onDocumentMouseUp @ load.php?lang=fr&modules=ext.visualEditor.core%2Cmwtransclusion&skin=timeless&version=3ben0:440
dispatch @ load.php?lang=fr&modules=ext.CodeMirror.lib%7Cext.HighlightjsIntegration%7Cjquery%2Coojs-ui-core%2Coojs-ui-widgets%7Cjquery.ui%7Coojs-ui.styles.icons-editing-advanced&skin=timeless&version=1l7ie:475
elemData.handle @ load.php?lang=fr&modules=ext.CodeMirror.lib%7Cext.HighlightjsIntegration%7Cjquery%2Coojs-ui-core%2Coojs-ui-widgets%7Cjquery.ui%7Coojs-ui.styles.icons-editing-advanced&skin=timeless&version=1l7ie:471

I don't understand this error or how to resolved it.

so if someone has a hint I would be thankful. Thank you

Whatamidoing (WMF) (talkcontribs)
Nicolas senechal (talkcontribs)

thank you for the tips, but I don't know why the code dosent work. he have this error :

load.php?lang=fr&modules=ext.HighlightjsIntegration%7Cjquery&skin=timeless&version=mfrgu:197

       jQuery.Deferred exception: ve.ui.wikitextCommandRegistry is not a function TypeError: ve.ui.wikitextCommandRegistry is not a function

So I look to the documentation and I found ve.ui.MWWikitextCommandRegistry - VisualEditor - Documentation (wikimedia.org) so normaly it work...

so did you have any tips (maybe somethink I do wrong) because I know that ve.ui should work here.

Whatamidoing (WMF) (talkcontribs)

Unfortunately, I don't know anything about coding. Perhaps it would be worth asking at Project:Support desk? Some coders hang out there.

Reply to "Create a tool who insert wikitext"