mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-05-07 18:48:39 +00:00
small changes
This commit is contained in:
@@ -66,10 +66,6 @@ updates:
|
|||||||
- dependency-name: "@babel/preset-react"
|
- dependency-name: "@babel/preset-react"
|
||||||
versions:
|
versions:
|
||||||
- 7.13.13
|
- 7.13.13
|
||||||
- dependency-name: codemirror
|
|
||||||
versions:
|
|
||||||
- 5.59.3
|
|
||||||
- 5.60.0
|
|
||||||
- dependency-name: classnames
|
- dependency-name: classnames
|
||||||
versions:
|
versions:
|
||||||
- 2.3.0
|
- 2.3.0
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
const autoCloseCurlyBraces = function(CodeMirror, cm, typingClosingBrace) {
|
|
||||||
const ranges = cm.listSelections(), replacements = [];
|
|
||||||
for (let i = 0; i < ranges.length; i++) {
|
|
||||||
if(!ranges[i].empty()) return CodeMirror.Pass;
|
|
||||||
const pos = ranges[i].head, line = cm.getLine(pos.line), tok = cm.getTokenAt(pos);
|
|
||||||
if(!typingClosingBrace && (tok.type == 'string' || tok.string.charAt(0) != '{' || tok.start != pos.ch - 1))
|
|
||||||
return CodeMirror.Pass;
|
|
||||||
else if(typingClosingBrace) {
|
|
||||||
let hasUnclosedBraces = false, index = -1;
|
|
||||||
do {
|
|
||||||
index = line.indexOf('{{', index + 1);
|
|
||||||
if(index !== -1 && line.indexOf('}}', index + 1) === -1) {
|
|
||||||
hasUnclosedBraces = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (index !== -1);
|
|
||||||
if(!hasUnclosedBraces) return CodeMirror.Pass;
|
|
||||||
}
|
|
||||||
|
|
||||||
replacements[i] = typingClosingBrace ? {
|
|
||||||
text : '}}',
|
|
||||||
newPos : CodeMirror.Pos(pos.line, pos.ch + 2)
|
|
||||||
} : {
|
|
||||||
text : '{}}',
|
|
||||||
newPos : CodeMirror.Pos(pos.line, pos.ch + 1)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = ranges.length - 1; i >= 0; i--) {
|
|
||||||
const info = replacements[i];
|
|
||||||
cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, '+insert');
|
|
||||||
const sel = cm.listSelections().slice(0);
|
|
||||||
sel[i] = {
|
|
||||||
head : info.newPos,
|
|
||||||
anchor : info.newPos
|
|
||||||
};
|
|
||||||
cm.setSelections(sel);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
|
||||||
autoCloseCurlyBraces : function(CodeMirror, codeMirror) {
|
|
||||||
const map = { name: 'autoCloseCurlyBraces' };
|
|
||||||
map[`'{'`] = function(cm) { return autoCloseCurlyBraces(CodeMirror, cm); };
|
|
||||||
map[`'}'`] = function(cm) { return autoCloseCurlyBraces(CodeMirror, cm, true); };
|
|
||||||
codeMirror?.addKeyMap(map);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -18,7 +18,7 @@ import { EditorState, Compartment, StateEffect, StateField } from '@codemirror/s
|
|||||||
import { foldAll as foldAllCmd, unfoldAll as unfoldAllCmd, 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 } 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';
|
||||||
@@ -83,7 +83,7 @@ const createHighlightPlugin = (renderer, tab)=>{
|
|||||||
}
|
}
|
||||||
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': snippetCount } }).range(line.from));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -128,14 +128,14 @@ const programmaticCursorLineField = StateField.define({
|
|||||||
const CodeEditor = forwardRef(
|
const CodeEditor = forwardRef(
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
|
language = '',
|
||||||
|
tab = 'brewText',
|
||||||
|
view,
|
||||||
value = '',
|
value = '',
|
||||||
onChange = ()=>{},
|
onChange = ()=>{},
|
||||||
onCursorChange = ()=>{},
|
onCursorChange = ()=>{},
|
||||||
onViewChange = ()=>{},
|
onViewChange = ()=>{},
|
||||||
language = '',
|
|
||||||
tab = 'brewText',
|
|
||||||
editorTheme = 'default',
|
editorTheme = 'default',
|
||||||
view,
|
|
||||||
style,
|
style,
|
||||||
renderer,
|
renderer,
|
||||||
...props
|
...props
|
||||||
@@ -344,14 +344,6 @@ const CodeEditor = forwardRef(
|
|||||||
}, [renderer, tab]);
|
}, [renderer, tab]);
|
||||||
|
|
||||||
useImperativeHandle(ref, ()=>({
|
useImperativeHandle(ref, ()=>({
|
||||||
getValue : ()=>viewRef.current.state.doc.toString(),
|
|
||||||
|
|
||||||
setValue : (text)=>{
|
|
||||||
const view = viewRef.current;
|
|
||||||
view.dispatch({
|
|
||||||
changes : { from: 0, to: view.state.doc.length, insert: text },
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
injectText : (text)=>{
|
injectText : (text)=>{
|
||||||
const view = viewRef.current;
|
const view = viewRef.current;
|
||||||
@@ -364,39 +356,15 @@ const CodeEditor = forwardRef(
|
|||||||
},
|
},
|
||||||
getCursorPosition : ()=>viewRef.current.state.selection.main.head,
|
getCursorPosition : ()=>viewRef.current.state.selection.main.head,
|
||||||
|
|
||||||
getScrollTop : ()=>viewRef.current.scrollDOM.scrollTop,
|
|
||||||
|
|
||||||
scrollToY : (y)=>{
|
|
||||||
viewRef.current.scrollDOM.scrollTo({ top: y });
|
|
||||||
},
|
|
||||||
|
|
||||||
scrollToPage : (pageNumber, smooth = true)=>{
|
scrollToPage : (pageNumber, smooth = true)=>{
|
||||||
const view = viewRef.current;
|
const view = viewRef.current;
|
||||||
if(!view) return;
|
if(!view) return;
|
||||||
|
|
||||||
const pos = pageBreaksRef.current[pageNumber - 1] ?? 0;
|
const pos = pageBreaksRef.current[pageNumber - 1] ?? 0;
|
||||||
|
|
||||||
view.dispatch({
|
|
||||||
effects : EditorView.scrollIntoView(pos, { y: 'start' })
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
|
||||||
getPagePos : (pageNumber)=>{
|
|
||||||
const view = viewRef.current;
|
|
||||||
if(!view) return 0;
|
|
||||||
|
|
||||||
const pos = pageBreaksRef.current[pageNumber - 1] ?? 0;
|
|
||||||
return pos;
|
|
||||||
},
|
|
||||||
setCursorToPage : (pageNumber)=>{
|
|
||||||
const view = viewRef.current;
|
|
||||||
if(!view) return;
|
|
||||||
|
|
||||||
const pos = pageBreaksRef.current[pageNumber - 1] ?? 0;
|
|
||||||
|
|
||||||
view.dispatch({
|
view.dispatch({
|
||||||
selection : { anchor: pos },
|
selection : { anchor: pos },
|
||||||
effects : setProgrammaticCursorLine.of(pos)
|
effects : [setProgrammaticCursorLine.of(pos), EditorView.scrollIntoView(pos, { y: 'start' })],
|
||||||
});
|
});
|
||||||
|
|
||||||
view.focus();
|
view.focus();
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const EditorThemes = Object.entries(themes)
|
|||||||
.map(([name])=>name);
|
.map(([name])=>name);
|
||||||
|
|
||||||
|
|
||||||
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
//const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
||||||
//const SNIPPETBREAK_REGEX_V3 = /^\\snippet\ .*$/;
|
//const SNIPPETBREAK_REGEX_V3 = /^\\snippet\ .*$/;
|
||||||
const DEFAULT_STYLE_TEXT = dedent`
|
const DEFAULT_STYLE_TEXT = dedent`
|
||||||
/*=======--- Example CSS styling ---=======*/
|
/*=======--- Example CSS styling ---=======*/
|
||||||
@@ -215,7 +215,6 @@ const Editor = createReactClass({
|
|||||||
jumpSource = 'source';
|
jumpSource = 'source';
|
||||||
|
|
||||||
editor.scrollToPage(targetPage);
|
editor.scrollToPage(targetPage);
|
||||||
editor.setCursorToPage(targetPage);
|
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
jumpSource = null;
|
jumpSource = null;
|
||||||
}, 200);
|
}, 200);
|
||||||
@@ -250,7 +249,6 @@ const Editor = createReactClass({
|
|||||||
onViewChange={(page)=>this.updateCurrentViewPage(page)}
|
onViewChange={(page)=>this.updateCurrentViewPage(page)}
|
||||||
editorTheme={this.state.editorTheme}
|
editorTheme={this.state.editorTheme}
|
||||||
renderer={this.props.brew.renderer}
|
renderer={this.props.brew.renderer}
|
||||||
rerenderParent={this.rerenderParent}
|
|
||||||
style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }}
|
style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }}
|
||||||
onReady={this.attachCodeMirrorListeners}/>
|
onReady={this.attachCodeMirrorListeners}/>
|
||||||
</>;
|
</>;
|
||||||
@@ -264,10 +262,8 @@ const Editor = createReactClass({
|
|||||||
view={this.state.view}
|
view={this.state.view}
|
||||||
value={this.props.brew.style ?? DEFAULT_STYLE_TEXT}
|
value={this.props.brew.style ?? DEFAULT_STYLE_TEXT}
|
||||||
onChange={this.props.onBrewChange('style')}
|
onChange={this.props.onBrewChange('style')}
|
||||||
enableFolding={true}
|
|
||||||
editorTheme={this.state.editorTheme}
|
editorTheme={this.state.editorTheme}
|
||||||
renderer={this.props.brew.renderer}
|
renderer={this.props.brew.renderer}
|
||||||
rerenderParent={this.rerenderParent}
|
|
||||||
style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }}
|
style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }}
|
||||||
onReady={this.attachCodeMirrorListeners}/>
|
onReady={this.attachCodeMirrorListeners}/>
|
||||||
</>;
|
</>;
|
||||||
@@ -276,8 +272,7 @@ const Editor = createReactClass({
|
|||||||
return <>
|
return <>
|
||||||
<CodeEditor key='codeEditor'
|
<CodeEditor key='codeEditor'
|
||||||
view={this.state.view}
|
view={this.state.view}
|
||||||
style={{ display: 'none' }}
|
style={{ display: 'none' }}/>
|
||||||
rerenderParent={this.rerenderParent} />
|
|
||||||
<MetadataEditor
|
<MetadataEditor
|
||||||
metadata={this.props.brew}
|
metadata={this.props.brew}
|
||||||
themeBundle={this.props.themeBundle}
|
themeBundle={this.props.themeBundle}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ const ThemeSnippets = {
|
|||||||
V3_Blank : V3_Blank,
|
V3_Blank : V3_Blank,
|
||||||
};
|
};
|
||||||
|
|
||||||
//import EditorThemes from '../../../../build/homebrew/codeMirror/editorThemes.json';
|
|
||||||
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';
|
||||||
import darkbrewery from '@themes/codeMirror/darkbrewery.js';
|
import darkbrewery from '@themes/codeMirror/darkbrewery.js';
|
||||||
|
|||||||
Reference in New Issue
Block a user