0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-28 23:08:12 +00:00

simplify fold export & restore legacy higlights

This commit is contained in:
Víctor Losada Hernández
2026-03-27 19:11:52 +01:00
parent 4da270616d
commit 4bce4a9489
7 changed files with 160 additions and 139 deletions

View File

@@ -24,16 +24,16 @@ import { autocompleteEmoji } from './autocompleteEmoji.js';
import { searchKeymap, search } from '@codemirror/search';
import * as themesImport from '@uiw/codemirror-themes-all';
import { defaultCM5Theme } from '@themes/codeMirror/customThemes/default.js';
import defaultCM5Theme from '@themes/codeMirror/customThemes/default.js';
const themes = { default: defaultCM5Theme, ...themesImport };
const themeCompartment = new Compartment();
const highlightCompartment = new Compartment();
import { customKeymap } from './customKeyMap.js';
import { homebreweryFold, hbFolding } from './customFolding.js';
import customKeymap from './customKeyMap.js';
import pageFoldExtension from './customFolding.js';
import { customHighlightStyle, tokenizeCustomMarkdown, tokenizeCustomCSS } from './customHighlight.js';
import { legacyCustomHighlightStyle, legacyTokenizeCustomMarkdown } from './legacyCustomHighlight.js'; //only makes highlight for
import { legacyCustomHighlightStyle, legacyTokenizeCustomMarkdown } from './legacyCustomHighlight.js';
const createHighlightPlugin = (renderer, tab)=>{
let tokenize;
@@ -131,7 +131,7 @@ const CodeEditor = forwardRef(
const prevTabRef = useRef(tab);
const createExtensions = ({ onChange, language, editorTheme })=>{
const updateListener = EditorView.updateListener.of((update)=>{
const setEventListeners = EditorView.updateListener.of((update)=>{
if(update.docChanged) {
onChange(update.state.doc.toString());
}
@@ -155,26 +155,17 @@ const CodeEditor = forwardRef(
const customHighlightPlugin = createHighlightPlugin(renderer, tab);
const combinedHighlight = [
customHighlightPlugin,
highlightExtension,
];
const languageExtension = language === 'css' ? [css(), cssLanguage] : markdown({ base: markdownLanguage, codeLanguages: languages });
const themeExtension = Array.isArray(themes[editorTheme]) ? themes[editorTheme] : [];
return [
history(),
updateListener,
history(), //allows for undo and redo
setEventListeners,
EditorView.lineWrapping,
scrollPastEnd(),
languageExtension,
lineNumbers(),
homebreweryFold,
hbFolding,
pageFoldExtension,
foldGutter({
openText : '▾',
@@ -183,7 +174,7 @@ const CodeEditor = forwardRef(
highlightActiveLine(),
highlightActiveLineGutter(),
highlightCompartment.of(combinedHighlight),
highlightCompartment.of([customHighlightPlugin,highlightExtension]),
themeCompartment.of(themeExtension),
...(tab !== 'brewStyles' ? [autocompleteEmoji] : []),
search(),