Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split shortcuts by platform and name them #591

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 57 additions & 43 deletions src/js/editor/key-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,102 +38,116 @@ function deleteToEndOfSection(editor) {
});
}

export const DEFAULT_KEY_COMMANDS = [{
const MAC_KEY_COMMANDS = [{
str: 'META+B',
name: 'default-bold',
run(editor) {
editor.toggleMarkup('strong');
}
}, {
str: 'CTRL+B',
str: 'META+I',
name: 'default-italic',
run(editor) {
editor.toggleMarkup('strong');
editor.toggleMarkup('em');
}
}, {
str: 'META+I',
str: 'META+U',
name: 'default-underline',
run(editor) {
editor.toggleMarkup('em');
editor.toggleMarkup('u');
}
}, {
str: 'CTRL+I',
str: 'META+K',
name: 'default-link',
run(editor) {
editor.toggleMarkup('em');
return toggleLink(editor);
}
}, {
str: 'META+U',
str: 'META+A',
name: 'default-select-all',
run(editor) {
editor.toggleMarkup('u');
selectAll(editor);
}
}, {
str: 'CTRL+U',
str: 'META+Z',
name: 'default-undo',
run(editor) {
editor.toggleMarkup('u');
editor.run(postEditor => postEditor.undoLastChange());
}
}, {
str: 'META+SHIFT+Z',
name: 'default-redo',
run(editor) {
editor.run(postEditor => postEditor.redoLastChange());
}
}, {
str: 'CTRL+K',
name: 'default-delete-line',
run(editor) {
if (Browser.isMac()) {
return deleteToEndOfSection(editor);
} else if (Browser.isWin()) {
return toggleLink(editor);
}
return deleteToEndOfSection(editor);
}
}, {
str: 'CTRL+A',
name: 'default-goto-line-start',
run(editor) {
if (Browser.isMac()) {
gotoStartOfLine(editor);
} else {
selectAll(editor);
}
gotoStartOfLine(editor);
}
}, {
str: 'META+A',
str: 'CTRL+E',
name: 'default-goto-line-end',
run(editor) {
gotoEndOfLine(editor);
}
}];

const WINDOWS_KEY_COMMANDS = [{
str: 'CTRL+B',
name: 'default-bold',
run(editor) {
if (Browser.isMac()) {
selectAll(editor);
}
editor.toggleMarkup('strong');
}
}, {
str: 'CTRL+E',
str: 'CTRL+I',
name: 'default-italic',
run(editor) {
if (Browser.isMac()) {
gotoEndOfLine(editor);
}
editor.toggleMarkup('em');
}
}, {
str: 'META+K',
str: 'CTRL+U',
name: 'default-underline',
run(editor) {
return toggleLink(editor);
},

editor.toggleMarkup('u');
}
}, {
str: 'META+Z',
str: 'CTRL+K',
name: 'default-link',
run(editor) {
editor.run(postEditor => {
postEditor.undoLastChange();
});
return toggleLink(editor);
}
}, {
str: 'META+SHIFT+Z',
str: 'CTRL+A',
name: 'default-select-all',
run(editor) {
editor.run(postEditor => {
postEditor.redoLastChange();
});
selectAll(editor);
}
}, {
str: 'CTRL+Z',
name: 'default-undo',
run(editor) {
if (Browser.isMac()) { return false; }
editor.run(postEditor => postEditor.undoLastChange());
}
}, {
str: 'CTRL+SHIFT+Z',
name: 'default-redo',
run(editor) {
if (Browser.isMac()) { return false; }
editor.run(postEditor => postEditor.redoLastChange());
}
}];

export const DEFAULT_KEY_COMMANDS = (Browser.isMac() && MAC_KEY_COMMANDS)
|| (Browser.isWin() && WINDOWS_KEY_COMMANDS)
|| [];

function modifierNamesToMask(modiferNames) {
let defaultVal = 0;
return reduce(modiferNames,
Expand Down