mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-04 16:08:54 +00:00
Merge branch 'master' into fix-new-brew-page
This commit is contained in:
@@ -156,6 +156,31 @@ const CodeEditor = forwardRef(
|
||||
return folds;
|
||||
};
|
||||
|
||||
const foldAll = (view = viewRef.current)=>{
|
||||
if(!view) return false;
|
||||
|
||||
const doc = view.state.doc;
|
||||
const pages = pageMap.current;
|
||||
|
||||
const effects = pages.map((start, i)=>{
|
||||
const next = pages[i + 1] || doc.length;
|
||||
const from = i ? doc.line(doc.lineAt(start).number + 1).from : 0;
|
||||
const to = doc.line(doc.lineAt(next).number).from - 1;
|
||||
|
||||
return to > from ? foldEffect.of({ from, to }) : null;
|
||||
}).filter(Boolean);
|
||||
|
||||
view.dispatch({ effects });
|
||||
return true;
|
||||
};
|
||||
|
||||
const unfoldAll = (view = viewRef.current)=>{
|
||||
if(!view) return false;
|
||||
|
||||
view.dispatch(unfoldAllCmd(view));
|
||||
return true;
|
||||
};
|
||||
|
||||
const createExtensions = ({ onChange, language, editorTheme })=>{
|
||||
const setEventListeners = EditorView.updateListener.of((update)=>{
|
||||
if(update.docChanged) {
|
||||
@@ -199,7 +224,7 @@ const CodeEditor = forwardRef(
|
||||
|
||||
//keyboard shortcut
|
||||
keymap.of([...defaultKeymap, foldKeymap, ...searchKeymap]),
|
||||
generalKeymap,
|
||||
generalKeymap(foldAll, unfoldAll),
|
||||
...(tab === 'brewStyles' ? [cssKeymap] : [markdownKeymap]),
|
||||
|
||||
//multiple cursors and selections
|
||||
@@ -404,29 +429,8 @@ const CodeEditor = forwardRef(
|
||||
undone : redoDepth(view.state),
|
||||
};
|
||||
},
|
||||
|
||||
foldAll : ()=>{
|
||||
const view = viewRef.current;
|
||||
if(!view) return;
|
||||
|
||||
const doc = view.state.doc;
|
||||
const pages = pageMap.current;
|
||||
|
||||
const effects = pages.map((start, i)=>{
|
||||
const next = pages[i + 1] || doc.length;
|
||||
const from = i ? doc.line(doc.lineAt(start).number + 1).from : 0;
|
||||
const to = doc.line(doc.lineAt(next).number).from - 1;
|
||||
|
||||
return to > from ? foldEffect.of({ from, to }) : null;
|
||||
}).filter(Boolean);
|
||||
|
||||
view.dispatch({ effects });
|
||||
},
|
||||
unfoldAll : ()=>{
|
||||
const view = viewRef.current;
|
||||
if(!view) return;
|
||||
view.dispatch(unfoldAllCmd(view));
|
||||
},
|
||||
foldAll : ()=>foldAll(),
|
||||
unfoldAll : ()=>unfoldAll(),
|
||||
|
||||
focus : ()=>viewRef.current.focus(),
|
||||
}));
|
||||
|
||||
@@ -215,13 +215,15 @@ const newBreak = (type)=>(view)=>forEachSelection(view, (state, from, to, select
|
||||
};
|
||||
});
|
||||
|
||||
export const generalKeymap = Prec.high(keymap.of([
|
||||
export const generalKeymap = (foldAll, unfoldAll) => Prec.high(keymap.of([
|
||||
{ key: 'Tab', run: insertTab },
|
||||
{ key: 'Shift-Tab', run: indentLess },
|
||||
{ key: 'Mod-z', run: undo }, //it may be unnecessary
|
||||
{ key: 'Mod-Shift-z', run: redo },
|
||||
{ key: 'Mod-y', run: redo }, //user asked, so double keybind
|
||||
{ key: 'Mod-d', run: deleteLine }, //annoyingly overrides "selectNextOccurrence" because users asked
|
||||
{ key: 'Mod-Shift-[', run: foldAll },
|
||||
{ key: 'Mod-Shift-]', run: unfoldAll },
|
||||
]));
|
||||
|
||||
export const cssKeymap = Prec.highest(keymap.of([
|
||||
|
||||
@@ -368,8 +368,8 @@ const api = {
|
||||
if(failedPatchCount){
|
||||
throw (`Patch failure: ${failedPatchCount}/${result[1].length} did not apply`);
|
||||
}
|
||||
patchedText = decodeURI(result[0]);
|
||||
if(patchedText != brewFromClient.text){
|
||||
const patchedText = decodeURI(result[0]);
|
||||
if(patchedText !== brewFromClient.text){
|
||||
debugTextMismatch(brewFromClient.text, patchedText, `edit/${brewFromClient.editId}`);
|
||||
throw ('Patches did not apply cleanly, text mismatch detected');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user