Esanders has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/401751 )

Change subject: Convert single nbsp's to plain spaces on paste
......................................................................

Convert single nbsp's to plain spaces on paste

Change-Id: I88f015c14cde4ac5ae2b26424e64d2074bb350db
---
M src/dm/lineardata/ve.dm.ElementLinearData.js
M tests/dm/lineardata/ve.dm.ElementLinearData.test.js
2 files changed, 26 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/51/401751/1

diff --git a/src/dm/lineardata/ve.dm.ElementLinearData.js 
b/src/dm/lineardata/ve.dm.ElementLinearData.js
index 73ae828..f1f6c99 100644
--- a/src/dm/lineardata/ve.dm.ElementLinearData.js
+++ b/src/dm/lineardata/ve.dm.ElementLinearData.js
@@ -1324,6 +1324,23 @@
                                        }
                                }
                        }
+                       // Support: Chrome, Safari
+                       // Sometimes all spaces are replaced with NBSP by the 
browser, so replace those
+                       // which aren't adjacent to plain spaces. T183647
+                       if (
+                               this.getCharacterData( i ) === '\u00a0' &&
+                               // Get last open type from the stack
+                               
!ve.dm.nodeFactory.doesNodeHaveSignificantWhitespace( elementStack[ 
elementStack.length - 1 ].type )
+                       ) {
+                               if ( !( this.getCharacterData( i + 1 ) === ' ' 
|| this.getCharacterData( i - 1 ) === ' ' ) ) {
+                                       // Replace with a space
+                                       if ( typeof this.getData( i ) === 
'string' ) {
+                                               this.data[ i ] = ' ';
+                                       } else {
+                                               this.data[ i ][ 0 ] = ' ';
+                                       }
+                               }
+                       }
                }
                annotations = this.getAnnotationsFromOffset( i, true );
                if ( !annotations.isEmpty() ) {
diff --git a/tests/dm/lineardata/ve.dm.ElementLinearData.test.js 
b/tests/dm/lineardata/ve.dm.ElementLinearData.test.js
index 82289dc..0a96436 100644
--- a/tests/dm/lineardata/ve.dm.ElementLinearData.test.js
+++ b/tests/dm/lineardata/ve.dm.ElementLinearData.test.js
@@ -1694,7 +1694,7 @@
                                msg: 'Breaks split content branch nodes'
                        },
                        {
-                               html: '<p>Foo\nBar\n <b>Baz \nQuux</b></p>',
+                               html: '<p>Foo\nBar\n <b>Baz 
\nQu&nbsp;ux</b></p>',
                                data: [
                                        { type: 'paragraph' },
                                        'F', 'o', 'o', ' ', 'B', 'a', 'r', ' ',
@@ -1704,30 +1704,34 @@
                                        [ ' ', [ ve.dm.example.annIndex( 'b' ) 
] ],
                                        [ 'Q', [ ve.dm.example.annIndex( 'b' ) 
] ],
                                        [ 'u', [ ve.dm.example.annIndex( 'b' ) 
] ],
+                                       [ ' ', [ ve.dm.example.annIndex( 'b' ) 
] ],
                                        [ 'u', [ ve.dm.example.annIndex( 'b' ) 
] ],
                                        [ 'x', [ ve.dm.example.annIndex( 'b' ) 
] ],
                                        { type: '/paragraph' },
                                        { type: 'internalList' },
                                        { type: '/internalList' }
                                ],
-                               msg: 'Newline characters are stripped and 
replaced with spaces where necessary'
+                               msg: 'Newline characters and NBSPs are replaced 
with spaces and/or stripped where necessary'
                        },
                        {
-                               html: '<p>Foo\nBar\n </p><pre>Baz 
\nQuux<!--comment-->\nWhee</pre>',
+                               html: '<p>Foo\nBar\n </p><pre>Baz 
\nQu&nbsp;ux<!--comment-->\nWhee</pre><p>A&nbsp;&nbsp;B&nbsp;&nbsp;&nbsp;C</p>',
                                data: [
                                        { type: 'paragraph' },
                                        'F', 'o', 'o', ' ', 'B', 'a', 'r',
                                        { type: '/paragraph' },
                                        { type: 'preformatted' },
-                                       'B', 'a', 'z', ' ', '\n', 'Q', 'u', 
'u', 'x',
+                                       'B', 'a', 'z', ' ', '\n', 'Q', 'u', 
'\u00a0', 'u', 'x',
                                        { type: 'comment', attributes: { text: 
'comment' } },
                                        { type: '/comment' },
                                        '\n', 'W', 'h', 'e', 'e',
                                        { type: '/preformatted' },
+                                       { type: 'paragraph' },
+                                       'A', ' ', '\u00a0', 'B', ' ', '\u00a0', 
' ', 'C',
+                                       { type: '/paragraph' },
                                        { type: 'internalList' },
                                        { type: '/internalList' }
                                ],
-                               msg: 'Newline characters are not stripped when 
they are meaningful'
+                               msg: 'Newline characters and NBSPs are not 
stripped when they are meaningful'
                        },
                        {
                                html: '<p>Foo</p> \n\t <p>Bar</p>',

-- 
To view, visit https://gerrit.wikimedia.org/r/401751
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I88f015c14cde4ac5ae2b26424e64d2074bb350db
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

Reply via email to