diff --git a/package-lock.json b/package-lock.json index bb85c1f458..b88bfa1bd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13040,7 +13040,6 @@ "@fluent/langneg": "^0.7.0", "@fluent/react": "^0.15.1", "@fluent/syntax": "^0.19.0", - "@lezer/highlight": "^1.1.6", "@messageformat/fluent": "^0.4.1", "@reduxjs/toolkit": "^1.6.1", "classnames": "^2.3.1", diff --git a/translate/package.json b/translate/package.json index 426127c0ad..5e565a8aec 100644 --- a/translate/package.json +++ b/translate/package.json @@ -11,7 +11,6 @@ "@fluent/langneg": "^0.7.0", "@fluent/react": "^0.15.1", "@fluent/syntax": "^0.19.0", - "@lezer/highlight": "^1.1.6", "@messageformat/fluent": "^0.4.1", "@reduxjs/toolkit": "^1.6.1", "classnames": "^2.3.1", diff --git a/translate/src/modules/translationform/components/EditField.tsx b/translate/src/modules/translationform/components/EditField.tsx index 77ee844c0b..56a3c3fe66 100644 --- a/translate/src/modules/translationform/components/EditField.tsx +++ b/translate/src/modules/translationform/components/EditField.tsx @@ -17,7 +17,6 @@ import { Locale } from '~/context/Locale'; import { useReadonlyEditor } from '~/hooks/useReadonlyEditor'; import { getExtensions, useKeyHandlers } from '../utils/editFieldExtensions'; -import { EntityView } from '~/context/EntityView'; export type EditFieldProps = { index: number; @@ -39,14 +38,13 @@ export const EditField = memo( const { l10n } = useLocalization(); const locale = useContext(Locale); const readOnly = useReadonlyEditor(); - const { entity } = useContext(EntityView); const { setResultFromInput } = useContext(EditorActions); const keyHandlers = useKeyHandlers(); const [view, setView] = useState(null); const initView = useCallback((parent: HTMLDivElement | null) => { if (parent) { - const extensions = getExtensions(entity.format, keyHandlers); + const extensions = getExtensions(keyHandlers); if (readOnly) { extensions.push( EditorState.readOnly.of(true), diff --git a/translate/src/modules/translationform/utils/editFieldExtensions.ts b/translate/src/modules/translationform/utils/editFieldExtensions.ts index 6ddb2d07ff..478c9688da 100644 --- a/translate/src/modules/translationform/utils/editFieldExtensions.ts +++ b/translate/src/modules/translationform/utils/editFieldExtensions.ts @@ -5,12 +5,7 @@ import { insertNewlineAndIndent, standardKeymap, } from '@codemirror/commands'; -import { - HighlightStyle, - StreamLanguage, - bracketMatching, - syntaxHighlighting, -} from '@codemirror/language'; +import { bracketMatching } from '@codemirror/language'; import { Extension } from '@codemirror/state'; import { EditorView, keymap } from '@codemirror/view'; import { useContext, useEffect, useRef } from 'react'; @@ -22,8 +17,6 @@ import { useHandleEnter, useHandleEscape, } from './editFieldShortcuts'; -import { fluentMode, commonMode } from './editFieldModes'; -import { tags } from '@lezer/highlight'; /** * Key handlers depend on application state, @@ -57,23 +50,13 @@ export function useKeyHandlers() { return ref; } -const style = HighlightStyle.define([ - { tag: tags.keyword, color: '#872bff', fontFamily: 'monospace' }, // printf - { tag: tags.tagName, color: '#3e9682', fontFamily: 'monospace' }, // <...> - { tag: tags.brace, color: '#872bff', fontWeight: 'bold' }, // {...} - { tag: tags.name, color: '#872bff' }, // {...} -]); - export const getExtensions = ( - format: string, ref: ReturnType, ): Extension[] => [ history(), bracketMatching(), closeBrackets(), EditorView.lineWrapping, - StreamLanguage.define(format === 'ftl' ? fluentMode : commonMode), - syntaxHighlighting(style), keymap.of([ { key: 'Enter', diff --git a/translate/src/modules/translationform/utils/editFieldModes.ts b/translate/src/modules/translationform/utils/editFieldModes.ts deleted file mode 100644 index 8c4dffed7e..0000000000 --- a/translate/src/modules/translationform/utils/editFieldModes.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { StreamParser } from '@codemirror/language'; - -export const fluentMode: StreamParser<{ expression: boolean; tag: boolean }> = { - name: 'fluent', - startState: () => ({ expression: false, tag: false }), - token(stream, state) { - const ch = stream.next(); - if (state.expression) { - if (ch === '}') { - state.expression = false; - return 'brace'; - } - stream.skipTo('}'); - return 'name'; - } else { - if (ch === '{') { - state.expression = true; - return 'brace'; - } - if (ch === '<') { - state.tag = true; - } - if (state.tag) { - if (ch === '>') { - state.tag = false; - } else { - stream.eatWhile(/[^>{]+/); - } - return 'tagName'; - } - stream.eatWhile(/[^<{]+/); - return 'string'; - } - }, -}; - -const printf = - /^%(\d\$|\(.*?\))?[-+ 0'#]*[\d*]*(\.[\d*])?(hh?|ll?|[jLtz])?[%@AacdEeFfGginopSsuXx]/; - -const pythonFormat = /^{[\w.[\]]*(![rsa])?(:.*?)?}/; - -export const commonMode: StreamParser<{ tag: boolean }> = { - name: 'common', - startState: () => ({ tag: false }), - token(stream, state) { - if (stream.match(printf) || stream.match(pythonFormat)) { - return 'keyword'; - } - const ch = stream.next(); - if (ch === '<') { - state.tag = true; - } - if (state.tag) { - if (ch === '>') { - state.tag = false; - } else { - stream.eatWhile(/[^>%{]+/); - } - return 'tagName'; - } - stream.eatWhile(/[^%{<]+/); - return 'string'; - }, -};