Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/205618

Change subject: ve.ce.TextNode: Do "meaningful whitespace characters" first
......................................................................

ve.ce.TextNode: Do "meaningful whitespace characters" first

Prevents the space mucking stuff from interfering.

Change-Id: I46b245aea5b1a4c46a66a56fbc6686051656e112
---
M src/ce/nodes/ve.ce.TextNode.js
1 file changed, 10 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/18/205618/1

diff --git a/src/ce/nodes/ve.ce.TextNode.js b/src/ce/nodes/ve.ce.TextNode.js
index b9fff97..ba4a248 100644
--- a/src/ce/nodes/ve.ce.TextNode.js
+++ b/src/ce/nodes/ve.ce.TextNode.js
@@ -68,6 +68,14 @@
        }
 
        if ( !significantWhitespace ) {
+               for ( i = 0; i < data.length; i++ ) {
+                       chr = getChar( i, data );
+                       // Show meaningful whitespace characters
+                       if ( Object.prototype.hasOwnProperty.call( 
whitespaceHtmlChars, chr ) ) {
+                               setChar( whitespaceHtmlChars[chr], i, data );
+                       }
+               }
+
                // Replace spaces with &nbsp; where needed
                // \u00a0 == &#160; == &nbsp;
                if ( data.length > 0 ) {
@@ -83,20 +91,13 @@
                        }
                }
 
-               for ( i = 0; i < data.length; i++ ) {
-                       chr = getChar( i, data );
-
+               for ( i = 0; i < data.length - 1; i++ ) {
                        // Replace any sequence of 2+ spaces with an 
alternating pattern
                        // (space-nbsp-space-nbsp-...).
                        // The leading and trailing space, if present, have 
already been converted
                        // to nbsp, so we know that i is between 1 and 
data.length - 2.
-                       if ( chr === ' ' && getChar( i + 1, data ) === ' ' ) {
+                       if ( getChar( i, data ) === ' ' && getChar( i + 1, data 
) === ' ' ) {
                                setChar( '\u00a0', i + 1, data );
-                       }
-
-                       // Show meaningful whitespace characters
-                       if ( Object.prototype.hasOwnProperty.call( 
whitespaceHtmlChars, chr ) ) {
-                               setChar( whitespaceHtmlChars[chr], i, data );
                        }
                }
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I46b245aea5b1a4c46a66a56fbc6686051656e112
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to