r113674 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113673‎ | r113674 | r113675 >
Date:21:50, 12 March 2012
Author:rmoen
Status:deferred
Tags:
Comment:
port over select event listener, and updateSelection methods for setting and removing context icon, add getSelectionRect method for context icon position
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/ui/ve.ui.Context.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js
@@ -17,6 +17,7 @@
1818
1919 // Properties
2020 this.model = model;
 21+ this.currentSelection = new ve.Range();
2122 this.documentView = new ve.ce.DocumentNode( this.model.getDocument(), this );
2223 this.contextView = null;
2324 this.$ = $container
@@ -79,6 +80,18 @@
8081 'compositionStart': null,
8182 'compositionEnd': null
8283 };
 84+
 85+ this.model.on( 'select', function( selection ) {
 86+ // Keep a copy of the current selection on hand
 87+ _this.currentSelection = selection.clone();
 88+ // Respond to selection changes
 89+ _this.updateSelection();
 90+ if ( selection.getLength() ) {
 91+ _this.clearInsertionAnnotations();
 92+ } else {
 93+ _this.loadInsertionAnnotations();
 94+ }
 95+ } );
8396 };
8497
8598 /* Methods */
@@ -242,6 +255,31 @@
243256 return this.model;
244257 };
245258
 259+ve.ce.Surface.prototype.updateSelection = function( delay ) {
 260+ var _this = this;
 261+ function update() {
 262+ if ( _this.currentSelection.getLength() ) {
 263+ _this.clearInsertionAnnotations();
 264+ }
 265+ if ( _this.contextView ) {
 266+ if ( _this.currentSelection.getLength() ) {
 267+ _this.contextView.set();
 268+ } else {
 269+ _this.contextView.clear();
 270+ }
 271+ }
 272+ _this.updateSelectionTimeout = undefined;
 273+ }
 274+ if ( delay ) {
 275+ if ( this.updateSelectionTimeout !== undefined ) {
 276+ return;
 277+ }
 278+ this.updateSelectionTimeout = setTimeout( update, delay );
 279+ } else {
 280+ update();
 281+ }
 282+};
 283+
246284 ve.ce.Surface.prototype.documentOnFocus = function() {
247285 this.startPolling();
248286 };
@@ -517,6 +555,11 @@
518556 }
519557 };
520558
 559+ve.ce.Surface.prototype.getSelectionRect = function() {
 560+ var sel = rangy.getSelection();
 561+ return sel.getBoundingClientRect();
 562+};
 563+
521564 ve.ce.Surface.prototype.getDOMNodeAndOffset = function( offset ) {
522565 var $node = this.documentView.getNodeFromOffset( offset ).$,
523566 nodeOffset = this.documentView.getOffsetFromNode( $node.data('view') ) + 1,
@@ -579,6 +622,8 @@
580623 range.setStart( start.node, start.offset );
581624 range.setEnd( stop.node, stop.offset );
582625 sel.setSingleRange( range );
 626+ // Trigger select event
 627+ this.model.select( this.getSelectionRange() );
583628 };
584629
585630 ve.ce.Surface.prototype.getLeafNode = function( elem ) {
Index: trunk/extensions/VisualEditor/modules/ve/ui/ve.ui.Context.js
@@ -95,6 +95,9 @@
9696 var selection = this.surfaceView.getModel().getSelection(),
9797 offset;
9898 this.position = null;
 99+
 100+ console.log( this.surfaceView.getSelectionRect() );
 101+
99102 if ( selection.from < selection.to ) {
100103 var $lastRange = this.surfaceView.$.find( '.es-contentView-range:visible:last' );
101104 if ( $lastRange.length ) {

Status & tagging log