Inez has uploaded a new change for review.

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


Change subject: Removed ve.dm.Document.getIEStyleWordBoundary method. Added 
ve.ce.Document.getSiblingWordBoundary method.
......................................................................

Removed ve.dm.Document.getIEStyleWordBoundary method.
Added ve.ce.Document.getSiblingWordBoundary method.

Change-Id: I44b53273429aede5be10f39c2ee2f70d96cdc6fb
---
M modules/ve/ce/ve.ce.Document.js
M modules/ve/dm/ve.dm.Document.js
M modules/ve/test/dm/ve.dm.Document.test.js
3 files changed, 83 insertions(+), 215 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/54/55154/1

diff --git a/modules/ve/ce/ve.ce.Document.js b/modules/ve/ce/ve.ce.Document.js
index 703e296..610aa4c 100644
--- a/modules/ve/ce/ve.ce.Document.js
+++ b/modules/ve/ce/ve.ce.Document.js
@@ -53,3 +53,85 @@
        var node = this.getNodeFromOffset( offset );
        return node ? node.getSlugAtOffset( offset ) : null;
 };
+
+/**
+ * Configuration for getSiblingWordBoundary method.
+ */
+ve.ce.Document.static.siblingWordBoundaryConfig = {
+       'default' : {
+               'left' : {
+                       'boundary' : { 'text' : true, 'space' : true },
+                       'space' : { 'text' : true, 'boundary' : true }
+               },
+               'right' : {
+                       'boundary' : { 'text' : true, 'space' : true },
+                       'space' : { 'text' : true, 'boundary' : true }
+               }
+       },
+       'ie' : {
+               'left' : {
+                       'space' : { 'text' : true, 'boundary' : true }
+               },
+               'right' : {
+                       'text' : { 'space' : true },
+                       'boundary' : { 'space' : true }
+               }
+       }
+};
+
+/**
+ * Get the nearest word boundary.
+ *
+ * @method
+ * @param {number} offset Offset to start from
+ * @param {number} [direction] Direction to prefer matching offset in, -1 for 
left and 1 for right
+ * @returns {number} Nearest word boundary
+ */
+ve.ce.Document.prototype.getSiblingWordBoundary = function ( offset, direction 
) {
+       var config = ve.ce.Document.static.siblingWordBoundaryConfig,
+               pattern = ve.dm.SurfaceFragment.wordBoundaryPattern,
+               data = this.model.data,
+               i = direction > 0 ? offset : offset - 1,
+               inc = direction > 0 ? 1 : -1,
+               prevChar, nextChar, prevType, nextType;
+
+       config = $.browser.msie ? config.ie : config.default;
+       config = direction > 0 ? config.right : config.left;
+
+       if ( !data[i] || data[i].type !== undefined ) {
+               return -1;
+       } else {
+               prevChar = typeof data[i] === 'string' ? data[i] : data[i][0];
+               if ( !pattern.test( prevChar ) ) {
+                       prevType = 'text';
+               } else if ( prevChar !== ' ' ) {
+                       prevType = 'boundary';
+               } else {
+                       prevType = 'space';
+               }
+               i = i + inc;
+               do {
+                       if ( data[i].type !== undefined ) {
+                               break;
+                       } else {
+                               nextChar = typeof data[i] === 'string' ? 
data[i] : data[i][0];
+                               if ( !pattern.test( nextChar ) ) {
+                                       nextType = 'text';
+                               } else if ( nextChar !== ' ' ) {
+                                       nextType = 'boundary';
+                               } else {
+                                       nextType = 'space';
+                               }
+                               if ( prevType !== nextType ) {
+                                       if ( config[prevType] && nextType in 
config[prevType] ) {
+                                               prevType = nextType
+                                               continue;
+                                       } else {
+                                               break;
+                                       }
+                               }
+                       }
+               } while ( data[i += inc] );
+               return i + ( inc > 0 ? 0 : 1 );
+       }
+};
\ No newline at end of file
diff --git a/modules/ve/dm/ve.dm.Document.js b/modules/ve/dm/ve.dm.Document.js
index 94d7cca..8bce6a3 100644
--- a/modules/ve/dm/ve.dm.Document.js
+++ b/modules/ve/dm/ve.dm.Document.js
@@ -1086,124 +1086,6 @@
        }
 };
 
