From a83ac83ed35e674dbac2015eb1f596cc6c50a0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 24 Aug 2026 18:46:22 +0200 Subject: [PATCH] full functionality --- client/components/codeEditor/codeEditor.jsx | 44 ++++++++++++++++--- client/homebrew/editor/editor.jsx | 2 +- .../editor/settingsEditor/settingsEditor.jsx | 15 ++++++- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/client/components/codeEditor/codeEditor.jsx b/client/components/codeEditor/codeEditor.jsx index 25bf4f88e..1a9bb0213 100644 --- a/client/components/codeEditor/codeEditor.jsx +++ b/client/components/codeEditor/codeEditor.jsx @@ -1,4 +1,4 @@ -/* eslint max-lines: ["error", { "max": 405 }] */ +/* eslint max-lines: ["error", { "max": 455 }] */ import './codeEditor.less'; import React, { useEffect, useRef, forwardRef, useImperativeHandle } from 'react'; @@ -42,6 +42,7 @@ import cm5Themes from 'codemirror-5-themes'; const themes = { default: defaultCM5Theme, ...cm5Themes, darkbrewery }; const themeCompartment = new Compartment(); const highlightCompartment = new Compartment(); +const settingsCompartment = new Compartment(); import { generalKeymap, markdownKeymap } from './extensions/customKeyMaps.js'; import foldOnPages from './extensions/customFolding.js'; @@ -78,6 +79,20 @@ const programmaticCursorLineField = StateField.define({ provide : (decorationSet)=>EditorView.decorations.from(decorationSet) }); +const createSettingsExtensions = (settings)=>[ + ...(settings.autoCloseBrackets ? [autoCloseBrackets] : []), + ...(settings.lineNumbers ? [lineNumbers()] : []), + ...(settings.activeLineShading ? [highlightActiveLine(), + highlightActiveLineGutter()] : []), + ...(settings.fontSize + ? [EditorView.theme({ + '&, .cm-content' : { + fontSize : `${settings.fontSize}px`, + }, + })] + : []), +]; + const CodeEditor = forwardRef( ( { @@ -91,6 +106,7 @@ const CodeEditor = forwardRef( editorTheme = 'default', style, renderer, + settings = {}, ...props }, ref, @@ -163,8 +179,7 @@ const CodeEditor = forwardRef( EditorView.lineWrapping, setEventListeners, languageExtension, - autoCloseBrackets, - lineNumbers(), + settingsCompartment.of(createSettingsExtensions(settings)), scrollPastEnd(), search(), history(), //allows for undo and redo @@ -180,8 +195,6 @@ const CodeEditor = forwardRef( //highlights highlightCompartment.of([customHighlightPlugin(renderer, tab), highlightExtension]), themeCompartment.of(themeExtension), - highlightActiveLine(), - highlightActiveLineGutter(), //keyboard shortcut keymap.of([...defaultKeymap, foldKeymap, ...searchKeymap]), @@ -271,6 +284,14 @@ const CodeEditor = forwardRef( } view.setState(nextState); + view.dispatch({ + effects : settingsCompartment.reconfigure( + createSettingsExtensions(settings) + ), + }); + + //load settings too + restoreFolds(view, foldsRef.current[tab]); const savedScroll = scrollRef.current[tab]; @@ -320,10 +341,21 @@ const CodeEditor = forwardRef( : syntaxHighlighting(legacyCustomHighlightStyle); view.dispatch({ - effects : highlightCompartment.reconfigure([customHighlightPlugin(renderer, tab), highlightExtension]), + effects : highlightCompartment.reconfigure([customHighlightPlugin(renderer, tab), highlightExtension]) }); }, [renderer, tab]); + useEffect(()=>{ + const view = viewRef.current; + if(!view) return; + + view.dispatch({ + effects : settingsCompartment.reconfigure( + createSettingsExtensions(settings) + ), + }); + }, [settings]); + useImperativeHandle(ref, ()=>({ injectText : (text)=>{ diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 797a452fb..f03dc0e4e 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -78,7 +78,7 @@ const Editor = forwardRef( blockShading: false, activeLineShading: true, lineNumbers: true, - fontSize: 14 + fontSize: 13 }) const editor = useRef(null); diff --git a/client/homebrew/editor/settingsEditor/settingsEditor.jsx b/client/homebrew/editor/settingsEditor/settingsEditor.jsx index c3566f8de..1acb64598 100644 --- a/client/homebrew/editor/settingsEditor/settingsEditor.jsx +++ b/client/homebrew/editor/settingsEditor/settingsEditor.jsx @@ -52,7 +52,7 @@ const SettingsEditor = ({settings, updateSettings = () => {} }) => { return (

Editor Settings

- +{/*
*/} + +
+ + handleFieldChange('autoCloseBrackets', e)} + />