mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-05-09 20:38:40 +00:00
fix tab indent issue
This commit is contained in:
@@ -1,26 +1,6 @@
|
|||||||
/* eslint max-lines: ["error", { "max": 300 }] */
|
/* eslint max-lines: ["error", { "max": 300 }] */
|
||||||
import { keymap } from '@codemirror/view';
|
import { keymap } from '@codemirror/view';
|
||||||
import { undo, redo } from '@codemirror/commands';
|
import { undo, redo, indentMore } 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
const indentLess = (view)=>{
|
const indentLess = (view)=>{
|
||||||
const { from, to } = view.state.selection.main;
|
const { from, to } = view.state.selection.main;
|
||||||
@@ -208,7 +188,7 @@ const newPage = (view)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const generalKeymap = keymap.of([
|
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-z', run: undo }, //i think it may be unnecessary
|
||||||
{ key: 'Mod-Shift-z', run: redo },
|
{ 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-6', run: makeHeader(6) },
|
||||||
{ key: 'Shift-Mod-Enter', run: newColumn },
|
{ key: 'Shift-Mod-Enter', run: newColumn },
|
||||||
{ key: 'Mod-Enter', run: newPage },
|
{ key: 'Mod-Enter', run: newPage },
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user