0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-05-07 16:38:38 +00:00

fix tab indent issue

This commit is contained in:
Víctor Losada Hernández
2026-04-13 17:27:06 +02:00
parent 1659c4b45a
commit 0208550ca3
+3 -22
View File
@@ -1,26 +1,6 @@
/* eslint max-lines: ["error", { "max": 300 }] */
import { keymap } from '@codemirror/view';
import { undo, redo } from '@codemirror/commands';
const insertTabAtCursor = (view)=>{
const { from } = view.state.selection.main;
view.dispatch({
changes : { from, insert: ' ' },
selection : { anchor: from + 1 }
});
return true;
};
const indentMore = (view)=>{
const { from, to } = view.state.selection.main;
const lines = [];
for (let l = view.state.doc.lineAt(from).number; l <= view.state.doc.lineAt(to).number; l++) {
const line = view.state.doc.line(l);
lines.push({ from: line.from, to: line.from, insert: ' ' }); // 2 spaces for tab
}
view.dispatch({ changes: lines });
return true;
};
import { undo, redo, indentMore } from '@codemirror/commands';
const indentLess = (view)=>{
const { from, to } = view.state.selection.main;
@@ -208,7 +188,7 @@ const newPage = (view)=>{
};
export const generalKeymap = keymap.of([
{ key: 'Tab', run: insertTabAtCursor },
{ key: 'Tab', run: indentMore },
{ key: 'Mod-z', run: undo }, //i think it may be unnecessary
{ key: 'Mod-Shift-z', run: redo },
]);
@@ -238,4 +218,5 @@ export const markdownKeymap = keymap.of([
{ key: 'Shift-Mod-6', run: makeHeader(6) },
{ key: 'Shift-Mod-Enter', run: newColumn },
{ key: 'Mod-Enter', run: newPage },
]);