0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-06-26 08:38:40 +00:00

fix keybind to ctrl f

This commit is contained in:
Víctor Losada Hernández
2026-05-13 21:22:36 +02:00
parent ef9c3c1eb6
commit 7c30380ca6
2 changed files with 48 additions and 56 deletions
+2 -2
View File
@@ -37,7 +37,7 @@ const themes = { default: defaultCM5Theme, ...cm5Themes, darkbrewery };
const themeCompartment = new Compartment(); const themeCompartment = new Compartment();
const highlightCompartment = new Compartment(); const highlightCompartment = new Compartment();
import { generalKeymap, markdownKeymap } from './customKeyMaps.js'; import { generalKeymap, markdownKeymap, cssKeymap } from './customKeyMaps.js';
import foldOnPages from './customFolding.js'; import foldOnPages from './customFolding.js';
import { customHighlightStyle, tokenizeCustomMarkdown, tokenizeCustomCSS } from './customHighlight.js'; import { customHighlightStyle, tokenizeCustomMarkdown, tokenizeCustomCSS } from './customHighlight.js';
import { legacyCustomHighlightStyle, legacyTokenizeCustomMarkdown } from './legacyCustomHighlight.js'; import { legacyCustomHighlightStyle, legacyTokenizeCustomMarkdown } from './legacyCustomHighlight.js';
@@ -238,7 +238,7 @@ const CodeEditor = forwardRef(
//keyboard shortcut //keyboard shortcut
keymap.of([...defaultKeymap, foldKeymap, ...searchKeymap]), keymap.of([...defaultKeymap, foldKeymap, ...searchKeymap]),
generalKeymap, generalKeymap,
...(tab !== 'brewStyles' ? [markdownKeymap] : []), ...(tab === 'brewStyles' ? [cssKeymap] : [markdownKeymap]),
//multiple cursors and selections //multiple cursors and selections
drawSelection(), drawSelection(),
+46 -54
View File
@@ -2,37 +2,26 @@
import { keymap } from '@codemirror/view'; import { keymap } from '@codemirror/view';
import { undo, redo, indentMore, deleteLine } from '@codemirror/commands'; import { undo, redo, indentMore, deleteLine } from '@codemirror/commands';
import { Prec } from '@codemirror/state'; import { Prec } from '@codemirror/state';
import * as prettier from "prettier/standalone"; import * as prettier from 'prettier/standalone';
import * as postcssPlugin from "prettier/plugins/postcss"; import * as postcssPlugin from 'prettier/plugins/postcss';
async function formatCSS(view) { export async function formatCSS(view) {
const code = view.state.doc.toString(); const code = view.state.doc.toString();
const formatted = await prettier.format(code, { const formatted = await prettier.format(code, {
parser: "css", parser : 'css',
plugins: [postcssPlugin] plugins : [postcssPlugin]
}); });
view.dispatch({ view.dispatch({
changes: { changes : {
from: 0, from : 0,
to: view.state.doc.length, to : view.state.doc.length,
insert: formatted insert : formatted
} }
}); });
} }
const insertTab = (view) => {
const { from, to } = view.state.selection.main;
view.dispatch({
changes: { from, to, insert: ' ' },
selection: { anchor: from + 2 }
});
return true;
};
const indentLess = (view)=>{ const indentLess = (view)=>{
const { from, to } = view.state.selection.main; const { from, to } = view.state.selection.main;
const lines = []; const lines = [];
@@ -47,46 +36,46 @@ const indentLess = (view)=>{
return true; return true;
}; };
const wrapSelection = (prefix, suffix) => (view) => { const wrapSelection = (prefix, suffix)=>(view)=>{
const changes = []; const { from, to } = view.state.selection.main;
const selected = view.state.doc.sliceString(from, to);
for(const range of view.state.selection.ranges) { let text, selection;
const { from, to } = range;
const selected = view.state.doc.sliceString(from, to);
let text; if(from === to) {
text = prefix + suffix;
if(from === to) { text = prefix + suffix } selection = { anchor: from + prefix.length, head: from + prefix.length };
else if(selected.startsWith(prefix) && selected.endsWith(suffix)) { } else if(selected.startsWith(prefix) && selected.endsWith(suffix)) {
text = selected.slice(prefix.length, -suffix.length); text = selected.slice(prefix.length, -suffix.length);
} selection = { anchor: from, head: from + text.length };
else {text = `${prefix}${selected}${suffix}`} } else {
text = `${prefix}${selected}${suffix}`;
changes.push({ from, to, insert: text }); selection = { anchor: from, head: from + text.length };
} }
view.dispatch({ view.dispatch({
changes changes : { from, to, insert: text },
selection
}); });
return true; return true;
}; };
const makeNbsp = (view) => { const makeNbsp = (view)=>{
const { from } = view.state.selection.main; const { from } = view.state.selection.main;
const prev2 = from >= 2 const prev2 = from >= 2
? view.state.doc.sliceString(from - 2, from) ? view.state.doc.sliceString(from - 2, from)
: ''; : '';
const insert = (prev2 === ':>' || prev2 === '>>') ? '>' : ':>'; const insert = (prev2 === ':>' || prev2 === '>>') ? '>' : ':>';
view.dispatch({ view.dispatch({
changes : { from, to: from, insert }, changes : { from, to: from, insert },
selection : { anchor: from + insert.length }, selection : { anchor: from + insert.length },
}); });
return true; return true;
}; };
const makeSpace = (view)=>{ const makeSpace = (view)=>{
@@ -190,13 +179,17 @@ const newPage = (view)=>{
}; };
export const generalKeymap = Prec.high(keymap.of([ export const generalKeymap = Prec.high(keymap.of([
{ key: 'Tab', run: insertTab }, { key: 'Tab', run: indentMore },
{ key: 'Mod-z', run: undo }, //i think it may be unnecessary { key: 'Mod-z', run: undo }, //i think it may be unnecessary
{ key: 'Mod-Shift-z', run: redo }, { key: 'Mod-Shift-z', run: redo },
{ key: 'Mod-y', run: redo }, { key: 'Mod-y', run: redo },
{ key: 'Mod-d', run: deleteLine }, { key: 'Mod-d', run: deleteLine },
])); ]));
export const cssKeymap = Prec.highest(keymap.of([
{ key: 'Mod-Shift-f', run: formatCSS },
]));
export const markdownKeymap = Prec.highest(keymap.of([ export const markdownKeymap = Prec.highest(keymap.of([
//{ key: 'Shift-Tab', run: indentMore }, //{ key: 'Shift-Tab', run: indentMore },
{ key: 'Shift-Tab', run: indentLess }, { key: 'Shift-Tab', run: indentLess },
@@ -222,5 +215,4 @@ export const markdownKeymap = Prec.highest(keymap.of([
{ key: 'Shift-Mod-6', run: makeHeader(6) }, { key: 'Shift-Mod-6', run: makeHeader(6) },
{ key: 'Mod-Enter', run: newPage }, { key: 'Mod-Enter', run: newPage },
{ key: 'Shift-Mod-Enter', run: newColumn }, { key: 'Shift-Mod-Enter', run: newColumn },
{ key: 'Mod-Shift-f', run: formatCSS },
])); ]));