Realtime Preview: also trigger on form.reset()

If the form is reset, make sure that the preview is re-run.
There isn't actually any reset button in the normal edit
form, but Edit Recovery uses reset() to remove any
recovered data, and if RTP is open when that's done the preview
needs to be updated.

Bug: T351821
Depends-On: I1ec757d5ddd9f0db66496c6aaef70747d93a5c83
Change-Id: I30481edae4c071e8586ac1dc7d587bd550965967
This commit is contained in:
Sam Wilson 2023-12-07 13:25:45 +08:00 committed by Samtar
parent 3bf5db1857
commit f1bcbe75c3

View file

@ -158,6 +158,7 @@ RealtimePreview.prototype.saveUserPref = function () {
RealtimePreview.prototype.toggle = function ( saveUserPref ) {
var $uiText = this.context.$ui.find( '.wikiEditor-ui-text' );
var $textarea = this.context.$textarea;
var $form = $textarea.parents( 'form' );
// Save the current cursor selection and focused element.
var cursorPos = $textarea.textSelection( 'getCaretPosition', { startAndEnd: true } );
@ -174,6 +175,7 @@ RealtimePreview.prototype.toggle = function ( saveUserPref ) {
// Remove the keyup handler.
$textarea.off( this.eventNames );
$form.off( 'reset.realtimepreview' );
// Let other things happen after disabling.
mw.hook( 'ext.WikiEditor.realtimepreview.disable' ).fire( this );
@ -194,6 +196,8 @@ RealtimePreview.prototype.toggle = function ( saveUserPref ) {
$textarea
.off( this.eventNames )
.on( this.eventNames, this.getEventHandler() );
$form.off( 'reset.realtimepreview' )
.on( 'reset.realtimepreview', this.getEventHandler() );
// Hide or show the manual-reload message bar.
this.manualWidget.toggle( this.inManualMode );