mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-29 16:28:10 +00:00
proper use of tab
This commit is contained in:
@@ -165,7 +165,7 @@ const CodeEditor = forwardRef(
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
history(),
|
history(),
|
||||||
keymap.of([...defaultKeymap, customKeymap, foldKeymap, ...searchKeymap]),
|
|
||||||
updateListener,
|
updateListener,
|
||||||
EditorView.lineWrapping,
|
EditorView.lineWrapping,
|
||||||
scrollPastEnd(),
|
scrollPastEnd(),
|
||||||
@@ -186,6 +186,8 @@ const CodeEditor = forwardRef(
|
|||||||
themeCompartment.of(themeExtension),
|
themeCompartment.of(themeExtension),
|
||||||
...(tab !== 'brewStyles' ? [autocompleteEmoji] : []),
|
...(tab !== 'brewStyles' ? [autocompleteEmoji] : []),
|
||||||
search(),
|
search(),
|
||||||
|
keymap.of([...defaultKeymap, foldKeymap, ...searchKeymap]),
|
||||||
|
customKeymap
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,17 @@
|
|||||||
import { keymap } from '@codemirror/view';
|
import { keymap } from '@codemirror/view';
|
||||||
import { undo, redo } from '@codemirror/commands';
|
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 indentMore = (view)=>{
|
||||||
const { from, to } = view.state.selection.main;
|
const { from, to } = view.state.selection.main;
|
||||||
const lines = [];
|
const lines = [];
|
||||||
@@ -199,6 +210,7 @@ const newPage = (view)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const customKeymap = keymap.of([
|
export const customKeymap = keymap.of([
|
||||||
|
{ key: 'Tab', run: insertTabAtCursor },
|
||||||
{ key: 'Shift-Tab', run: indentMore },
|
{ key: 'Shift-Tab', run: indentMore },
|
||||||
{ key: 'Mod-Shift-Tab', run: indentLess },
|
{ key: 'Mod-Shift-Tab', run: indentLess },
|
||||||
{ key: 'Mod-b', run: makeBold },
|
{ key: 'Mod-b', run: makeBold },
|
||||||
|
|||||||
Reference in New Issue
Block a user