diff --git a/modules/ve/ce/ve.ce.Document.js b/modules/ve/ce/ve.ce.Document.js index ed918e9aed..79fd18a8d7 100644 --- a/modules/ve/ce/ve.ce.Document.js +++ b/modules/ve/ce/ve.ce.Document.js @@ -99,7 +99,7 @@ ve.ce.Document.prototype.getSiblingWordBoundary = function ( offset, direction ) config = direction > 0 ? config.right : config.left; if ( !data[i] || data[i].type !== undefined ) { - return -1; + return this.model.getRelativeContentOffset( offset, direction ); } else { prevChar = typeof data[i] === 'string' ? data[i] : data[i][0]; if ( !pattern.test( prevChar ) ) { @@ -134,4 +134,22 @@ ve.ce.Document.prototype.getSiblingWordBoundary = function ( offset, direction ) } while ( data[i += inc] ); return i + ( inc > 0 ? 0 : 1 ); } +}; + +/** + * Get the relative word or character 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 + * @param {string} [unit] Unit [word|character] + * @returns {number} Relative offset + */ +ve.ce.Document.prototype.getRelativeOffset = function ( offset, direction, unit ) { + if ( unit === 'word' ) { // word + return this.getSiblingWordBoundary( offset, direction ); + } else { // character + // TODO: add support for slugs + return this.model.getRelativeContentOffset( offset, direction ); + } }; \ No newline at end of file