Skip to content

Commit 4dbb7e7

Browse files
authored
Merge pull request #241 from eccenca/bugfix/jDBCDatasetErrorsWhenUsingSourceQuery-CMEM-6432
Update mode highlighter to v6 (CMEM-6432)
2 parents 6c40687 + f4edd6a commit 4dbb7e7

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1313
### Fixed
1414

1515
- `MultiSelect`:
16-
- Old suggestions might be shown for a very short time when typing in a new search query.
16+
- Old suggestions might be shown for a very short time when typing in a new search query.
17+
- `CodeEditor`:
18+
- Broken highlighting for editor modes that leveraged adapted legacy modes.
1719

1820
## [24.0.0] - 2024-12-17
1921

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@
7676
"@codemirror/lang-json": "^6.0.1",
7777
"@codemirror/lang-markdown": "^6.3.1",
7878
"@codemirror/lang-xml": "^6.1.0",
79+
"@codemirror/lang-sql": "^6.8.0",
7980
"@codemirror/legacy-modes": "^6.4.2",
81+
"@codemirror/lang-yaml": "^6.1.2",
82+
"@codemirror/lang-javascript": "^6.2.2",
8083
"@mavrin/remark-typograf": "^2.2.0",
8184
"codemirror": "^6.0.1",
8285
"color": "^4.2.3",

src/extensions/codemirror/hooks/useCodemirrorModeExtension.hooks.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { defaultHighlightStyle, StreamLanguage, StreamParser, LanguageSupport } from "@codemirror/language";
2-
3-
//modes imports
4-
import { markdown } from "@codemirror/lang-markdown";
1+
//adapted v6 modes imports
2+
import { javascript } from "@codemirror/lang-javascript";
53
import { json } from "@codemirror/lang-json";
4+
import { markdown } from "@codemirror/lang-markdown";
5+
import { sql } from "@codemirror/lang-sql";
66
import { xml } from "@codemirror/lang-xml";
7-
import { javascript } from "@codemirror/legacy-modes/mode/javascript";
7+
import { yaml } from "@codemirror/lang-yaml";
8+
import { defaultHighlightStyle, LanguageSupport, StreamLanguage, StreamParser } from "@codemirror/language";
9+
//legacy mode imports
10+
import { jinja2 } from "@codemirror/legacy-modes/mode/jinja2";
11+
import { mathematica } from "@codemirror/legacy-modes/mode/mathematica";
12+
import { ntriples } from "@codemirror/legacy-modes/mode/ntriples";
813
import { python } from "@codemirror/legacy-modes/mode/python";
914
import { sparql } from "@codemirror/legacy-modes/mode/sparql";
10-
import { sql } from "@codemirror/legacy-modes/mode/sql";
1115
import { turtle } from "@codemirror/legacy-modes/mode/turtle";
12-
import { jinja2 } from "@codemirror/legacy-modes/mode/jinja2";
13-
import { yaml } from "@codemirror/legacy-modes/mode/yaml";
14-
import { ntriples } from "@codemirror/legacy-modes/mode/ntriples";
15-
import { mathematica } from "@codemirror/legacy-modes/mode/mathematica";
1616

1717
//adaptations
1818
import { adaptedSyntaxHighlighting } from "../tests/codemirrorTestHelper";
@@ -35,10 +35,19 @@ const supportedModes = {
3535
export const supportedCodeEditorModes = Object.keys(supportedModes) as Array<keyof typeof supportedModes>;
3636
export type SupportedCodeEditorModes = (typeof supportedCodeEditorModes)[number];
3737

38+
const v6AdaptedModes: ReadonlyMap<SupportedCodeEditorModes, boolean> = new Map([
39+
["json", true],
40+
["markdown", true],
41+
["xml", true],
42+
["sql", true],
43+
["yaml", true],
44+
["javascript", true],
45+
]);
46+
3847
export const useCodeMirrorModeExtension = (mode?: SupportedCodeEditorModes) => {
3948
return !mode
4049
? adaptedSyntaxHighlighting(defaultHighlightStyle)
41-
: ["json", "markdown", "xml"].includes(mode)
50+
: v6AdaptedModes.has(mode)
4251
? ((typeof supportedModes[mode] === "function" ? supportedModes[mode] : () => {}) as () => LanguageSupport)()
4352
: StreamLanguage?.define(supportedModes[mode] as StreamParser<unknown>);
4453
};

0 commit comments

Comments
 (0)