Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js |
— | — | @@ -22,6 +22,7 @@ |
23 | 23 | this.$ = $container |
24 | 24 | .addClass( 'es-surfaceView' ) |
25 | 25 | .append( this.documentView.$ ); |
| 26 | + this.insertionAnnotations = []; |
26 | 27 | this.emitUpdateTimeout = undefined; |
27 | 28 | this.clipboard = {}; |
28 | 29 | this.autoRender = false; |
— | — | @@ -100,6 +101,7 @@ |
101 | 102 | this.autoRender = true; |
102 | 103 | this.model.transact( tx ); |
103 | 104 | this.autoRender = false; |
| 105 | + //TODO: Redraw selection |
104 | 106 | |
105 | 107 | } else { |
106 | 108 | if ( method === 'set' ) { |
— | — | @@ -110,10 +112,47 @@ |
111 | 113 | } |
112 | 114 | }; |
113 | 115 | |
114 | | -ve.ce.Surface.prototype.renderDomNode = function ( node ) { |
115 | | - this.getLeafNode( node ).data( 'view' ).renderContent(); |
| 116 | +ve.ce.Surface.prototype.getAnnotations = function() { |
| 117 | + return this.getSelection().getLength() ? |
| 118 | + this.model.getDocument().getAnnotationsFromRange( this.getSelection() ) : |
| 119 | + { |
| 120 | + 'full': this.insertionAnnotations, |
| 121 | + 'partial': [], |
| 122 | + 'all': this.insertionAnnotations |
| 123 | + }; |
116 | 124 | }; |
117 | 125 | |
| 126 | +ve.ce.Surface.prototype.getInsertionAnnotations = function() { |
| 127 | + return this.insertionAnnotations; |
| 128 | +}; |
| 129 | + |
| 130 | +ve.ce.Surface.prototype.addInsertionAnnotation = function( annotation ) { |
| 131 | + this.insertionAnnotations.push( annotation ); |
| 132 | +}; |
| 133 | + |
| 134 | +ve.ce.Surface.prototype.loadInsertionAnnotations = function( annotation ) { |
| 135 | + this.insertionAnnotations = |
| 136 | + this.model.getDocument().getAnnotationsFromOffset( this.getSelection().to - 1 ); |
| 137 | + // Filter out annotations that aren't textStyles or links |
| 138 | + for ( var i = 0; i < this.insertionAnnotations.length; i++ ) { |
| 139 | + if ( !this.insertionAnnotations[i].type.match( /(textStyle\/|link\/)/ ) ) { |
| 140 | + this.insertionAnnotations.splice( i, 1 ); |
| 141 | + i--; |
| 142 | + } |
| 143 | + } |
| 144 | +}; |
| 145 | + |
| 146 | +ve.ce.Surface.prototype.removeInsertionAnnotation = function( annotation ) { |
| 147 | + var index = ve.dm.DocumentNode.getIndexOfAnnotation( this.insertionAnnotations, annotation ); |
| 148 | + if ( index !== -1 ) { |
| 149 | + this.insertionAnnotations.splice( index, 1 ); |
| 150 | + } |
| 151 | +}; |
| 152 | + |
| 153 | +ve.ce.Surface.prototype.clearInsertionAnnotations = function() { |
| 154 | + this.insertionAnnotations = []; |
| 155 | +}; |
| 156 | + |
118 | 157 | ve.ce.Surface.prototype.onCutCopy = function( e ) { |
119 | 158 | var _this = this, |
120 | 159 | sel = rangy.getSelection(), |