0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-27 03:48:14 +00:00

update key map

This commit is contained in:
Víctor Losada Hernández
2026-03-26 17:19:54 +01:00
parent 3a671cf48f
commit 96e1d6e100

View File

@@ -1,28 +1,28 @@
import { keymap } from '@codemirror/view';
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 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 { 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);
const match = line.text.match(/^ {1,2}/); // match up to 2 spaces
if (match) {
lines.push({ from: line.from, to: line.from + match[0].length, insert: '' });
}
}
if (lines.length > 0) view.dispatch({ changes: lines });
return true;
const indentLess = (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);
const match = line.text.match(/^ {1,2}/); // match up to 2 spaces
if(match) {
lines.push({ from: line.from, to: line.from + match[0].length, insert: '' });
}
}
if(lines.length > 0) view.dispatch({ changes: lines });
return true;
};
const makeBold = (view)=>{
@@ -197,8 +197,8 @@ const newPage = (view)=>{
};
export const customKeymap = keymap.of([
{ key: 'Tab', run: indentMore },
{ key: 'Shift-Tab', run: indentLess },
{ key: 'Shift-Tab', run: indentMore },
{ key: 'Mod-Shift-Tab', run: indentLess },
{ key: 'Mod-b', run: makeBold },
{ key: 'Mod-i', run: makeItalic },
{ key: 'Mod-u', run: makeUnderline },