Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | this.model = model; |
21 | 21 | this.documentView = new ve.es.DocumentNode( this.model.getDocument(), this ); |
22 | 22 | this.contextView = null; |
23 | | - this.paste = {}; |
| 23 | + this.clipboard = {}; |
24 | 24 | this.$ = $container |
25 | 25 | .addClass( 'es-surfaceView' ) |
26 | 26 | .append( this.documentView.$ ); |
— | — | @@ -34,8 +34,10 @@ |
35 | 35 | .on('cut copy', function(event) { |
36 | 36 | var key = rangy.getSelection().getRangeAt(0).toString().replace(/( |\r\n|\n|\r|\t)/gm,""); |
37 | 37 | |
38 | | - _this.paste[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelection() ) ); |
39 | | - |
| 38 | + _this.clipboard[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelection() ) ); |
| 39 | + |
| 40 | + console.log(_this.clipboard); |
| 41 | + |
40 | 42 | if (event.type == 'cut') { |
41 | 43 | var selection = _this.getSelection(); |
42 | 44 | |
— | — | @@ -49,6 +51,7 @@ |
50 | 52 | }) |
51 | 53 | .on('beforepaste paste', function(event) { |
52 | 54 | var insertionPoint = _this.getSelection().start; |
| 55 | + console.log(_this.clipboard); |
53 | 56 | |
54 | 57 | $('#paste').html(''); |
55 | 58 | $('#paste').focus(); |
— | — | @@ -56,10 +59,10 @@ |
57 | 60 | setTimeout(function() { |
58 | 61 | var key = $('#paste').text().replace(/( |\r\n|\n|\r|\t)/gm,""); |
59 | 62 | |
60 | | - if (_this.paste[key]) { |
61 | | - var tx = _this.documentView.model.prepareInsertion( insertionPoint, _this.paste[key]); |
| 63 | + if (_this.clipboard[key]) { |
| 64 | + var tx = _this.documentView.model.prepareInsertion( insertionPoint, _this.clipboard[key]); |
62 | 65 | _this.documentView.model.commit(tx); |
63 | | - _this.showCursorAt(insertionPoint + _this.paste[key].length); |
| 66 | + _this.showCursorAt(insertionPoint + _this.clipboard[key].length); |
64 | 67 | } else { |
65 | 68 | alert('i can only handle copy/paste from hybrid surface. sorry. :('); |
66 | 69 | } |
— | — | @@ -129,6 +132,13 @@ |
130 | 133 | if ( $( item ).attr('contentEditable') === "false" ) { |
131 | 134 | offset += 1; |
132 | 135 | } else { |
| 136 | + console.log(item); |
| 137 | + console.log(localNode); |
| 138 | + if ( item === localNode ) { |
| 139 | + offset += localOffset; |
| 140 | + break; |
| 141 | + } |
| 142 | + |
133 | 143 | stack.push( [$item.contents(), 0] ); |
134 | 144 | current[1]++; |
135 | 145 | current = stack[stack.length-1]; |
— | — | @@ -143,16 +153,19 @@ |
144 | 154 | |
145 | 155 | ve.es.Surface.prototype.getSelection = function() { |
146 | 156 | var selection = rangy.getSelection(); |
147 | | - |
| 157 | + |
148 | 158 | if ( selection.anchorNode === selection.focusNode && selection.anchorOffset === selection.focusOffset ) { |
149 | 159 | // only one offset |
150 | 160 | var offset = this.getOffset( selection.anchorNode, selection.anchorOffset ); |
151 | 161 | return new ve.Range( offset, offset ); |
152 | 162 | } else { |
153 | | - // two offsets |
| 163 | + // two offsets |
154 | 164 | var offset1 = this.getOffset( selection.anchorNode, selection.anchorOffset ); |
155 | 165 | var offset2 = this.getOffset( selection.focusNode, selection.focusOffset ); |
156 | | - return new ve.Range( offset1, offset2 ); |
| 166 | + |
| 167 | + var blah = this.model.getDocument().getRelativeContentOffset( offset2, -1 ); |
| 168 | + |
| 169 | + return new ve.Range( offset1, blah ); |
157 | 170 | } |
158 | 171 | }; |
159 | 172 | |