defaultKeymap top-level property
Default keymap with additional editing commands.
Includes all of standardKeymap plus:
- Alt-ArrowUp: moveLineUp
- Alt-ArrowDown: moveLineDown
- Shift-Alt-ArrowUp: copyLineUp
- Shift-Alt-ArrowDown: copyLineDown
- Escape: simplifySelection
- Mod-Enter: create blank line below
- Alt-l (Ctrl-l on Mac): selectLine
- Mod-[: indentLess
- Mod-]: indentMore
- Shift-Mod-k: deleteLine
Implementation
final List<KeyBinding> defaultKeymap = [
// Line movement
KeyBinding(key: 'Alt-ArrowUp', run: _stateCmd(moveLineUp)),
KeyBinding(key: 'Alt-ArrowDown', run: _stateCmd(moveLineDown)),
// Line copying
KeyBinding(key: 'Shift-Alt-ArrowUp', run: _stateCmd(copyLineUp)),
KeyBinding(key: 'Shift-Alt-ArrowDown', run: _stateCmd(copyLineDown)),
// Simplify selection
KeyBinding(key: 'Escape', run: _stateCmd(simplifySelection)),
// Blank line
KeyBinding(key: 'Mod-Enter', run: _stateCmd((target) {
if (target.state.isReadOnly) return false;
final state = target.state;
final line = state.doc.lineAt(state.selection.main.head);
target.dispatch(state.update([
TransactionSpec(
changes: ChangeSpec(from: line.to, insert: state.lineBreak),
selection: EditorSelection.single(line.to + 1),
scrollIntoView: true,
userEvent: 'input',
),
]));
return true;
})),
// Select line
KeyBinding(key: 'Alt-l', mac: 'Ctrl-l', run: _stateCmd(selectLine)),
// Indentation
KeyBinding(key: 'Mod-[', run: _stateCmd(indentLess)),
KeyBinding(key: 'Mod-]', run: _stateCmd(indentMore)),
// Delete line
KeyBinding(key: 'Shift-Mod-k', run: _stateCmd(deleteLine)),
// Include all standard bindings
...standardKeymap,
];