mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-27 10:18:11 +00:00
update key map
This commit is contained in:
@@ -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 },
|
||||||
|
|||||||
Reference in New Issue
Block a user