Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | $document.unbind( '.ce-surfaceView' ); |
34 | 34 | $document.bind( { |
35 | 35 | 'keydown.ce-surfaceView': function( e ) { |
36 | | -// return _this.onKeyDown( e ); |
| 36 | + return _this.onKeyDown( e ); |
37 | 37 | } |
38 | 38 | } ); |
39 | 39 | }, |
— | — | @@ -104,13 +104,14 @@ |
105 | 105 | }; |
106 | 106 | |
107 | 107 | ve.es.Surface.prototype.onPaste = function( e ) { |
108 | | - var _this = this, |
109 | | - insertionPoint = _this.getSelection().start, |
110 | | - node = rangy.getSelection().anchorNode; |
| 108 | + var _this = this, |
| 109 | + insertionPoint = _this.getSelection().start, |
| 110 | + node = rangy.getSelection().anchorNode; |
111 | 111 | |
| 112 | +_this.stopPolling(); |
112 | 113 | $('#paste').html('').show().css( 'top', $(window).scrollTop() ).css(' left', $(window).scrollLeft() ).focus(); |
113 | 114 | |
114 | | - _this.stopPolling(); |
| 115 | + |
115 | 116 | |
116 | 117 | setTimeout( function() { |
117 | 118 | |
— | — | @@ -129,11 +130,12 @@ |
130 | 131 | |
131 | 132 | // re-render |
132 | 133 | _this.getLeafNode( node ).data( 'view' ).renderContent(); |
| 134 | + _this.poll.prevText = _this.poll.prevHash = _this.poll.prevOffset = _this.poll.node = null; |
133 | 135 | |
134 | 136 | // place cursor |
135 | | - _this.showCursorAt( insertionPoint + _this.clipboard[key].length ); |
| 137 | + //_this.showCursorAt( insertionPoint + _this.clipboard[key].length ); |
136 | 138 | |
137 | | - _this.startPolling(); |
| 139 | + //_this.startPolling(); |
138 | 140 | } else { |
139 | 141 | alert('i can only handle copy/paste from hybrid surface. sorry. :('); |
140 | 142 | } |
— | — | @@ -171,10 +173,12 @@ |
172 | 174 | ve.es.Surface.prototype.startPolling = function() { |
173 | 175 | if ( this.poll.interval === null ) { |
174 | 176 | var _this = this; |
| 177 | + setTimeout( function() { |
| 178 | + _this.pollContent(); |
| 179 | + }, 0); |
175 | 180 | this.poll.interval = setInterval( function() { |
176 | 181 | _this.pollContent(); |
177 | 182 | }, this.poll.frequency ); |
178 | | - this.pollContent(); |
179 | 183 | } |
180 | 184 | }; |
181 | 185 | |
— | — | @@ -231,7 +235,7 @@ |
232 | 236 | |
233 | 237 | if ( lengthDiff === offsetDiff && this.poll.prevText.substring( 0, this.poll.prevOffset ) === text.substring( 0, this.poll.prevOffset ) ) { |
234 | 238 | newData = text.substring( this.poll.prevOffset, localOffset ).split( '' ); |
235 | | - annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + this.poll.prevOffset - 1 ); |
| 239 | + annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + this.poll.prevOffset - 1, true ); |
236 | 240 | ve.dm.DocumentNode.addAnnotationsToData( newData, annotations ); |
237 | 241 | this.model.transact( this.documentView.model.prepareInsertion( |
238 | 242 | nodeOffset + 1 + this.poll.prevOffset, |
— | — | @@ -248,12 +252,12 @@ |
249 | 253 | while ( sameFromRight < l && this.poll.prevText[this.poll.prevText.length - 1 - sameFromRight] === text[text.length - 1 - sameFromRight] ) { |
250 | 254 | ++sameFromRight; |
251 | 255 | } |
| 256 | + annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft, true ); |
252 | 257 | this.model.transact( this.documentView.model.prepareRemoval( new ve.Range( |
253 | 258 | nodeOffset + 1 + sameFromLeft, |
254 | 259 | nodeOffset + 1 + this.poll.prevText.length - sameFromRight |
255 | 260 | ) ) ); |
256 | 261 | newData = text.substring( sameFromLeft, text.length - sameFromRight ).split( '' ); |
257 | | - annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft ); |
258 | 262 | ve.dm.DocumentNode.addAnnotationsToData( newData, annotations ); |
259 | 263 | this.model.transact( this.documentView.model.prepareInsertion( |
260 | 264 | nodeOffset + 1 + sameFromLeft, |
— | — | @@ -263,7 +267,15 @@ |
264 | 268 | this.poll.prevText = text; |
265 | 269 | } |
266 | 270 | if ( hash !== this.poll.prevHash ) { |
| 271 | + console.log("hash mismatch", text, hash); |
267 | 272 | // TODO: redisplay cursor in correct position (with setTimeout) |
| 273 | + /* |
| 274 | + this.stopPolling(); |
| 275 | + var _this = this; |
| 276 | + setTimeout(function() { |
| 277 | + _this.startPolling(); |
| 278 | + }, 500); |
| 279 | + */ |
268 | 280 | this.getLeafNode( this.poll.node ).data( 'view' ).renderContent(); |
269 | 281 | this.poll.prevHash = hash; |
270 | 282 | } |
— | — | @@ -271,6 +283,41 @@ |
272 | 284 | this.poll.prevOffset = localOffset; |
273 | 285 | }; |
274 | 286 | |
| 287 | +ve.es.Surface.prototype.onKeyDown = function( e ) { |
| 288 | + console.log("keyDown"); |
| 289 | + switch ( e.keyCode ) { |
| 290 | + // Left arrow |
| 291 | + case 37: |
| 292 | + var rangySel = rangy.getSelection(); |
| 293 | + if ( rangySel.anchorOffset === 0 ) { |
| 294 | + var globalOffset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, true ), |
| 295 | + node = this.documentView.getNodeFromOffset( globalOffset ), |
| 296 | + nodeOffset = surfaceView.documentView.getOffsetFromNode( node ); |
| 297 | + |
| 298 | + |
| 299 | + if ( nodeOffset + 1 === globalOffset ) { |
| 300 | + var newOffset = this.documentView.model.getRelativeContentOffset( globalOffset, -1 ); |
| 301 | + console.log('newOffset', newOffset); |
| 302 | + this.showCursorAt(newOffset); |
| 303 | + e.preventDefault(); |
| 304 | + //return false; |
| 305 | + } |
| 306 | + |
| 307 | + //debugger; |
| 308 | + |
| 309 | + |
| 310 | + |
| 311 | + } |
| 312 | + |
| 313 | + console.log( 'left' ); |
| 314 | + break; |
| 315 | + // Right arrow |
| 316 | + case 39: |
| 317 | + console.log( 'right' ); |
| 318 | + break; |
| 319 | + } |
| 320 | +}; |
| 321 | + |
275 | 322 | ve.es.Surface.prototype.getOffset = function( elem, offset, global ) { |
276 | 323 | var $leafNode = this.getLeafNode( elem ), |
277 | 324 | current = [$leafNode.contents(), 0], |
Index: trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js |
— | — | @@ -723,9 +723,13 @@ |
724 | 724 | * @param {Integer} offset Offset to get annotations for |
725 | 725 | * @returns {Object[]} A copy of all annotation objects offset is covered by |
726 | 726 | */ |
727 | | -ve.dm.DocumentNode.prototype.getAnnotationsFromOffset = function( offset ) { |
| 727 | +ve.dm.DocumentNode.prototype.getAnnotationsFromOffset = function( offset, byref ) { |
728 | 728 | if ( ve.isArray( this.data[offset] ) ) { |
729 | | - return ve.copyArray( this.data[offset].slice( 1 ) ); |
| 729 | + if ( byref === true ) { |
| 730 | + return this.data[offset].slice( 1 ); |
| 731 | + } else { |
| 732 | + return ve.copyArray( this.data[offset].slice( 1 ) ); |
| 733 | + } |
730 | 734 | } |
731 | 735 | return []; |
732 | 736 | }; |