Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/154407
Change subject: Ignore whitespace when generating paste context ...................................................................... Ignore whitespace when generating paste context textStart/End offsets assume there is no inner whitespace so make sure that is the case. Bug: 69595 Change-Id: Ibfddaf94aaf7daedf05eec56821994f7f30ddd56 --- M src/ce/ve.ce.Surface.js M tests/ce/ve.ce.Surface.test.js 2 files changed, 37 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/07/154407/1 diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js index b76da37..207840f 100644 --- a/src/ce/ve.ce.Surface.js +++ b/src/ce/ve.ce.Surface.js @@ -985,7 +985,7 @@ * @param {jQuery.Event} e Paste event */ ve.ce.Surface.prototype.beforePaste = function ( e ) { - var tx, node, range, rangyRange, sel, + var tx, node, range, contextElement, rangyRange, sel, context, leftText, rightText, textNode, textStart, textEnd, selection = this.model.getSelection(), clipboardData = e.originalEvent.clipboardData, @@ -1020,7 +1020,13 @@ // to the paste target to give CE some context. textStart = textEnd = 0; range = node.getRange(); - context = [ node.getClonedElement() ]; + contextElement = node.getClonedElement(); + // Throw away inner whitespace otherwise our textStart/End + // offsets will be wrong. + if ( contextElement.internal ) { + delete contextElement.internal.whitespace; + } + context = [ contextElement ]; // If there is content to the left of the cursor, put a placeholder // character to the left of the cursor if ( selection.start > range.start ) { diff --git a/tests/ce/ve.ce.Surface.test.js b/tests/ce/ve.ce.Surface.test.js index 61e339f..bf08712 100644 --- a/tests/ce/ve.ce.Surface.test.js +++ b/tests/ce/ve.ce.Surface.test.js @@ -553,7 +553,7 @@ } ); QUnit.test( 'beforePaste/afterPaste', function ( assert ) { - var i, exampleDoc = '<p></p><p>Foo</p>', + var i, exampleDoc = '<p></p><p>Foo</p><h2> Baz </h2>', TestEvent = function ( data ) { this.originalEvent = { clipboardData: { @@ -579,7 +579,7 @@ ], remove: [] }, - { type: 'retain', length: 8 } + { type: 'retain', length: 13 } ] ], msg: 'Text into empty paragraph' @@ -596,7 +596,7 @@ insert: [ 'B', 'a', 'r' ], remove: [] }, - { type: 'retain', length: 5 } + { type: 'retain', length: 10 } ] ], msg: 'Text into paragraph' @@ -617,7 +617,7 @@ ], remove: [] }, - { type: 'retain', length: 5 } + { type: 'retain', length: 10 } ] ], msg: 'Formatted text into paragraph' @@ -635,7 +635,7 @@ insert: [ 'B', 'a', 'r' ], remove: [] }, - { type: 'retain', length: 5 } + { type: 'retain', length: 10 } ] ], msg: 'Formatted text into paragraph with pasteSpecial' @@ -652,7 +652,7 @@ insert: [ 'B', 'a', 'r' ], remove: [] }, - { type: 'retain', length: 5 } + { type: 'retain', length: 10 } ] ], msg: 'Paragraph into paragraph' @@ -669,7 +669,7 @@ insert: [ 'B', 'a', 'r' ], remove: [] }, - { type: 'retain', length: 3 } + { type: 'retain', length: 8 } ] ], msg: 'Paragraph at end of paragraph' @@ -686,10 +686,27 @@ insert: [ 'B', 'a', 'r' ], remove: [] }, - { type: 'retain', length: 6 } + { type: 'retain', length: 11 } ] ], msg: 'Paragraph at start of paragraph' + }, + { + range: new ve.Range( 11 ), + pasteHtml: '<h2>Quux</h2>', + expectedRange: new ve.Range( 15 ), + expectedOps: [ + [ + { type: 'retain', length: 11 }, + { + type: 'replace', + insert: [ 'Q', 'u', 'u', 'x' ], + remove: [] + }, + { type: 'retain', length: 3 } + ] + ], + msg: 'Heading into heading with whitespace' }, { range: new ve.Range( 4 ), @@ -703,7 +720,7 @@ insert: [ '☂', 'f', 'o', 'o', '☀' ], remove: [] }, - { type: 'retain', length: 5 } + { type: 'retain', length: 10 } ] ], msg: 'Left/right placeholder characters' @@ -728,7 +745,7 @@ ], remove: [] }, - { type: 'retain', length: 2 } + { type: 'retain', length: 7 } ] ], msg: 'List at end of paragraph (moves insertion point)' @@ -764,7 +781,7 @@ ], remove: [] }, - { type: 'retain', length: 5 } + { type: 'retain', length: 10 } ] ], msg: 'Table with caption into paragraph' @@ -786,7 +803,7 @@ insert: ve.dm.example.RDFa.slice( 0, 5 ), remove: [] }, - { type: 'retain', length: 9 } + { type: 'retain', length: 14 } ] ], msg: 'RDFa attributes restored/overwritten from data-ve-attributes' -- To view, visit https://gerrit.wikimedia.org/r/154407 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibfddaf94aaf7daedf05eec56821994f7f30ddd56 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits