r110913 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110912‎ | r110913 | r110914 >
Date:06:28, 8 February 2012
Author:christian
Status:deferred
Tags:
Comment:
working on getSelection and getOffset for triple click
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js
@@ -19,7 +19,7 @@
2020 this.model = model;
2121 this.documentView = new ve.es.DocumentNode( this.model.getDocument(), this );
2222 this.contextView = null;
23 - this.paste = {};
 23+ this.clipboard = {};
2424 this.$ = $container
2525 .addClass( 'es-surfaceView' )
2626 .append( this.documentView.$ );
@@ -34,8 +34,10 @@
3535 .on('cut copy', function(event) {
3636 var key = rangy.getSelection().getRangeAt(0).toString().replace(/( |\r\n|\n|\r|\t)/gm,"");
3737
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+
4042 if (event.type == 'cut') {
4143 var selection = _this.getSelection();
4244
@@ -49,6 +51,7 @@
5052 })
5153 .on('beforepaste paste', function(event) {
5254 var insertionPoint = _this.getSelection().start;
 55+ console.log(_this.clipboard);
5356
5457 $('#paste').html('');
5558 $('#paste').focus();
@@ -56,10 +59,10 @@
5760 setTimeout(function() {
5861 var key = $('#paste').text().replace(/( |\r\n|\n|\r|\t)/gm,"");
5962
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]);
6265 _this.documentView.model.commit(tx);
63 - _this.showCursorAt(insertionPoint + _this.paste[key].length);
 66+ _this.showCursorAt(insertionPoint + _this.clipboard[key].length);
6467 } else {
6568 alert('i can only handle copy/paste from hybrid surface. sorry. :(');
6669 }
@@ -129,6 +132,13 @@
130133 if ( $( item ).attr('contentEditable') === "false" ) {
131134 offset += 1;
132135 } else {
 136+ console.log(item);
 137+ console.log(localNode);
 138+ if ( item === localNode ) {
 139+ offset += localOffset;
 140+ break;
 141+ }
 142+
133143 stack.push( [$item.contents(), 0] );
134144 current[1]++;
135145 current = stack[stack.length-1];
@@ -143,16 +153,19 @@
144154
145155 ve.es.Surface.prototype.getSelection = function() {
146156 var selection = rangy.getSelection();
147 -
 157+
148158 if ( selection.anchorNode === selection.focusNode && selection.anchorOffset === selection.focusOffset ) {
149159 // only one offset
150160 var offset = this.getOffset( selection.anchorNode, selection.anchorOffset );
151161 return new ve.Range( offset, offset );
152162 } else {
153 - // two offsets
 163+ // two offsets
154164 var offset1 = this.getOffset( selection.anchorNode, selection.anchorOffset );
155165 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 );
157170 }
158171 };
159172

Status & tagging log