Divec has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/380451 )
Change subject: Make IME tests more consistent across test environments ...................................................................... Make IME tests more consistent across test environments Bug: T176453 Change-Id: Id6441ed82bd810de253db5c9696343da4657a7f6 --- M tests/ce/ve.ce.TestRunner.js 1 file changed, 16 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/51/380451/1 diff --git a/tests/ce/ve.ce.TestRunner.js b/tests/ce/ve.ce.TestRunner.js index a48bacc..f1412ae 100644 --- a/tests/ce/ve.ce.TestRunner.js +++ b/tests/ce/ve.ce.TestRunner.js @@ -182,34 +182,33 @@ * @param {string} text The new text */ ve.ce.TestRunner.prototype.changeText = function ( text ) { - var focusNode, focusOffset; + var paragraph, range, textNode; // TODO: This method doesn't handle arbitrary text changes in a paragraph // with non-text nodes. It just works for the main cases that are important // in the existing IME tests. - // Store the focus before the selection gets clobbered - focusNode = this.nativeSelection.focusNode; - focusOffset = this.nativeSelection.focusOffset; - - // Empty all descendent text nodes + // Remove all descendent text nodes // This may clobber the selection, so the test had better call changeSel next. - $( this.getParagraph() ).find( '*' ).addBack().contents().each( function () { + paragraph = this.getParagraph(); + $( paragraph ).find( '*' ).addBack().contents().each( function () { if ( this.nodeType === Node.TEXT_NODE ) { - this.textContent = ''; + this.parentNode.removeChild( this ); } } ); - // Insert text at the focus - if ( focusNode === null ) { - throw new Error( 'No focus node' ); - } else if ( focusNode.nodeType === Node.TEXT_NODE ) { - focusNode.textContent = text; + range = document.createRange(); + if ( text === '' ) { + range.setStart( paragraph, 0 ); } else { - focusNode.insertBefore( - document.createTextNode( text ), - focusNode.childNodes[ focusOffset ] - ); + // Insert the text at the start of the paragraph, and put the cursor after + // the insertion, to ensure consistency across test environments. + // See T176453 + textNode = document.createTextNode( text ); + paragraph.insertBefore( textNode, paragraph.firstChild ); + range.setStart( textNode, text.length ); } + this.nativeSelection.removeAllRanges(); + this.nativeSelection.addRange( range ); this.lastText = text; }; -- To view, visit https://gerrit.wikimedia.org/r/380451 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id6441ed82bd810de253db5c9696343da4657a7f6 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Divec <da...@troi.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits