0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-29 14:18:11 +00:00

fold all and unfold all restored

This commit is contained in:
Víctor Losada Hernández
2026-03-29 01:36:37 +01:00
parent 1d02fb9565
commit fb42675574
3 changed files with 24 additions and 14 deletions

View File

@@ -16,17 +16,17 @@ import {
dropCursor, dropCursor,
} from '@codemirror/view'; } from '@codemirror/view';
import { EditorState, Compartment } from '@codemirror/state'; 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 { defaultKeymap, history, undo, redo, undoDepth, redoDepth } from '@codemirror/commands';
import { languages } from '@codemirror/language-data'; import { languages } from '@codemirror/language-data';
import { css, cssLanguage } from '@codemirror/lang-css'; import { css, cssLanguage } from '@codemirror/lang-css';
import { markdown, markdownLanguage } from '@codemirror/lang-markdown'; 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 { autocompleteEmoji } from './autocompleteEmoji.js';
import { searchKeymap, search } from '@codemirror/search'; 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 * as themesImport from '@uiw/codemirror-themes-all';
import defaultCM5Theme from '@themes/codeMirror/default.js'; import defaultCM5Theme from '@themes/codeMirror/default.js';
@@ -80,11 +80,11 @@ const createHighlightPlugin = (renderer, tab)=>{
if(tok.type === 'pageLine' && tab === 'brewText') { if(tok.type === 'pageLine' && tab === 'brewText') {
pageCount++; pageCount++;
line.from === 0 && 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') { if(tok.type === 'snippetLine' && tab === 'brewSnippets') {
snippetCount++; 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(), focus : ()=>viewRef.current.focus(),
})); }));

View File

@@ -8,7 +8,7 @@ const pageFoldExtension = [
const startLine = doc.lineAt(lineStart); const startLine = doc.lineAt(lineStart);
const prevLineText = startLine.number > 1 ? doc.line(startLine.number - 1).text : ''; 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; let endLine = startLine.number;
while (endLine < doc.lines && !matcher.test(doc.line(endLine + 1).text)) { while (endLine < doc.lines && !matcher.test(doc.line(endLine + 1).text)) {

View File

@@ -330,14 +330,13 @@ const Editor = createReactClass({
return this.codeEditor.current?.undo(); return this.codeEditor.current?.undo();
}, },
foldCode : function(){ foldCode: function() {
return this.codeEditor.current?.foldAllCode(); return this.codeEditor.current?.foldAll();
}, },
unfoldCode : function(){
return this.codeEditor.current?.unfoldAllCode();
},
unfoldCode: function() {
return this.codeEditor.current?.unfoldAll();
},
render : function(){ render : function(){
return ( return (
<div className='editor' ref={this.editor}> <div className='editor' ref={this.editor}>