0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-27 05:58:10 +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'; import { keymap } from '@codemirror/view';
const indentMore = (view) => { const indentMore = (view)=>{
const { from, to } = view.state.selection.main; const { from, to } = view.state.selection.main;
const lines = []; const lines = [];
for (let l = view.state.doc.lineAt(from).number; l <= view.state.doc.lineAt(to).number; l++) { 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 line = view.state.doc.line(l);
lines.push({ from: line.from, to: line.from, insert: ' ' }); // 2 spaces for tab lines.push({ from: line.from, to: line.from, insert: ' ' }); // 2 spaces for tab
} }
view.dispatch({ changes: lines }); view.dispatch({ changes: lines });
return true; 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 = [];
for (let l = view.state.doc.lineAt(from).number; l <= view.state.doc.lineAt(to).number; l++) { 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 line = view.state.doc.line(l);
const match = line.text.match(/^ {1,2}/); // match up to 2 spaces const match = line.text.match(/^ {1,2}/); // match up to 2 spaces
if (match) { if(match) {
lines.push({ from: line.from, to: line.from + match[0].length, insert: '' }); lines.push({ from: line.from, to: line.from + match[0].length, insert: '' });
} }
} }
if (lines.length > 0) view.dispatch({ changes: lines }); if(lines.length > 0) view.dispatch({ changes: lines });
return true; return true;
}; };
const makeBold = (view)=>{ const makeBold = (view)=>{
@@ -197,8 +197,8 @@ const newPage = (view)=>{
}; };
export const customKeymap = keymap.of([ export const customKeymap = keymap.of([
{ key: 'Tab', run: indentMore }, { key: 'Shift-Tab', run: indentMore },
{ key: 'Shift-Tab', run: indentLess }, { key: 'Mod-Shift-Tab', run: indentLess },
{ key: 'Mod-b', run: makeBold }, { key: 'Mod-b', run: makeBold },
{ key: 'Mod-i', run: makeItalic }, { key: 'Mod-i', run: makeItalic },
{ key: 'Mod-u', run: makeUnderline }, { key: 'Mod-u', run: makeUnderline },