textSelection compat layer getCaretPosition could error if no selection

Reported as happening when a gadget was triggering some calls early in
initialization, presumably before the surface had reached the point
where it had been focused.

Bug: T334930
Change-Id: Idebc31ef042d45acf59d8dceaa7566744233f426
This commit is contained in:
David Lynch 2023-04-18 09:59:43 -05:00
parent 2fde6f2caa
commit 4d4093b938

View file

@ -77,7 +77,7 @@ ve.ui.MWWikitextSurface = function VeUiMWWikitextSurface() {
caretPos = range ? surfaceModel.getSourceOffsetFromOffset( range.start ) : 0;
return options.startAndEnd ?
[ caretPos, surfaceModel.getSourceOffsetFromOffset( range.end ) ] :
[ caretPos, range ? surfaceModel.getSourceOffsetFromOffset( range.end ) : 0 ] :
caretPos;
},
replaceSelection: function ( value ) {