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:
Rob Moen 2012-06-20 19:43:46 -07:00 committed by Trevor Parscal
parent 5ac30a2f5f
commit 8bccdf9d78

View file

@ -76,10 +76,28 @@ ve.ui.LinkInspector.prototype.getAnnotationFromSelection = function() {
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() {
var annotation = this.getAnnotationFromSelection();
if ( annotation === null ) {
this.$locationInput.val( '' );
this.$locationInput.val( this.getSelectionText() );
this.$clearButton.addClass( 'es-inspector-button-disabled' );
} else if ( annotation.type === 'link/wikiLink' ) {
// Internal link