- Added auto-link selection when opening the link editor without selecting any text

- Resolves bug #33049
This commit is contained in:
Trevor Parscal 2011-12-13 23:12:27 +00:00
parent 59ce5ee33a
commit fef6d5525e
3 changed files with 20 additions and 9 deletions

View file

@ -682,11 +682,11 @@ es.DocumentModel.prototype.getContentDataFromNode = function( node, range ) {
* @param {Object} annotation Annotation to test for coverage with
* @returns {es.Range|null} Range of content covered by annotation, or null if offset is not covered
*/
es.DocumentModel.prototype.getAnnotationBoundaries = function( offset, annotation ) {
es.DocumentModel.prototype.getAnnotationBoundaries = function( offset, annotation, typeOnly ) {
if ( annotation.hash === undefined ) {
annotation.hash = es.DocumentModel.getHash( annotation );
}
if ( es.DocumentModel.getIndexOfAnnotation( this.data[offset], annotation ) === -1 ) {
if ( es.DocumentModel.getIndexOfAnnotation( this.data[offset], annotation, typeOnly ) === -1 ) {
return null;
}
var start = offset,
@ -694,13 +694,13 @@ es.DocumentModel.prototype.getAnnotationBoundaries = function( offset, annotatio
item;
while ( start > 0 ) {
start--;
if ( es.DocumentModel.getIndexOfAnnotation( this.data[start], annotation ) === -1 ) {
if ( es.DocumentModel.getIndexOfAnnotation( this.data[start], annotation, typeOnly ) === -1 ) {
start++;
break;
}
}
while ( end < this.data.length ) {
if ( es.DocumentModel.getIndexOfAnnotation( this.data[end], annotation ) === -1 ) {
if ( es.DocumentModel.getIndexOfAnnotation( this.data[end], annotation, typeOnly ) === -1 ) {
break;
}
end++;

View file

@ -23,11 +23,14 @@ es.AnnotationButtonTool = function( toolbar, name, title, data ) {
es.AnnotationButtonTool.prototype.onClick = function() {
var surfaceView = this.toolbar.getSurfaceView();
if ( this.inspector ) {
if ( surfaceView.getModel().getSelection().getLength() ) {
this.toolbar.getSurfaceView().getContextView().openInspector( this.inspector );
} else {
if ( !this.active ) {
surfaceView.annotate( 'set', this.annotation );
if ( !surfaceView.getModel().getSelection().getLength() ) {
if ( this.active ) {
var surfaceModel = surfaceView.getModel(),
documentModel = surfaceModel.getDocument(),
selection = surfaceModel.getSelection(),
range = documentModel.getAnnotationBoundaries( selection.from, this.annotation, true );
surfaceModel.select( range );
this.toolbar.getSurfaceView().getContextView().openInspector( this.inspector );
}
}
} else {

View file

@ -626,6 +626,14 @@ es.SurfaceView.prototype.onKeyDown = function( e ) {
case 75:
if ( this.currentSelection.getLength() ) {
this.contextView.openInspector( 'link' );
} else {
var range = this.model.getDocument().getAnnotationBoundaries(
this.currentSelection.from, { 'type': 'link/internal' }, true
);
if ( range ) {
this.model.select( range );
this.contextView.openInspector( 'link' );
}
}
return false;
}