r102613 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102612‎ | r102613 | r102614 >
Date:01:13, 10 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Support for selecting words and nodes with mouse
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -17,11 +17,8 @@
1818
1919 // Interaction state
2020 this.mouse = {
21 - selecting: false,
22 - timer: null,
23 - delta: 0,
24 - clickTime: 0,
25 - clickPosition: null
 21+ selectingMode: null,
 22+ selectedRange: null
2623 };
2724 this.cursor = {
2825 $: $( '<div class="es-surfaceView-cursor"></div>' ).appendTo( this.$ ),
@@ -110,11 +107,13 @@
111108 };
112109
113110 es.SurfaceView.prototype.onMouseDown = function( e ) {
114 - if ( e.button === 0 ) {
 111+ if ( e.button === 0 /* left mouse button */ ) {
115112 switch ( e.originalEvent.detail ) {
116113 case 1: // single click
117 - this.mouse.selecting = true;
 114+ this.mouse.selectingMode = 1;
 115+
118116 this.selection.to = this.documentView.getOffsetFromEvent( e );
 117+ console.log(this.selection.to);
119118 if ( this.keyboard.keys.shift ) {
120119 this.documentView.drawSelection( this.selection );
121120 this.hideCursor();
@@ -128,21 +127,26 @@
129128 }
130129 break;
131130 case 2: // double click
 131+ this.mouse.selectingMode = 2;
 132+
132133 this.selection = this.documentView.model.getWordBoundaries(
133134 this.documentView.getOffsetFromEvent( e )
134135 );
135136 this.documentView.drawSelection( this.selection );
136137 this.hideCursor();
 138+ this.mouse.selectedRange = new es.Range( this.selection.from, this.selection.to );
137139 break;
138 - break;
139140 default: // 3 and more
 141+ this.mouse.selectingMode = 3;
 142+
140143 var node = this.documentView.getNodeFromOffset(
141144 this.documentView.getOffsetFromEvent( e )
142145 );
143146 this.selection.from = this.documentView.getOffsetFromNode( node, false );
144147 this.selection.to = this.selection.from + node.getElementLength() - 1;
145148 this.documentView.drawSelection( this.selection );
146 - this.hideCursor();
 149+ this.hideCursor();
 150+ this.mouse.selectedRange = new es.Range( this.selection.from, this.selection.to );
147151 break;
148152 }
149153 }
@@ -154,18 +158,81 @@
155159 };
156160
157161 es.SurfaceView.prototype.onMouseMove = function( e ) {
158 - if ( e.button === 0 /* left mouse button */ && this.mouse.selecting ) {
159 - this.selection.to = this.documentView.getOffsetFromEvent( e );
 162+ if ( e.button === 0 /* left mouse button */ && this.mouse.selectingMode ) {
 163+ if ( this.mouse.selectingMode === 1 ) {
 164+ this.selection.to = this.documentView.getOffsetFromEvent( e );
 165+ } else if ( this.mouse.selectingMode === 2 ) {
 166+ var wordBoundaries = this.documentView.model.getWordBoundaries(
 167+ this.documentView.getOffsetFromEvent( e )
 168+ );
 169+ if ( wordBoundaries.to <= this.mouse.selectedRange.from ) {
 170+ this.selection.to = wordBoundaries.from;
 171+ this.selection.from = this.mouse.selectedRange.to;
 172+ } else {
 173+ this.selection.from = this.mouse.selectedRange.from;
 174+ this.selection.to = wordBoundaries.to;
 175+ }
 176+ } else if ( this.mouse.selectingMode === 3 ) {
 177+ var node = this.documentView.getNodeFromOffset(
 178+ this.documentView.getOffsetFromEvent( e )
 179+ );
 180+ var nodeBoundaries = new es.Range();
 181+ nodeBoundaries.from = this.documentView.getOffsetFromNode( node, false );
 182+ nodeBoundaries.to = nodeBoundaries.from + node.getElementLength() - 1;
 183+
 184+ if ( nodeBoundaries.to <= this.mouse.selectedRange.from ) {
 185+ this.selection.to = nodeBoundaries.from;
 186+ this.selection.from = this.mouse.selectedRange.to;
 187+ } else {
 188+ this.selection.from = this.mouse.selectedRange.from;
 189+ this.selection.to = nodeBoundaries.to;
 190+ }
 191+ }
160192 this.documentView.drawSelection( this.selection );
161193 if ( this.selection.getLength() ) {
162194 this.hideCursor();
 195+ }
 196+ }
 197+ return;
 198+
 199+ if ( e.button === 0 /* left mouse button */ && this.mouse.selected ) {
 200+
 201+ var offset = this.documentView.getOffsetFromEvent( e );
 202+ if ( this.mouse.selected.containsOffset( offset ) ) {
 203+ //return;
163204 }
 205+ var wordBoundaries = this.documentView.model.getWordBoundaries( offset );
 206+ if ( wordBoundaries.to <= this.mouse.selected.from ) {
 207+ this.selection.to = wordBoundaries.from;
 208+ this.selection.from = this.mouse.selected.to;
 209+ } else {
 210+ this.selection.from = this.mouse.selected.from;
 211+ this.selection.to = wordBoundaries.to;
 212+ }
 213+
 214+ /*
 215+ var to = this.documentView.getOffsetFromEvent( e );
 216+
 217+ if ( to <= this.mouse.selected.from ) {
 218+ this.selection.to = to;
 219+ this.selection.from = this.mouse.selected.to;
 220+ } else if ( to >= this.mouse.selected.to ) {
 221+ this.selection.from = this.mouse.selected.from;
 222+ this.selection.to = to;
 223+ }
 224+ */
 225+
 226+ this.documentView.drawSelection( this.selection );
 227+
 228+ } else if ( e.button === 0 /* left mouse button */ && this.mouse.selecting ) {
 229+ this.selection.to = this.documentView.getOffsetFromEvent( e );
 230+
164231 }
165232 };
166233
167234 es.SurfaceView.prototype.onMouseUp = function( e ) {
168235 if ( e.button === 0 /* left mouse button */ ) {
169 - this.mouse.selecting = false;
 236+ this.mouse.selectingMode = this.mouse.selectedRange = null;
170237 }
171238 };
172239

Status & tagging log