mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 16:20:52 +00:00
- Added auto-link selection when opening the link editor without selecting any text
- Resolves bug #33049
This commit is contained in:
parent
59ce5ee33a
commit
fef6d5525e
|
@ -682,11 +682,11 @@ es.DocumentModel.prototype.getContentDataFromNode = function( node, range ) {
|
||||||
* @param {Object} annotation Annotation to test for coverage with
|
* @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
|
* @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 ) {
|
if ( annotation.hash === undefined ) {
|
||||||
annotation.hash = es.DocumentModel.getHash( annotation );
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
var start = offset,
|
var start = offset,
|
||||||
|
@ -694,13 +694,13 @@ es.DocumentModel.prototype.getAnnotationBoundaries = function( offset, annotatio
|
||||||
item;
|
item;
|
||||||
while ( start > 0 ) {
|
while ( start > 0 ) {
|
||||||
start--;
|
start--;
|
||||||
if ( es.DocumentModel.getIndexOfAnnotation( this.data[start], annotation ) === -1 ) {
|
if ( es.DocumentModel.getIndexOfAnnotation( this.data[start], annotation, typeOnly ) === -1 ) {
|
||||||
start++;
|
start++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while ( end < this.data.length ) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
end++;
|
end++;
|
||||||
|
|
|
@ -23,11 +23,14 @@ es.AnnotationButtonTool = function( toolbar, name, title, data ) {
|
||||||
es.AnnotationButtonTool.prototype.onClick = function() {
|
es.AnnotationButtonTool.prototype.onClick = function() {
|
||||||
var surfaceView = this.toolbar.getSurfaceView();
|
var surfaceView = this.toolbar.getSurfaceView();
|
||||||
if ( this.inspector ) {
|
if ( this.inspector ) {
|
||||||
if ( surfaceView.getModel().getSelection().getLength() ) {
|
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 );
|
this.toolbar.getSurfaceView().getContextView().openInspector( this.inspector );
|
||||||
} else {
|
|
||||||
if ( !this.active ) {
|
|
||||||
surfaceView.annotate( 'set', this.annotation );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -626,6 +626,14 @@ es.SurfaceView.prototype.onKeyDown = function( e ) {
|
||||||
case 75:
|
case 75:
|
||||||
if ( this.currentSelection.getLength() ) {
|
if ( this.currentSelection.getLength() ) {
|
||||||
this.contextView.openInspector( 'link' );
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue