diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/incompleteHighlighting/Server.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/incompleteHighlighting/Server.java index 195c2af24806..6b3a0a903ce8 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/incompleteHighlighting/Server.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/incompleteHighlighting/Server.java @@ -5,7 +5,7 @@ * use this file except in compliance with the License. You may obtain a copy of * the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/JavaWebReferenceTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/JavaWebReferenceTest.java index c572ae01347d..d69f37692bf9 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/JavaWebReferenceTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/JavaWebReferenceTest.java @@ -29,7 +29,7 @@ public class JavaWebReferenceTest extends LightJavaCodeInsightFixtureTestCase { public void testHighlighting() { getReferences("class Hi { String url=\"http://foo\"; }"); + (SystemInfoRt.isMac ? "⌘Click, ⌘B" : "Ctrl+Click, Ctrl+B") + ")\">http://foo\"; }"); myFixture.testHighlighting(true, true, true); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HyperlinkAnnotator.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HyperlinkAnnotator.java index 8b9dc3cf59db..f4212b16a4fd 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HyperlinkAnnotator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HyperlinkAnnotator.java @@ -169,7 +169,15 @@ public class HyperlinkAnnotator implements Annotator, DumbAware { Shortcut mouseShortcut = ContainerUtil.find(shortcuts, shortcut -> !shortcut.isKeyboard()); if (mouseShortcut != null) { shortcutText += KeymapUtil.getShortcutText(mouseShortcut); - return shortcutText.replace("Button1 ", ""); + shortcutText = shortcutText.replace("Button1 ", ""); + } + Shortcut keyboardShortcut = ContainerUtil.find(shortcuts, shortcut -> shortcut.isKeyboard()); + if (keyboardShortcut != null) { + if (!shortcutText.isEmpty()) shortcutText += ", "; + shortcutText += KeymapUtil.getShortcutText(keyboardShortcut); + } + if (!shortcutText.isEmpty()) { + return shortcutText; } return ""; } diff --git a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/actions/styling/BaseToggleStateAction.kt b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/actions/styling/BaseToggleStateAction.kt index 2e0c3c871832..511a6eba081e 100644 --- a/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/actions/styling/BaseToggleStateAction.kt +++ b/plugins/markdown/core/src/org/intellij/plugins/markdown/ui/actions/styling/BaseToggleStateAction.kt @@ -56,6 +56,10 @@ abstract class BaseToggleStateAction: ToggleAction(), DumbAware { event.presentation.isEnabled = false return false } + if (shouldIgnoreLinkElement(selectionElements)) { + event.presentation.isEnabled = false + return false + } val commonParents = selectionElements.map { (left, right) -> getCommonParentOfType(left, right, targetNodeType) } val hasMissingParents = commonParents.any { it == null } @@ -165,6 +169,11 @@ abstract class BaseToggleStateAction: ToggleAction(), DumbAware { targetNodeType != MarkdownElementTypes.CODE_SPAN && selectionElements.any { getCommonParentOfType(it.first, it.second, MarkdownElementTypes.CODE_SPAN) != null } + private fun shouldIgnoreLinkElement(selectionElements: Sequence>) = + selectionElements.any { (left, right) -> + elementsToIgnore.any { type -> getCommonParentOfType(left, right, type) != null } + } + companion object { private val elementsToIgnore = setOf( MarkdownElementTypes.LINK_DESTINATION, diff --git a/plugins/markdown/test/src/org/intellij/plugins/markdown/actions/MarkdownStylingActionsConsistencyTest.kt b/plugins/markdown/test/src/org/intellij/plugins/markdown/actions/MarkdownStylingActionsConsistencyTest.kt index 8cfe24935b1a..04d3917668f0 100644 --- a/plugins/markdown/test/src/org/intellij/plugins/markdown/actions/MarkdownStylingActionsConsistencyTest.kt +++ b/plugins/markdown/test/src/org/intellij/plugins/markdown/actions/MarkdownStylingActionsConsistencyTest.kt @@ -41,6 +41,42 @@ class MarkdownStylingActionsConsistencyTest { checkResultByText(content) } + fun `test enabled inside inline link text`() { + val content = """ + Click [JetBrains](https://jetbrains.com) here + """.trimIndent() + val applied = """ + Click [$wrapPrefixJetBrains$wrapSuffix](https://jetbrains.com) here + """.trimIndent() + configureFromFileText("some.md", content) + executeAction(actionId) + checkResultByText(applied) + executeAction(actionId) + checkResultByText(content) + } + + fun `test disabled inside inline link destination`() { + // language=Markdown + val content = """ + Click [text](https://example.com) here + """.trimIndent() + configureFromFileText("some.md", content) + val action = ActionManager.getInstance().getAction(actionId) + assertFalse(EditorTestUtil.checkActionIsEnabled(editor, action)) + checkResultByText(content) + } + + fun `test disabled inside autolink`() { + // language=Markdown + val content = """ + Visit mple.com> + """.trimIndent() + configureFromFileText("some.md", content) + val action = ActionManager.getInstance().getAction(actionId) + assertFalse(EditorTestUtil.checkActionIsEnabled(editor, action)) + checkResultByText(content) + } + fun `test whole line`() { // language=Markdown val content = """