0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-05-08 01:18:38 +00:00

simple formatter

This commit is contained in:
Víctor Losada Hernández
2026-04-02 18:40:56 +02:00
parent 84d32a70f9
commit 950f6a79c5
3 changed files with 349 additions and 327 deletions
@@ -1,6 +1,26 @@
/* eslint max-lines: ["error", { "max": 300 }] */
import { keymap } from '@codemirror/view';
import { undo, redo } from '@codemirror/commands';
import * as prettier from "prettier/standalone";
import * as postcssPlugin from "prettier/plugins/postcss";
async function formatCSS(view) {
const code = view.state.doc.toString();
const formatted = await prettier.format(code, {
parser: "css",
plugins: [postcssPlugin]
});
view.dispatch({
changes: {
from: 0,
to: view.state.doc.length,
insert: formatted
}
});
}
const insertTabAtCursor = (view)=>{
const { from } = view.state.selection.main;
@@ -235,4 +255,5 @@ export default keymap.of([
{ key: 'Mod-Enter', run: newPage },
{ key: 'Mod-z', run: undo }, //i think it may be unnecessary
{ key: 'Mod-Shift-z', run: redo },
{ key: 'alt-Shift-f', run: formatCSS },
]);