mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Added getSelectionText method to link inspector so that the default
text for a link is the selected text. patchset 2 - add case for if data offset is an object, be sure it is a string prior to adding it. truncate to 255 chars. patchset 3 - actually add the patched file Change-Id: Ibddf942c2a0ba3412d93cf9730f74eb858025fad
This commit is contained in:
parent
5ac30a2f5f
commit
8bccdf9d78
|
@ -76,10 +76,28 @@ ve.ui.LinkInspector.prototype.getAnnotationFromSelection = function() {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: This should probably be somewhere else but I needed this here for now.
|
||||||
|
ve.ui.LinkInspector.prototype.getSelectionText = function() {
|
||||||
|
var surfaceView = this.context.getSurfaceView(),
|
||||||
|
surfaceModel = surfaceView.getModel(),
|
||||||
|
documentModel = surfaceModel.getDocument(),
|
||||||
|
data = documentModel.getData( surfaceModel.getSelection() ),
|
||||||
|
str = '',
|
||||||
|
max = Math.min( data.length, 255 );
|
||||||
|
for ( var i = 0; i < max; i++ ) {
|
||||||
|
if ( ve.isArray( data[i] ) ) {
|
||||||
|
str += data[i][0];
|
||||||
|
} else if( typeof data[i] === 'string') {
|
||||||
|
str += data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
};
|
||||||
|
|
||||||
ve.ui.LinkInspector.prototype.onOpen = function() {
|
ve.ui.LinkInspector.prototype.onOpen = function() {
|
||||||
var annotation = this.getAnnotationFromSelection();
|
var annotation = this.getAnnotationFromSelection();
|
||||||
if ( annotation === null ) {
|
if ( annotation === null ) {
|
||||||
this.$locationInput.val( '' );
|
this.$locationInput.val( this.getSelectionText() );
|
||||||
this.$clearButton.addClass( 'es-inspector-button-disabled' );
|
this.$clearButton.addClass( 'es-inspector-button-disabled' );
|
||||||
} else if ( annotation.type === 'link/wikiLink' ) {
|
} else if ( annotation.type === 'link/wikiLink' ) {
|
||||||
// Internal link
|
// Internal link
|
||||||
|
|
Loading…
Reference in a new issue