From 7d476d3d59449e6a0a7dd2cd9c2b081cece6d1d3 Mon Sep 17 00:00:00 2001 From: Jozef Tomek Date: Sat, 8 Jun 2024 02:32:51 +0200 Subject: [PATCH] Fix styling enhancements menu not always reflecting Javadoc content - incorrect text was searched for inside HTML content to see if enhancements are present - menu actions for enhancements enabled state were not set / left only when enhancements were present in content Fixes #1442 --- .../JavaElementLabelComposerCore.java | 4 +-- .../ui/viewsupport/JavaElementLinks.java | 28 ++++++++++++------- .../SignatureStylingMenuToolbarAction.java | 6 ++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/JavaElementLabelComposerCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/JavaElementLabelComposerCore.java index f5c72d8700c..352957340d4 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/JavaElementLabelComposerCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/JavaElementLabelComposerCore.java @@ -904,7 +904,7 @@ protected void appendTypeParameterSignaturesLabel(String[] typeParamSigs, long f if (i > 0) { fBuffer.append(JavaElementLabelsCore.COMMA_STRING); } - appendTypeParameteSignatureLabel(Signature.getTypeVariable(typeParamSigs[i])); + appendTypeParameterSignatureLabel(Signature.getTypeVariable(typeParamSigs[i])); } appendGT(); } @@ -915,7 +915,7 @@ protected void appendTypeParameterSignaturesLabel(String[] typeParamSigs, long f * * @param typeVariableName the type variable name */ - protected void appendTypeParameteSignatureLabel(String typeVariableName) { + protected void appendTypeParameterSignatureLabel(String typeVariableName) { fBuffer.append(typeVariableName); } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java index 69499fd5ffd..c00c1a71d49 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/JavaElementLinks.java @@ -71,10 +71,10 @@ */ public class JavaElementLinks { - /** - * ID of the checkbox in generated HTML content that toggles formatting inside element labels. - */ - public static final String CHECKBOX_ID_FORMATTIG= "formattingSwitch"; //$NON-NLS-1$ + private static final String CHECKBOX_FORMATTING_ID = "formattingSwitch"; //$NON-NLS-1$ + // browser on windows changes single quotes to double quotes (other platforms don't do that) thus we use / primarily search for this one + private static final String CHECKBOX_FORMATTING_ID_ATTR_DQUOTES= "id=\"" + CHECKBOX_FORMATTING_ID + "\""; //$NON-NLS-1$ //$NON-NLS-2$ + private static final String CHECKBOX_FORMATTING_ID_ATTR_SQUOTES= "id='" + CHECKBOX_FORMATTING_ID + "'"; //$NON-NLS-1$ //$NON-NLS-2$ private static final String PREFERENCE_KEY_POSTFIX_TYPE_PARAMETERS_REFERENCES_COLORING= "javadocElementsStyling.typeParamsReferencesColoring"; //$NON-NLS-1$ @@ -339,7 +339,7 @@ public void appendElementLabel(IJavaElement element, long flags) { appendHoverParent= false; // formatting checkbox - fBuffer.append(" contentAccessor) { return; } var content= contentAccessor.get(); - if (content != null && !content.isBlank() && content.contains(JavaElementLinks.CHECKBOX_ID_FORMATTIG)) { + if (content != null && !content.isBlank() && JavaElementLinks.isStylingPresent(content)) { reAddActionItems(enabledActions); } else { reAddActionItems(noStylingActions); @@ -141,6 +141,8 @@ public void stylingStateChanged(boolean isEnabled) { parent.getDisplay().execute(() -> { enhancementsEnabled= isEnabled; presentEnhancementsState(); + // even if enhancements switched from off to on, only browserContentChanged() sets enabledActions + reAddActionItems(noStylingActions); runEnhancementsReconfiguredTask(); }); }