@codemirror/view#KeyBinding TypeScript Examples
The following examples show how to use
@codemirror/view#KeyBinding.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From pintora with MIT License | 7 votes |
tabKeymaps: KeyBinding[] = [
{
key: 'Tab',
run(view) {
const { dispatch, state } = view
const { from, to } = state.selection.main
const hasCrossRowSelection = state.sliceDoc(from, to).includes(state.lineBreak)
if (hasCrossRowSelection) {
indentMore(view)
} else {
dispatch(
state.update(state.replaceSelection(getSoftTabChars(state.tabSize)), {
scrollIntoView: true,
userEvent: 'input',
}),
)
}
return true
},
},
{
key: 'Shift-Tab',
run(view) {
return indentLess(view)
},
},
]
Example #2
Source File: editor.tsx From nota with MIT License | 6 votes |
insertCommandAtCursor = (key: string, cmd: string): KeyBinding => ({
key,
run({ state, dispatch }) {
let changes = state.changeByRange(range => {
let anchor = range.from + 2 + cmd.length;
if (range.empty) {
return {
changes: [
{
from: range.from,
insert: `@${cmd}{}`,
},
],
range: EditorSelection.cursor(anchor),
};
} else {
let changes = [
{
from: range.from,
insert: `@${cmd}{`,
},
{
from: range.to,
insert: `}`,
},
];
return {
changes,
range: EditorSelection.range(anchor, anchor + range.head - range.anchor),
};
}
});
dispatch(state.update(changes));
return true;
},
})
Example #3
Source File: editor.tsx From nota with MIT License | 6 votes |
keyBindings: KeyBinding[] = [
insertCommandAtCursor("Mod-b", "strong"),
insertCommandAtCursor("Mod-i", "em"),
insertCommandAtCursor("Mod-u", "u"),
insertCommandAtCursor("Mod-k", "a"),
insertCommandAtCursor("Ctrl-1", "Section"),
insertCommandAtCursor("Ctrl-2", "Subsection"),
insertCommandAtCursor("Ctrl-3", "Subsubsection"),
]