mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-04 20:29:01 +00:00
Merge branch 'master' into clean-up-app-base
This commit is contained in:
@@ -156,6 +156,31 @@ const CodeEditor = forwardRef(
|
|||||||
return folds;
|
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 createExtensions = ({ onChange, language, editorTheme })=>{
|
||||||
const setEventListeners = EditorView.updateListener.of((update)=>{
|
const setEventListeners = EditorView.updateListener.of((update)=>{
|
||||||
if(update.docChanged) {
|
if(update.docChanged) {
|
||||||
@@ -199,7 +224,7 @@ const CodeEditor = forwardRef(
|
|||||||
|
|
||||||
//keyboard shortcut
|
//keyboard shortcut
|
||||||
keymap.of([...defaultKeymap, foldKeymap, ...searchKeymap]),
|
keymap.of([...defaultKeymap, foldKeymap, ...searchKeymap]),
|
||||||
generalKeymap,
|
generalKeymap(foldAll, unfoldAll),
|
||||||
...(tab === 'brewStyles' ? [cssKeymap] : [markdownKeymap]),
|
...(tab === 'brewStyles' ? [cssKeymap] : [markdownKeymap]),
|
||||||
|
|
||||||
//multiple cursors and selections
|
//multiple cursors and selections
|
||||||
@@ -404,29 +429,8 @@ const CodeEditor = forwardRef(
|
|||||||
undone : redoDepth(view.state),
|
undone : redoDepth(view.state),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
foldAll : ()=>foldAll(),
|
||||||
foldAll : ()=>{
|
unfoldAll : ()=>unfoldAll(),
|
||||||
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));
|
|
||||||
},
|
|
||||||
|
|
||||||
focus : ()=>viewRef.current.focus(),
|
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: 'Tab', run: insertTab },
|
||||||
{ key: 'Shift-Tab', run: indentLess },
|
{ key: 'Shift-Tab', run: indentLess },
|
||||||
{ key: 'Mod-z', run: undo }, //it may be unnecessary
|
{ key: 'Mod-z', run: undo }, //it may be unnecessary
|
||||||
{ key: 'Mod-Shift-z', run: redo },
|
{ key: 'Mod-Shift-z', run: redo },
|
||||||
{ key: 'Mod-y', run: redo }, //user asked, so double keybind
|
{ key: 'Mod-y', run: redo }, //user asked, so double keybind
|
||||||
{ key: 'Mod-d', run: deleteLine }, //annoyingly overrides "selectNextOccurrence" because users asked
|
{ 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([
|
export const cssKeymap = Prec.highest(keymap.of([
|
||||||
|
|||||||
@@ -112,12 +112,15 @@ const EditorPage = (props)=>{
|
|||||||
const snipStorage = localStorage.getItem(SNIPKEY);
|
const snipStorage = localStorage.getItem(SNIPKEY);
|
||||||
const metaStorage = JSON.parse(localStorage.getItem(METAKEY));
|
const metaStorage = JSON.parse(localStorage.getItem(METAKEY));
|
||||||
|
|
||||||
brew.text = brewStorage ?? brew.text;
|
brew.title = metaStorage?.title ?? brew.title;
|
||||||
brew.style = styleStorage ?? brew.style;
|
brew.description = metaStorage?.description ?? brew.description;
|
||||||
brew.snippets = snipStorage ?? brew.snippets;
|
brew.tags = metaStorage?.tags ?? brew.tags;
|
||||||
brew.renderer = metaStorage?.renderer ?? brew.renderer;
|
brew.text = brewStorage ?? brew.text;
|
||||||
brew.theme = metaStorage?.theme ?? brew.theme;
|
brew.style = styleStorage ?? brew.style;
|
||||||
brew.lang = metaStorage?.lang ?? brew.lang;
|
brew.snippets = snipStorage ?? brew.snippets;
|
||||||
|
brew.renderer = metaStorage?.renderer ?? brew.renderer;
|
||||||
|
brew.theme = metaStorage?.theme ?? brew.theme;
|
||||||
|
brew.lang = metaStorage?.lang ?? brew.lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SAVEKEY = `${SAVEKEY_PREFIX}${global.account?.username}`;
|
const SAVEKEY = `${SAVEKEY_PREFIX}${global.account?.username}`;
|
||||||
@@ -130,7 +133,7 @@ const EditorPage = (props)=>{
|
|||||||
localStorage.setItem(BREWKEY, brew.text);
|
localStorage.setItem(BREWKEY, brew.text);
|
||||||
if(brew.style) localStorage.setItem(STYLEKEY, brew.style);
|
if(brew.style) localStorage.setItem(STYLEKEY, brew.style);
|
||||||
if(brew.snippets) localStorage.setItem(SNIPKEY, brew.snippets);
|
if(brew.snippets) localStorage.setItem(SNIPKEY, brew.snippets);
|
||||||
localStorage.setItem(METAKEY, JSON.stringify({ renderer: brew.renderer, theme: brew.theme, lang: brew.lang }));
|
localStorage.setItem(METAKEY, JSON.stringify({ title: brew.title, description: brew.description, tags: brew.tags, renderer: brew.renderer, theme: brew.theme, lang: brew.lang }));
|
||||||
if(window.location.pathname !== '/new')
|
if(window.location.pathname !== '/new')
|
||||||
window.history.replaceState({}, window.location.title, '/new/');
|
window.history.replaceState({}, window.location.title, '/new/');
|
||||||
};
|
};
|
||||||
@@ -177,9 +180,12 @@ const EditorPage = (props)=>{
|
|||||||
if(field == 'style') localStorage.setItem(STYLEKEY, value);
|
if(field == 'style') localStorage.setItem(STYLEKEY, value);
|
||||||
if(field == 'snippets') localStorage.setItem(SNIPKEY, value);
|
if(field == 'snippets') localStorage.setItem(SNIPKEY, value);
|
||||||
if(field == 'metadata') localStorage.setItem(METAKEY, JSON.stringify({
|
if(field == 'metadata') localStorage.setItem(METAKEY, JSON.stringify({
|
||||||
renderer : value.renderer,
|
title : value.title,
|
||||||
theme : value.theme,
|
description : value.description,
|
||||||
lang : value.lang
|
tags : value.tags,
|
||||||
|
renderer : value.renderer,
|
||||||
|
theme : value.theme,
|
||||||
|
lang : value.lang
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -368,8 +368,8 @@ const api = {
|
|||||||
if(failedPatchCount){
|
if(failedPatchCount){
|
||||||
throw (`Patch failure: ${failedPatchCount}/${result[1].length} did not apply`);
|
throw (`Patch failure: ${failedPatchCount}/${result[1].length} did not apply`);
|
||||||
}
|
}
|
||||||
patchedText = decodeURI(result[0]);
|
const patchedText = decodeURI(result[0]);
|
||||||
if(patchedText != brewFromClient.text){
|
if(patchedText !== brewFromClient.text){
|
||||||
debugTextMismatch(brewFromClient.text, patchedText, `edit/${brewFromClient.editId}`);
|
debugTextMismatch(brewFromClient.text, patchedText, `edit/${brewFromClient.editId}`);
|
||||||
throw ('Patches did not apply cleanly, text mismatch detected');
|
throw ('Patches did not apply cleanly, text mismatch detected');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user