From 23ac4b79bb2312f461c054e9c7b43d0c61ea4f8f Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Thu, 4 Apr 2013 16:52:54 -0700 Subject: [PATCH] Clickable inline images Clicking an inline image will select it, or expand the selection. Change-Id: I505665f2dac2e52140cc049e63e3355190dcbfec --- modules/ve/ce/nodes/ve.ce.MWImageNode.js | 16 ++++++++++++++-- modules/ve/ve.Range.js | 12 +++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/modules/ve/ce/nodes/ve.ce.MWImageNode.js b/modules/ve/ce/nodes/ve.ce.MWImageNode.js index 701a88417c..71d44b55d9 100644 --- a/modules/ve/ce/nodes/ve.ce.MWImageNode.js +++ b/modules/ve/ce/nodes/ve.ce.MWImageNode.js @@ -59,8 +59,20 @@ ve.ce.MWImageNode.prototype.onUpdate = function () { * @param {jQuery.Event} e Click event */ ve.ce.MWImageNode.prototype.onClick = function ( e ) { - e.preventDefault(); - return false; + var range, + surfaceModel = this.getRoot().getSurface().getModel(), + selection = surfaceModel.getSelection(); + + range = new ve.Range( + this.model.getOffset(), + this.model.getOffset() + this.model.getOuterLength() + ); + + if ( e.shiftKey ) { + range = ve.Range.newCoveringRange( [ selection, range ], selection.from > range.from ); + } + + this.getRoot().getSurface().getModel().change( null, range ); }; /** diff --git a/modules/ve/ve.Range.js b/modules/ve/ve.Range.js index e6681de5a9..b9a5f16b8b 100644 --- a/modules/ve/ve.Range.js +++ b/modules/ve/ve.Range.js @@ -43,10 +43,11 @@ ve.Range.newFromTranslatedRange = function ( range, distance ) { * * @method * @param {Array} ranges Array of ve.Range objects (at least one) + * @param {boolean} backwards Return a backwards range * @returns {ve.Range} Range that spans all of the given ranges */ -ve.Range.newCoveringRange = function ( ranges ) { - var minStart, maxEnd, i; +ve.Range.newCoveringRange = function ( ranges, backwards ) { + var minStart, maxEnd, i, range; if ( !ranges || ranges.length === 0 ) { throw new Error( 'newCoveringRange() requires at least one range' ); } @@ -60,7 +61,12 @@ ve.Range.newCoveringRange = function ( ranges ) { maxEnd = ranges[i].end; } } - return new ve.Range( minStart, maxEnd ); + if ( backwards ) { + range = new ve.Range( maxEnd, minStart ); + } else { + range = new ve.Range( minStart, maxEnd ); + } + return range; }; /* Methods */