From 3a9c8f78ba8602e571317215462a156d55af37ea Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 2 Dec 2024 18:06:01 +0000 Subject: [PATCH] Replace x.slice(0,x.length-y) with x.slice(0,-y) Requires y to be non-zero. Change-Id: I033732cb78b5e3149ac26e19243bf21b143eb105 --- modules/ve-mw/ui/widgets/ve.ui.MWPreTextInputWidget.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWPreTextInputWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWPreTextInputWidget.js index c3d70d5ab9..ad047df96f 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWPreTextInputWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWPreTextInputWidget.js @@ -29,10 +29,14 @@ OO.inheritClass( ve.ui.MWPreTextInputWidget, ve.ui.WhitespacePreservingTextInput */ ve.ui.MWPreTextInputWidget.prototype.setValueAndWhitespace = function ( value ) { this.whitespace[ 0 ] = value.match( /^\n?/ )[ 0 ]; - value = value.slice( this.whitespace[ 0 ].length ); + if ( this.whitespace[ 0 ] ) { + value = value.slice( this.whitespace[ 0 ].length ); + } this.whitespace[ 1 ] = value.match( /\n?$/ )[ 0 ]; - value = value.slice( 0, value.length - this.whitespace[ 1 ].length ); + if ( this.whitespace[ 1 ] ) { + value = value.slice( 0, -this.whitespace[ 1 ].length ); + } this.setValue( value ); };