r110903 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110902‎ | r110903 | r110904 >
Date:00:26, 8 February 2012
Author:inez
Status:deferred
Tags:
Comment:
Delete scanBoundaries method from Content, as it does not make sense anymore for content editable approach
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Content.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Content.js
@@ -1,28 +1,3 @@
2 -/**
3 - * Creates an ve.es.Content object.
4 - *
5 - * A content view flows text into a DOM element and provides methods to get information about the
6 - * rendered output. HTML serialized specifically for rendering into and editing surface.
7 - *
8 - * Rendering occurs automatically when content is modified, by responding to "update" events from
9 - * the model. Rendering is iterative and interruptable to reduce user feedback latency.
10 - *
11 - * TODO: Cleanup code and comments
12 - *
13 - * @class
14 - * @constructor
15 - * @param {jQuery} $container Element to render into
16 - * @param {ve.ModelNode} model Model to produce view for
17 - * @property {jQuery} $
18 - * @property {ve.ContentModel} model
19 - * @property {Array} boundaries
20 - * @property {Array} lines
21 - * @property {Integer} width
22 - * @property {RegExp} bondaryTest
23 - * @property {Object} widthCache
24 - * @property {Object} renderState
25 - * @property {Object} contentCache
26 - */
272 ve.es.Content = function( $container, model ) {
283 // Inheritance
294 ve.EventEmitter.call( this );
@@ -30,13 +5,6 @@
316 // Properties
327 this.$ = $container;
338 this.model = model;
34 - this.boundaries = [];
35 - this.lines = [];
36 - this.width = null;
37 - this.boundaryTest = /([ \-\t\r\n\f])/g;
38 - this.widthCache = {};
39 - this.renderState = {};
40 - this.contentCache = null;
419
4210 if ( model ) {
4311 // Events
@@ -44,9 +12,6 @@
4513 this.model.on( 'update', function( offset ) {
4614 _this.render( offset || 0 );
4715 } );
48 -
49 - // Initialization
50 - this.scanBoundaries();
5116 }
5217 };
5318
@@ -202,50 +167,6 @@
203168
204169 /* Methods */
205170
206 -/**
207 - * Updates the word boundary cache, which is used for word fitting.
208 - *
209 - * @method
210 - */
211 -ve.es.Content.prototype.scanBoundaries = function() {
212 - /*
213 - * Word boundary scan
214 - *
215 - * To perform binary-search on words, rather than characters, we need to collect word boundary
216 - * offsets into an array. The offset of the right side of the breaking character is stored, so
217 - * the gaps between stored offsets always include the breaking character at the end.
218 - *
219 - * To avoid encoding the same words as HTML over and over while fitting text to lines, we also
220 - * build a list of HTML escaped strings for each gap between the offsets stored in the
221 - * "boundaries" array. Slices of the "words" array can be joined, producing the escaped HTML of
222 - * the words.
223 - */
224 - // Get and cache a copy of all content, the make a plain-text version of the cached content
225 - var data = this.contentCache = this.model.getContentData(),
226 - text = '';
227 - for ( var i = 0, length = data.length; i < length; i++ ) {
228 - text += typeof data[i] === 'string' ? data[i] : data[i][0];
229 - }
230 - // Purge "boundaries" and "words" arrays
231 - this.boundaries = [0];
232 - // Reset RegExp object's state
233 - this.boundaryTest.lastIndex = 0;
234 - // Iterate over each word+boundary sequence, capturing offsets and encoding text as we go
235 - var match,
236 - end;
237 - while ( ( match = this.boundaryTest.exec( text ) ) ) {
238 - // Include the boundary character in the range
239 - end = match.index + 1;
240 - // Store the boundary offset
241 - this.boundaries.push( end );
242 - }
243 - // If the last character is not a boundary character, we need to append the final range to the
244 - // "boundaries" and "words" arrays
245 - if ( end < text.length || this.boundaries.length === 1 ) {
246 - this.boundaries.push( text.length );
247 - }
248 -};
249 -
250171 ve.es.Content.prototype.render = function( offset ) {
251172 this.$.html( this.getHtml( 0, this.model.getContentLength() ) );
252173 };
@@ -263,7 +184,7 @@
264185 } else {
265186 range = { 'start': 0, 'end': undefined };
266187 }
267 - var data = this.contentCache.slice( range.start, range.end ),
 188+ var data = this.model.getContentData(),
268189 render = ve.es.Content.renderAnnotation,
269190 htmlChars = ve.es.Content.htmlCharacters;
270191 var out = '',

Status & tagging log