2018-04-26 19:04:40 +03:00
|
|
|
import Browser from 'mobiledoc-kit/utils/browser';
|
|
|
|
|
2018-01-30 13:58:28 +03:00
|
|
|
// Key commands will run any time a particular key or key combination is pressed
|
|
|
|
// https://github.com/bustlelabs/mobiledoc-kit#configuring-hot-keys
|
|
|
|
|
2018-04-26 19:04:40 +03:00
|
|
|
export const DEFAULT_KEY_COMMANDS = [{
|
|
|
|
str: 'SHIFT+ENTER',
|
|
|
|
run(editor) {
|
|
|
|
if (!editor.range.headSection.isMarkerable) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-10 17:34:12 +03:00
|
|
|
|
2018-04-26 19:04:40 +03:00
|
|
|
editor.run((postEditor) => {
|
|
|
|
let softReturn = postEditor.builder.createAtom('soft-return');
|
|
|
|
postEditor.insertMarkers(editor.range.head, [softReturn]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
str: 'CTRL+K',
|
|
|
|
run(editor, koenig) {
|
|
|
|
if (Browser.isWin()) {
|
|
|
|
return koenig.send('editLink', editor.range);
|
2018-01-30 13:58:28 +03:00
|
|
|
}
|
2018-04-26 19:04:40 +03:00
|
|
|
|
|
|
|
// default behaviour for Mac is delete to end of section
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
str: 'META+K',
|
|
|
|
run(editor, koenig) {
|
|
|
|
return koenig.send('editLink', editor.range);
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
export default function registerKeyCommands(editor, koenig) {
|
|
|
|
DEFAULT_KEY_COMMANDS.forEach((keyCommand) => {
|
|
|
|
editor.registerKeyCommand({
|
|
|
|
str: keyCommand.str,
|
|
|
|
run() {
|
|
|
|
keyCommand.run(editor, koenig);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2018-01-30 13:58:28 +03:00
|
|
|
}
|