From fb426755749eab3c3b0aff043768011cb20f009a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sun, 29 Mar 2026 01:36:37 +0100 Subject: [PATCH] fold all and unfold all restored --- client/components/codeEditor/codeEditor.jsx | 23 ++++++++++++++----- client/components/codeEditor/customFolding.js | 2 +- client/homebrew/editor/editor.jsx | 13 +++++------ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/client/components/codeEditor/codeEditor.jsx b/client/components/codeEditor/codeEditor.jsx index 9c97ba0e3..1dde9eaf5 100644 --- a/client/components/codeEditor/codeEditor.jsx +++ b/client/components/codeEditor/codeEditor.jsx @@ -16,17 +16,17 @@ import { dropCursor, } from '@codemirror/view'; import { EditorState, Compartment } from '@codemirror/state'; -import { foldGutter, foldKeymap, syntaxHighlighting } from '@codemirror/language'; +import { foldAll as foldAllCmd, unfoldAll as unfoldAllCmd, foldGutter, foldKeymap, syntaxHighlighting } from '@codemirror/language'; import { defaultKeymap, history, undo, redo, undoDepth, redoDepth } from '@codemirror/commands'; import { languages } from '@codemirror/language-data'; import { css, cssLanguage } from '@codemirror/lang-css'; import { markdown, markdownLanguage } from '@codemirror/lang-markdown'; -import {html} from "@codemirror/lang-html" +import { html } from '@codemirror/lang-html'; import { autocompleteEmoji } from './autocompleteEmoji.js'; import { searchKeymap, search } from '@codemirror/search'; -import {closeBrackets} from "@codemirror/autocomplete" +import { closeBrackets } from '@codemirror/autocomplete'; -const customClose = closeBrackets({ brackets: ["()", "[]", "{{}}"] }); +const customClose = closeBrackets({ brackets: ['()', '[]', '{{}}'] }); import * as themesImport from '@uiw/codemirror-themes-all'; import defaultCM5Theme from '@themes/codeMirror/default.js'; @@ -80,11 +80,11 @@ const createHighlightPlugin = (renderer, tab)=>{ if(tok.type === 'pageLine' && tab === 'brewText') { pageCount++; line.from === 0 && pageCount--; - decos.push( Decoration.line({ attributes: { "data-page-number": pageCount }}).range(line.from)); + decos.push(Decoration.line({ attributes: { 'data-page-number': pageCount } }).range(line.from)); } if(tok.type === 'snippetLine' && tab === 'brewSnippets') { snippetCount++; - decos.push(Decoration.line({ attributes: { "data-page-number": pageCount }}).range(line.from)); + decos.push(Decoration.line({ attributes: { 'data-page-number': pageCount } }).range(line.from)); } } }); @@ -324,6 +324,17 @@ const CodeEditor = forwardRef( }; }, + foldAll : ()=>{ + const view = viewRef.current; + if(!view) return; + view.dispatch(foldAllCmd(view)); + }, + unfoldAll : ()=>{ + const view = viewRef.current; + if(!view) return; + view.dispatch(unfoldAllCmd(view)); + }, + focus : ()=>viewRef.current.focus(), })); diff --git a/client/components/codeEditor/customFolding.js b/client/components/codeEditor/customFolding.js index b0ce67106..ea9087c03 100644 --- a/client/components/codeEditor/customFolding.js +++ b/client/components/codeEditor/customFolding.js @@ -8,7 +8,7 @@ const pageFoldExtension = [ const startLine = doc.lineAt(lineStart); const prevLineText = startLine.number > 1 ? doc.line(startLine.number - 1).text : ''; - if(startLine.number > 1 && !matcher.test(prevLineText)) return null; + if(!matcher.test(prevLineText)) return null; let endLine = startLine.number; while (endLine < doc.lines && !matcher.test(doc.line(endLine + 1).text)) { diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 4deffa18a..0916ac0d7 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -330,14 +330,13 @@ const Editor = createReactClass({ return this.codeEditor.current?.undo(); }, - foldCode : function(){ - return this.codeEditor.current?.foldAllCode(); - }, - - unfoldCode : function(){ - return this.codeEditor.current?.unfoldAllCode(); - }, +foldCode: function() { + return this.codeEditor.current?.foldAll(); +}, +unfoldCode: function() { + return this.codeEditor.current?.unfoldAll(); +}, render : function(){ return (