|
21 | 21 | *******************************************************************************/ |
22 | 22 | package org.eclipse.gef.dot.internal.ui.language.contentassist; |
23 | 23 |
|
| 24 | +import static org.eclipse.gef.dot.internal.language.dot.DotPackage.Literals.ATTRIBUTE__VALUE; |
| 25 | + |
24 | 26 | import java.lang.reflect.Field; |
25 | 27 | import java.lang.reflect.Modifier; |
26 | 28 | import java.util.ArrayList; |
|
69 | 71 | import org.eclipse.xtext.EcoreUtil2; |
70 | 72 | import org.eclipse.xtext.Keyword; |
71 | 73 | import org.eclipse.xtext.nodemodel.INode; |
| 74 | +import org.eclipse.xtext.nodemodel.util.NodeModelUtils; |
72 | 75 | import org.eclipse.xtext.ui.IImageHelper; |
73 | 76 | import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal; |
74 | 77 | import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal.IReplacementTextApplier; |
@@ -313,6 +316,28 @@ public void completeAttribute_Value(EObject model, Assignment assignment, |
313 | 316 | .setMatcher(new AttributeValueMatcher(context.getMatcher())) |
314 | 317 | .toContext(); |
315 | 318 |
|
| 319 | + /* |
| 320 | + * do not propose any attribute values if it is already properly |
| 321 | + * enclosed with double quotes and the cursor is located directly |
| 322 | + * after the closing quote |
| 323 | + */ |
| 324 | + ID attributeValue = attribute.getValue(); |
| 325 | + if (attributeValue != null) { |
| 326 | + String attributeValueText = attributeValue.toString(); |
| 327 | + int cursorPosition = context.getOffset(); |
| 328 | + |
| 329 | + int attributeValueEndOffset = NodeModelUtils |
| 330 | + .findNodesForFeature(attribute, ATTRIBUTE__VALUE).get(0) |
| 331 | + .getTotalEndOffset(); |
| 332 | + |
| 333 | + if (attributeValueText.startsWith("\"") //$NON-NLS-1$ |
| 334 | + && attributeValueText.endsWith("\"") //$NON-NLS-1$ |
| 335 | + && attributeValueText.length() > 1 |
| 336 | + && cursorPosition >= attributeValueEndOffset) { |
| 337 | + return; |
| 338 | + } |
| 339 | + } |
| 340 | + |
316 | 341 | switch (attributeContext) { |
317 | 342 | case EDGE: |
318 | 343 | switch (attributeName) { |
@@ -600,7 +625,9 @@ private void proposeAttributeValues(String subgrammarName, |
600 | 625 | } else { |
601 | 626 | text = text.substring(1, text.length() - 1); |
602 | 627 | } |
603 | | - offset++; |
| 628 | + if (context.getOffset() > offset) { |
| 629 | + offset++; |
| 630 | + } |
604 | 631 | } |
605 | 632 | } |
606 | 633 |
|
@@ -681,11 +708,22 @@ private void proposeHtmlLabelAttributeValues(Attribute attribute, |
681 | 708 | DotColorProposalProvider.globalColorScheme = DotAstHelper |
682 | 709 | .getColorSchemeAttributeValue(attribute); |
683 | 710 |
|
684 | | - if (attribute.getValue() != null |
685 | | - && attribute.getValue().getType() == Type.HTML_STRING) { |
686 | | - proposeAttributeValues( |
687 | | - DotActivator.ORG_ECLIPSE_GEF_DOT_INTERNAL_LANGUAGE_DOTHTMLLABEL, |
688 | | - context, acceptor); |
| 711 | + ID attributeValue = attribute.getValue(); |
| 712 | + if (attributeValue != null) { |
| 713 | + int cursorPosition = context.getOffset(); |
| 714 | + int attributeValueStartOffset = NodeModelUtils |
| 715 | + .findNodesForFeature(attribute, ATTRIBUTE__VALUE).get(0) |
| 716 | + .getOffset(); |
| 717 | + /* |
| 718 | + * do not propose the html-label values if the attribute value is |
| 719 | + * set, but the cursor is located before it |
| 720 | + */ |
| 721 | + if (cursorPosition > attributeValueStartOffset |
| 722 | + && attributeValue.getType() == Type.HTML_STRING) { |
| 723 | + proposeAttributeValues( |
| 724 | + DotActivator.ORG_ECLIPSE_GEF_DOT_INTERNAL_LANGUAGE_DOTHTMLLABEL, |
| 725 | + context, acceptor); |
| 726 | + } |
689 | 727 | } |
690 | 728 |
|
691 | 729 | // reset the state of the DotColorProposalProvider |
|
0 commit comments