Allow extension to activate in MDX files#759
Conversation
|
I don't speak Japanese nor Chinese, so those translations will need to be edited (they're currently English). |
|
I'm also unsure as to why the first test fails on the CI, I've run the tests locally to check if they still work + I've not modified anything specific to that function. |
No worries. We can rely on other users who would like to help 🤣.
Sometimes it fails because of "time-out". Many thanks! |
Lemmingh
left a comment
There was a problem hiding this comment.
| "when": "editorTextFocus && !editorReadonly", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.editing.toggleItalic", | ||
| "key": "ctrl+i", | ||
| "mac": "cmd+i", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown" | ||
| "when": "editorTextFocus && !editorReadonly", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.editing.toggleStrikethrough", | ||
| "key": "alt+s", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !isMac" | ||
| "when": "editorTextFocus && !editorReadonly && !isMac", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.editing.toggleHeadingUp", | ||
| "key": "ctrl+shift+]", | ||
| "mac": "ctrl+shift+]", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown" | ||
| "when": "editorTextFocus && !editorReadonly", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.editing.toggleHeadingDown", | ||
| "key": "ctrl+shift+[", | ||
| "mac": "ctrl+shift+[", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown" | ||
| "when": "editorTextFocus && !editorReadonly", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.editing.toggleMath", | ||
| "key": "ctrl+m", | ||
| "mac": "cmd+m", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown" | ||
| "when": "editorTextFocus && !editorReadonly", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onEnterKey", | ||
| "key": "enter", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress' && vim.mode != 'Replace' && vim.mode != 'EasyMotionMode' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'SurroundInputMode'" | ||
| "when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress' && vim.mode != 'Replace' && vim.mode != 'EasyMotionMode' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'SurroundInputMode'", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onCtrlEnterKey", | ||
| "key": "ctrl+enter", | ||
| "mac": "cmd+enter", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible" | ||
| "when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onShiftEnterKey", | ||
| "key": "shift+enter", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible" | ||
| "when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onTabKey", | ||
| "key": "tab", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions" | ||
| "when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onShiftTabKey", | ||
| "key": "shift+tab", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions" | ||
| "when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onBackspaceKey", | ||
| "key": "backspace", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress' && vim.mode != 'Replace' && vim.mode != 'EasyMotionMode' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'SurroundInputMode'" | ||
| "when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress' && vim.mode != 'Replace' && vim.mode != 'EasyMotionMode' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'SurroundInputMode'", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onMoveLineUp", | ||
| "key": "alt+up", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible" | ||
| "when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onMoveLineDown", | ||
| "key": "alt+down", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible" | ||
| "when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onCopyLineUp", | ||
| "key": "shift+alt+up", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible" | ||
| "when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onCopyLineDown", | ||
| "key": "shift+alt+down", | ||
| "when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible" | ||
| "when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onIndentLines", | ||
| "key": "ctrl+]", | ||
| "mac": "cmd+]", | ||
| "when": "editorTextFocus && editorLangId == markdown && !suggestWidgetVisible" | ||
| "when": "editorTextFocus && !suggestWidgetVisible", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.onOutdentLines", | ||
| "key": "ctrl+[", | ||
| "mac": "cmd+[", | ||
| "when": "editorTextFocus && editorLangId == markdown && !suggestWidgetVisible" | ||
| "when": "editorTextFocus && !suggestWidgetVisible", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.checkTaskList", | ||
| "key": "alt+c", | ||
| "when": "editorTextFocus && editorLangId == markdown" | ||
| "when": "editorTextFocus", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.togglePreview", | ||
| "key": "ctrl+shift+v", | ||
| "mac": "cmd+shift+v", | ||
| "when": "!terminalFocus" | ||
| "when": "!terminalFocus", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.togglePreviewToSide", | ||
| "key": "ctrl+k v", | ||
| "mac": "cmd+k v", | ||
| "when": "!terminalFocus" | ||
| "when": "!terminalFocus", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] | ||
| }, | ||
| { | ||
| "command": "markdown.extension.editing.paste", | ||
| "key": "ctrl+v", | ||
| "mac": "cmd+v", | ||
| "when": "editorTextFocus && editorLangId == markdown && editorHasSelection" | ||
| "when": "editorTextFocus && editorHasSelection", | ||
| "injectTo": ["text.html.markdown.jsx", "text.html.markdown"] |
There was a problem hiding this comment.
injectTo does not exist in keybindings:
- https://code.visualstudio.com/api/references/contribution-points#contributes.keybindings
- https://github.com/microsoft/vscode/blob/de68da88f9cf36a2e3d521bbaa3eb4654c1b2c52/src/vs/platform/extensions/common/extensions.ts#L46-L53
- Theoretically, injecting a key binding into a TM scope doesn't make sense.
Should revert.
| "text.html.markdown", | ||
| "text.html.markdown.jsx" | ||
| ] | ||
| }, | ||
| { | ||
| "scopeName": "markdown.math_inline", | ||
| "path": "./syntaxes/math_inline.markdown.tmLanguage.json", | ||
| "injectTo": [ | ||
| "text.html.markdown" | ||
| "text.html.markdown", | ||
| "text.html.markdown.jsx" |
There was a problem hiding this comment.
There seems to be nothing about LaTeX in JSX. Is it correct to inject them to text.html.markdown.jsx scope?
| "injectTo": [ | ||
| "text.html.markdown", | ||
| "text.html.markdown.jsx" | ||
| ] |
There was a problem hiding this comment.
I cannot understand this change.
{
"scopeName": "text.katex",
"path": "./syntaxes/katex.tmLanguage.json"
}was intended to simply import the TM grammar, because math_display.markdown.tmLanguage.json and math_inline.markdown.tmLanguage.json reference text.katex scope.
I think there should be no need to inject it into any scope.
|
|
||
| /** Scheme `File` or `Untitled` */ | ||
| export const mdDocSelector = [{ language: 'markdown', scheme: 'file' }, { language: 'markdown', scheme: 'untitled' }]; | ||
| export const mdDocSelector = [{ language: 'markdown', scheme: 'file' }, { language: 'markdown', scheme: 'untitled' }, { language: 'mdx', scheme: 'file' }, { language: 'mdx', scheme: 'file' }]; |
@Lemmingh Thanks for the important information! I thought embedded language support had been implemented 😅 (see microsoft/vscode#1751) so I didn't check. @thomaskoppelaar I have to revert this PR as this extension now activates in all documents (e.g. json). Probably we can have a better solution later. |
This reverts commit 10e0777.
Yeah. The universal solution doesn't exist yet. And I'm not optimistic about it, given the complexity of designing a universal way to declare matching pattern and algorithm, and related mechanisms. However, "hardcoded" embedded language support have been available for a long time. The VS Code team encourages extensions to adopt it with examples for both declarative and programmatic language features. Opinions from Matt Bierner: |
|
@Lemmingh thank you for the feedback and clarification! Like you said, I misunderstood the way |
Allows for the extension to work within MDX files.
Caveat: The "Print current page to HTML" command won't properly convert MDX into HTML; It will treat the document as markdown.