0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-27 21:08:13 +00:00

custom key map

This commit is contained in:
Víctor Losada Hernández
2026-03-26 17:08:01 +01:00
parent 3b9eae2e4f
commit 3a671cf48f
2 changed files with 226 additions and 37 deletions

View File

@@ -20,9 +20,9 @@ import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
import * as themes from '@uiw/codemirror-themes-all';
const themeCompartment = new Compartment();
const highlightCompartment = new Compartment();
import { customKeymap } from './customKeyMap.js';
import { homebreweryFold, hbFolding } from './customFolding.js';
import { customHighlightStyle, tokenizeCustomMarkdown } from './customHighlight.js';
import { legacyCustomHighlightStyle, legacyTokenizeCustomMarkdown } from './legacyCustomHighlight.js'; //only makes highlight for
@@ -64,7 +64,6 @@ const createHighlightPlugin = (renderer)=>{
);
};
const CodeEditor = forwardRef(
(
{
@@ -92,37 +91,6 @@ const CodeEditor = forwardRef(
}
});
const boldCommand = (view)=>{
const { from, to } = view.state.selection.main;
const selected = view.state.doc.sliceString(from, to);
const text = `**${selected}**`;
view.dispatch({
changes : { from, to, insert: text },
selection : { anchor: from + text.length },
});
return true;
};
const italicCommand = (view)=>{
const { from, to } = view.state.selection.main;
const selected = view.state.doc.sliceString(from, to);
const text = `*${selected}*`;
view.dispatch({
changes : { from, to, insert: text },
selection : { anchor: from + text.length },
});
return true;
};
const customKeymap = keymap.of([
{ key: 'Mod-b', run: boldCommand },
{ key: 'Mod-i', run: italicCommand },
]);
const highlightExtension = renderer === 'V3'
? syntaxHighlighting(customHighlightStyle)
: syntaxHighlighting(legacyCustomHighlightStyle);
@@ -134,13 +102,10 @@ const CodeEditor = forwardRef(
highlightExtension,
];
const languageExtension =
language === 'css' ? css() : markdown({ base: markdownLanguage, codeLanguages: languages });
const languageExtension = language === 'css' ? css() : markdown({ base: markdownLanguage, codeLanguages: languages });
const themeExtension = Array.isArray(themes[editorTheme]) ? themes[editorTheme] : [];
return [
history(),
keymap.of(defaultKeymap),