-ve.dm.Document.prototype.getIEStyleWordBoundary = function ( offset, direction 
) {
-       var firstChar, mode, i, currentChar,
-               pattern = ve.dm.SurfaceFragment.wordBoundaryPattern,
-               modes = {
-                       'STRUCTURAL' : 1,
-                       'TEXT' : 2,
-                       'BOUNDARY' : 3,
-                       'SPACE' : 4
-               };
-
-       if ( direction > 0 ) { // right
-               if ( this.data[offset].type !== undefined ) {
-                       mode = modes.STRUCTURAL;
-               } else {
-                       firstChar = typeof this.data[offset] === 'string' ? 
this.data[offset] : this.data[offset][0];
-                       if ( !pattern.test( firstChar ) ) {
-                               mode = modes.TEXT;
-                       } else if ( firstChar !== ' ' ) {
-                               mode = modes.BOUNDARY;
-                       } else {
-                               mode = modes.SPACE;
-                       }
-               }
-
-               i = offset + 1;
-
-               do {
-                       if ( !this.data[i] ) {
-                               break;
-                       } else if ( this.data[i].type === undefined ) {
-                               currentChar = typeof this.data[i] === 'string' 
? this.data[i] : this.data[i][0];
-                               if ( mode === modes.STRUCTURAL ) {
-                                       break;
-                               } else if ( mode === modes.SPACE ) {
-                                       if ( currentChar !== ' ' ) {
-                                               break;
-                                       }
-                               } else {
-                                       if ( mode === modes.TEXT ) {
-                                               if ( currentChar === ' ' ) {
-                                                       mode = modes.SPACE;
-                                               } else if ( pattern.test( 
currentChar ) ) {
-                                                       break;
-                                               }
-                                       } else if ( mode === modes.BOUNDARY ) {
-                                               if ( currentChar === ' ' ) {
-                                                       mode = modes.SPACE;
-                                               } else if ( !pattern.test( 
currentChar ) ) {
-                                                       break;
-                                               }
-                                       }
-                               }
-                       } else {
-                               if ( mode === modes.STRUCTURAL ) {
-                                       continue;
-                               }
-                               break;
-                       }
-               } while ( this.data[i += 1] );
-               return i;
-       }
-
-       if ( direction < 0 ) { // left
-               if ( this.data[offset-1].type !== undefined ) {
-                       mode = modes.STRUCTURAL;
-               } else {
-                       firstChar = typeof this.data[offset-1] === 'string' ? 
this.data[offset-1] : this.data[offset-1][0];
-                       if ( !pattern.test( firstChar ) ) {
-                               mode = modes.TEXT;
-                       } else if ( firstChar !== ' ' ) {
-                               mode = modes.BOUNDARY;
-                       } else {
-                               mode = modes.SPACE;
-                       }
-               }
-
-               i = offset - 1 - 1;
-
-               do {
-                       if ( !this.data[i] ) {
-                               break;
-                       } else if ( this.data[i].type === undefined ) {
-                               currentChar = typeof this.data[i] === 'string' 
? this.data[i] : this.data[i][0];
-                               if ( mode === modes.SPACE ) {
-                                       if ( currentChar === ' ' ) {
-                                               continue;
-                                       } else if ( !pattern.test( currentChar 
) ) {
-                                               mode = modes.TEXT;
-                                               continue;
-                                       } else {
-                                               mode = modes.BOUNDARY;
-                                               continue;
-                                       }
-                               }
-                               if ( mode === modes.TEXT ) {
-                                       if ( currentChar === ' ') {
-                                               break;
-                                       }
-                                       if ( pattern.test( currentChar ) ) {
-                                               break;
-                                       }
-                               }
-                               if ( mode === modes.BOUNDARY ) {
-                                       if ( currentChar === ' ') {
-                                               break;
-                                       }
-                                       if ( !pattern.test( currentChar ) ) {
-                                               break;
-                                       }
-                               }
-                       } else {
-                               break;
-                       }
-               } while ( this.data[i -= 1] );
-               return i + 1;
-       }
-};
-
 /**
  * Fix up data so it can safely be inserted into the document data at an 
offset.
  *
diff --git a/modules/ve/test/dm/ve.dm.Document.test.js 
b/modules/ve/test/dm/ve.dm.Document.test.js
index f10b72e..2859f52 100644
--- a/modules/ve/test/dm/ve.dm.Document.test.js
+++ b/modules/ve/test/dm/ve.dm.Document.test.js
@@ -1532,100 +1532,4 @@
                        cases[i].msg
                );
        }
-} );
-
-QUnit.test( 'getIEStyleWordBoundary', function ( assert ) {
-       var i, doc, cases = [
-               {
-                       'text': ' A',
-                       'direction': 1,
-                       'offset': 0,
-                       'expected': 1
-               },
-               {
-                       'text': '     A',
-                       'direction': 1,
-                       'offset': 0,
-                       'expected': 5
-               },
-               {
-                       'text': ' .',
-                       'direction': 1,
-                       'offset': 0,
-                       'expected': 1
-               },
-               {
-                       'text': '     .',
-                       'direction': 1,
-                       'offset': 0,
-                       'expected': 5
-               },
-               {
-                       'text': 'A.',
-                       'direction': 1,
-                       'offset': 0,
-                       'expected': 1
-               },
-               {
-                       'text': 'A .',
-                       'direction': 1,
-                       'offset': 0,
-                       'expected': 2
-               },
-               {
-                       'text': 'A  .',
-                       'direction': 1,
-                       'offset': 0,
-                       'expected': 3
-               },
-               {
-                       'text': '...  A',
-                       'direction': 1,
-                       'offset': 0,
-                       'expected': 5
-               },
-               {
-                       'text': 'A...   A',
-                       'direction': -1,
-                       'offset': 1,
-                       'expected': 0
-               },
-               {
-                       'text': 'A...   A',
-                       'direction': -1,
-                       'offset': 2,
-                       'expected': 1
-               },
-               {
-                       'text': 'A...   A',
-                       'direction': -1,
-                       'offset': 4,
-                       'expected': 1
-               },
-               {
-                       'text': 'A...   A',
-                       'direction': -1,
-                       'offset': 7,
-                       'expected': 1
-               },
-               {
-                       'text': 'A...   A',
-                       'direction': -1,
-                       'offset': 8,
-                       'expected': 7
-               },
-       ];
-       QUnit.expect( cases.length );
-
-       for ( i = 0; i < cases.length; i++ ) {
-               doc = new ve.dm.Document(
-                       [ { 'type' : 'paragraph' } ]
-                       .concat( cases[i].text.split( '' ) )
-                       .concat( { 'type' : '/paragraph' } )
-               );
-               assert.equal(
-                       doc.getIEStyleWordBoundary( cases[i].offset + 1, 
cases[i].direction ),
-                       cases[i].expected + 1
-               );
-       }
-} );
+} );
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I44b53273429aede5be10f39c2ee2f70d96cdc6fb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Inez <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Christian <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>

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

Reply via email to