All files / src/ce/nodes ve.ce.TextNode.js

92.3% Statements 24/26
87.5% Branches 7/8
100% Functions 4/4
92% Lines 23/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82                              1x   2108x   2108x         1x       1x   1x     1x                 1x 2504x 2504x 2504x     6x         6x         6451x 1379x   5072x       2504x 2369x 6451x   6451x 6x         2504x         1x  
/*!
 * VisualEditor ContentEditable TextNode class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * ContentEditable text node.
 *
 * @class
 * @extends ve.ce.LeafNode
 * @constructor
 * @param {ve.dm.TextNode} model Model to observe
 * @param {Object} [config] Configuration options
 */
ve.ce.TextNode = function VeCeTextNode() {
	// Parent constructor
	ve.ce.TextNode.super.apply( this, arguments );
 
	this.$element = $( [] );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ce.TextNode, ve.ce.LeafNode );
 
/* Static Properties */
 
ve.ce.TextNode.static.name = 'text';
 
ve.ce.TextNode.static.splitOnEnter = true;
 
// Deprecated alias
ve.ce.TextNode.static.whitespaceHtmlCharacters = ve.visibleWhitespaceCharacters;
 
/* Methods */
 
/**
 * Get an HTML rendering of the text.
 *
 * @return {Array} Array of rendered HTML fragments with annotations
 */
ve.ce.TextNode.prototype.getAnnotatedHtml = function () {
	const data = this.model.getDocument().getDataFromNode( this.model ),
		whitespaceHtmlChars = ve.visibleWhitespaceCharacters,
		significantWhitespace = this.getModel().getParent().hasSignificantWhitespace();
 
	function setChar( chr, index ) {
		Iif ( Array.isArray( data[ index ] ) ) {
			// Don't modify the original array, clone it first
			data[ index ] = data[ index ].slice( 0 );
			data[ index ][ 0 ] = chr;
		} else {
			data[ index ] = chr;
		}
	}
 
	function getChar( index ) {
		if ( Array.isArray( data[ index ] ) ) {
			return data[ index ][ 0 ];
		} else {
			return data[ index ];
		}
	}
 
	if ( !significantWhitespace ) {
		for ( let i = 0; i < data.length; i++ ) {
			const char = getChar( i );
			// Show meaningful whitespace characters
			if ( Object.prototype.hasOwnProperty.call( whitespaceHtmlChars, char ) ) {
				setChar( whitespaceHtmlChars[ char ], i );
			}
		}
	}
 
	return data;
};
 
/* Registration */
 
ve.ce.nodeFactory.register( ve.ce.TextNode );