Clickable inline images

Clicking an inline image will select it, or expand the selection.

Change-Id: I505665f2dac2e52140cc049e63e3355190dcbfec
This commit is contained in:
Christian Williams 2013-04-04 16:52:54 -07:00
parent 4c1934b19d
commit 23ac4b79bb
2 changed files with 23 additions and 5 deletions

View file

@ -59,8 +59,20 @@ ve.ce.MWImageNode.prototype.onUpdate = function () {
* @param {jQuery.Event} e Click event * @param {jQuery.Event} e Click event
*/ */
ve.ce.MWImageNode.prototype.onClick = function ( e ) { ve.ce.MWImageNode.prototype.onClick = function ( e ) {
e.preventDefault(); var range,
return false; 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 );
}; };
/** /**

View file

@ -43,10 +43,11 @@ ve.Range.newFromTranslatedRange = function ( range, distance ) {
* *
* @method * @method
* @param {Array} ranges Array of ve.Range objects (at least one) * @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 * @returns {ve.Range} Range that spans all of the given ranges
*/ */
ve.Range.newCoveringRange = function ( ranges ) { ve.Range.newCoveringRange = function ( ranges, backwards ) {
var minStart, maxEnd, i; var minStart, maxEnd, i, range;
if ( !ranges || ranges.length === 0 ) { if ( !ranges || ranges.length === 0 ) {
throw new Error( 'newCoveringRange() requires at least one range' ); throw new Error( 'newCoveringRange() requires at least one range' );
} }
@ -60,7 +61,12 @@ ve.Range.newCoveringRange = function ( ranges ) {
maxEnd = ranges[i].end; 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 */ /* Methods */