mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
Always apply inspected annotations to the right range
When you leave the inspector by changing the selection, we need to apply changes to the old selection. ve.ui.Inspector * Added initialSelection * Change getMatchingAnnotations to use a given fragment rather than generating it's own * Set initialSelection on open ve.ui.Context * Make hiding the context accept changes ve.ui.LinkInspector * Passing a fragment into getMatchingAnnotations now * Using fragment API instead of actions API to control the range of the fragment Change-Id: If6c8845285d87d0f144b15d50c38e192c797be59
This commit is contained in:
parent
a833691421
commit
05e39c1733
|
@ -76,7 +76,8 @@ ve.ui.LinkInspector.prototype.onLocationInputChange = function() {
|
|||
*/
|
||||
ve.ui.LinkInspector.prototype.onOpen = function () {
|
||||
var target = '',
|
||||
annotation = this.getMatchingAnnotations().get( 0 );
|
||||
fragment = this.context.getSurface().getModel().getFragment(),
|
||||
annotation = this.getMatchingAnnotations( fragment ).get( 0 );
|
||||
|
||||
if ( annotation ) {
|
||||
if ( annotation instanceof ve.dm.MWInternalLinkAnnotation ) {
|
||||
|
@ -106,9 +107,11 @@ ve.ui.LinkInspector.prototype.onOpen = function () {
|
|||
* @method
|
||||
*/
|
||||
ve.ui.LinkInspector.prototype.onClose = function ( accept ) {
|
||||
var target = this.$locationInput.val(),
|
||||
var i, len, annotations,
|
||||
target = this.$locationInput.val(),
|
||||
surface = this.context.getSurface(),
|
||||
selection = surface.getModel().getSelection();
|
||||
selection = surface.getModel().getSelection(),
|
||||
fragment = surface.getModel().getFragment( this.initialSelection );
|
||||
if ( accept && target && target !== this.initialTarget ) {
|
||||
if ( this.isNewAnnotation ) {
|
||||
// Go back to before we add an annotation in prepareSelection
|
||||
|
@ -117,10 +120,12 @@ ve.ui.LinkInspector.prototype.onClose = function ( accept ) {
|
|||
surface.execute( 'content', 'select', selection );
|
||||
} else {
|
||||
// Clear all existing annotations
|
||||
surface.execute( 'annotation', 'clearAll', this.constructor.static.typePattern );
|
||||
annotations = this.getMatchingAnnotations( fragment ).get();
|
||||
for ( i = 0, len = annotations.length; i < len; i++ ) {
|
||||
fragment.annotateContent( 'clear', annotations[i] );
|
||||
}
|
||||
// Apply the new annotation
|
||||
surface.execute( 'annotation', 'set', this.getAnnotationFromTarget( target ) );
|
||||
}
|
||||
fragment.annotateContent( 'set', this.getAnnotationFromTarget( target ) );
|
||||
}
|
||||
this.isNewAnnotation = false;
|
||||
this.context.getSurface().getView().getDocument().getDocumentNode().$.focus();
|
||||
|
@ -145,7 +150,7 @@ ve.ui.LinkInspector.prototype.reset = function () {
|
|||
*/
|
||||
ve.ui.LinkInspector.prototype.prepareSelection = function () {
|
||||
var fragment = this.context.getSurface().getModel().getFragment(),
|
||||
annotation = this.getMatchingAnnotations().get( 0 );
|
||||
annotation = this.getMatchingAnnotations( fragment ).get( 0 );
|
||||
if ( !annotation ) {
|
||||
// Create annotation from selection
|
||||
fragment = fragment.trimRange();
|
||||
|
|
|
@ -194,7 +194,7 @@ ve.ui.Context.prototype.show = function () {
|
|||
|
||||
ve.ui.Context.prototype.hide = function () {
|
||||
if ( this.inspector ) {
|
||||
this.closeInspector( false );
|
||||
this.closeInspector( true );
|
||||
this.$overlay.hide();
|
||||
}
|
||||
if ( this.menu ) {
|
||||
|
|
|
@ -20,6 +20,7 @@ ve.ui.Inspector = function VeUiInspector( context ) {
|
|||
// Properties
|
||||
this.context = context;
|
||||
this.disabled = false;
|
||||
this.initialSelection = null;
|
||||
this.frame = context.getFrame();
|
||||
this.$ = $( '<div class="ve-ui-inspector"></div>' );
|
||||
this.$form = this.frame.$$( '<form></form>' );
|
||||
|
@ -201,11 +202,11 @@ ve.ui.Inspector.prototype.prepareSelection = function () {
|
|||
* Gets a list of matching annotations in selection.
|
||||
*
|
||||
* @method
|
||||
* @param {ve.dm.SurfaceFragment} fragment Fragment to get matching annotations within
|
||||
* @returns {ve.AnnotationSet} Matching annotations
|
||||
*/
|
||||
ve.ui.Inspector.prototype.getMatchingAnnotations = function () {
|
||||
return this.context.getSurface().getModel().getFragment().getAnnotations()
|
||||
.getAnnotationsByName( this.constructor.static.typePattern );
|
||||
ve.ui.Inspector.prototype.getMatchingAnnotations = function ( fragment ) {
|
||||
return fragment.getAnnotations().getAnnotationsByName( this.constructor.static.typePattern );
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -216,6 +217,7 @@ ve.ui.Inspector.prototype.getMatchingAnnotations = function () {
|
|||
*/
|
||||
ve.ui.Inspector.prototype.open = function () {
|
||||
this.$.show();
|
||||
this.initialSelection = this.context.getSurface().getModel().getSelection();
|
||||
this.onOpen();
|
||||
this.emit( 'open' );
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue