Skip to content

Commit 47ba21f

Browse files
committed
Fixed multiple weird errors connected with Selection::extend.
1 parent cc5faaf commit 47ba21f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

core/selection.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,20 @@
215215

216216
function moveNativeSelectionToBookmark( document, bm ) {
217217
var sel = document.getSelection(),
218-
range = document.createRange();
218+
range = document.createRange(),
219+
wasZWS = ( bm[ 0 ].node.textContent == '\u200B' );
219220

220221
range.setStart( bm[ 0 ].node, bm[ 0 ].offset );
221222
range.collapse( true );
222223
sel.removeAllRanges();
223224
sel.addRange( range );
225+
226+
// For some unknown reason, Selection::addRange clears text node content
227+
// if the only character in the content was ZWS. So to prevent
228+
// errors, we recreate that. (#13284, #13389, #13307)
229+
if ( wasZWS && ( bm[ 0 ].node == bm[ 1 ].node ) && bm[ 0 ].node.textContent.length === 0 )
230+
bm[ 1 ].node.textContent = '\u200B';
231+
224232
sel.extend( bm[ 1 ].node, bm[ 1 ].offset );
225233
}
226234

0 commit comments

Comments
 (0)