jenkins-bot has submitted this change and it was merged.
Change subject: Expand annotation beyond a word if it exists
......................................................................
Expand annotation beyond a word if it exists
For the annotation inspector, if we start before a word, the
selection expands to fit the word. However, we may also be inside
a bigger annotation already. In that case, we want to run another
test to find the bigger annotation and expand the selection to
cover it as well.
Bug: T86399
Change-Id: I94a468f42e087eb16c68ba80fe74164e7a4875ee
---
M src/ui/inspectors/ve.ui.AnnotationInspector.js
1 file changed, 21 insertions(+), 2 deletions(-)
Approvals:
Jforrester: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/ui/inspectors/ve.ui.AnnotationInspector.js
b/src/ui/inspectors/ve.ui.AnnotationInspector.js
index 3164d6d..d345e28 100644
--- a/src/ui/inspectors/ve.ui.AnnotationInspector.js
+++ b/src/ui/inspectors/ve.ui.AnnotationInspector.js
@@ -168,6 +168,8 @@
return ve.ui.AnnotationInspector.super.prototype.getSetupProcess.call(
this, data )
.next( function () {
var expandedFragment, trimmedFragment,
initialCoveringAnnotation,
+ inspector = this,
+ annotationSet, annotations,
fragment = this.getFragment(),
surfaceModel = fragment.getSurface(),
annotation = this.getMatchingAnnotations(
fragment, true ).get( 0 );
@@ -183,19 +185,36 @@
// Expand to nearest word
expandedFragment =
fragment.expandLinearSelection( 'word' );
fragment = expandedFragment;
+
+ // TODO: We should review how
getMatchingAnnotation works in light of the fact
+ // that in the case of a collapsed
range, the method falls back to retrieving
+ // insertion annotations.
+
+ // Check if we're inside a relevant
annotation and if so, define it
+ annotationSet =
fragment.document.data.getAnnotationsFromRange( fragment.selection.range );
+ annotations = annotationSet.filter(
function ( existingAnnotation ) {
+ return ve.isInstanceOfAny(
existingAnnotation, inspector.constructor.static.modelClasses );
+ } );
+ if ( annotations.getLength() > 0 ) {
+ // We're in the middle of an
annotation, let's make sure we expand
+ // our selection to include the
entire existing annotation
+ annotation = annotations.get( 0
);
+ }
} else {
// Trim whitespace
trimmedFragment =
fragment.trimLinearSelection();
fragment = trimmedFragment;
}
- if ( !fragment.getSelection().isCollapsed() ) {
+
+ if ( !fragment.getSelection().isCollapsed() &&
!annotation ) {
// Create annotation from selection
annotation =
this.getAnnotationFromFragment( fragment );
if ( annotation ) {
fragment.annotateContent(
'set', annotation );
}
}
- } else {
+ }
+ if ( annotation ) {
// Expand range to cover annotation
expandedFragment =
fragment.expandLinearSelection( 'annotation', annotation );
fragment = expandedFragment;
--
To view, visit https://gerrit.wikimedia.org/r/197425
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I94a468f42e087eb16c68ba80fe74164e7a4875ee
Gerrit-PatchSet: 6
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits