Stackedit/res/shortcutMgr.js

283 lines
7.9 KiB
JavaScript
Raw Normal View History

2013-09-29 22:28:59 +00:00
define([
"underscore",
"eventMgr",
"settings",
2013-09-30 22:37:58 +00:00
"utils",
"text!html/settingsShortcutEntry.html",
], function(_, eventMgr, settings, utils, settingsShortcutEntryHTML) {
2013-09-29 22:28:59 +00:00
var shortcutMgr = {};
2013-09-30 00:16:01 +00:00
2013-09-29 22:28:59 +00:00
var shortcuts = {
'bold': {
title: 'Strong',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-B',
mac: 'Command-B|Ctrl-B',
},
isPageDown: true
},
'italic': {
2013-09-30 22:37:58 +00:00
title: 'Emphasis',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-I',
mac: 'Command-I|Ctrl-I',
},
isPageDown: true
},
'link': {
2013-09-30 22:37:58 +00:00
title: 'Hyperlink',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-L',
mac: 'Command-L|Ctrl-L',
},
isPageDown: true
},
'quote': {
2013-09-30 22:37:58 +00:00
title: 'Blockquote',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Q',
mac: 'Command-Q|Ctrl-Q',
},
isPageDown: true
},
'code': {
2013-09-30 22:37:58 +00:00
title: 'Code Sample',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-K',
mac: 'Command-K|Ctrl-K',
},
isPageDown: true
},
'image': {
2013-09-30 22:37:58 +00:00
title: 'Image',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-G',
mac: 'Command-G|Ctrl-G',
},
isPageDown: true
},
'olist': {
2013-09-30 22:37:58 +00:00
title: 'Numbered List',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-O',
mac: 'Command-O|Ctrl-O',
},
isPageDown: true
},
'ulist': {
2013-09-30 22:37:58 +00:00
title: 'Bulleted List',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-U',
mac: 'Command-U|Ctrl-U',
},
isPageDown: true
},
'heading': {
2013-09-30 22:37:58 +00:00
title: 'Heading',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-H',
mac: 'Command-H|Ctrl-H',
},
isPageDown: true
},
'hr': {
2013-09-30 22:37:58 +00:00
title: 'Horizontal Rule',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-R',
mac: 'Command-R|Ctrl-R',
},
isPageDown: true
},
'undo': {
2013-09-30 22:37:58 +00:00
title: 'Undo',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Z',
mac: 'Command-Z',
},
exec: function(editor) {
editor.undo();
},
isPageDown: true
},
'redo': {
title: 'Redo',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-30 22:37:58 +00:00
win: 'Ctrl-Y|Ctrl-Shift-Z',
mac: 'Command-Y|Command-Shift-Z',
2013-09-29 22:28:59 +00:00
},
exec: function(editor) {
editor.redo();
},
isPageDown: true
},
'selectall': {
title: 'Select All',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-A',
mac: 'Command-A',
},
exec: function(editor) {
editor.selectAll();
},
readOnly: true
},
'removeline': {
title: 'Remove Line',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-D',
mac: 'Command-D',
},
exec: function(editor) {
editor.removeLines();
},
multiSelectAction: "forEachLine"
},
'duplicateSelection': {
title: 'Duplicate Selection',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Shift-D',
mac: 'Command-Shift-D',
},
exec: function(editor) {
editor.duplicateSelection();
},
multiSelectAction: "forEach"
},
'sortlines': {
title: 'Sort Lines',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Alt-S',
mac: 'Command-Alt-S',
},
exec: function(editor) {
editor.sortLines();
},
multiSelectAction: "forEachLine"
},
'modifyNumberUp': {
title: 'Number Up',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Shift-Up',
mac: 'Alt-Shift-Up',
},
exec: function(editor) {
editor.modifyNumber(1);
},
multiSelectAction: "forEach"
},
'modifyNumberDown': {
title: 'Number Down',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Shift-Down',
mac: 'Alt-Shift-Down',
},
exec: function(editor) {
editor.modifyNumber(-1);
},
multiSelectAction: "forEach"
},
'find': {
title: 'Find',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-F',
mac: 'Command-F',
},
exec: function(editor) {
var config = require("ace/config");
config.loadModule("ace/ext/searchbox", function(e) {
2013-09-30 00:16:01 +00:00
e.Search(editor);
2013-09-29 22:28:59 +00:00
});
},
readOnly: true
},
'replace': {
title: 'Replace',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Shift-F',
mac: 'Command-Option-F',
},
exec: function(editor) {
var config = require("ace/config");
2013-09-30 00:16:01 +00:00
config.loadModule("ace/ext/searchbox", function(e) {
e.Search(editor, true);
});
2013-09-29 22:28:59 +00:00
},
readOnly: true
},
2013-09-30 22:37:58 +00:00
'findnext': {
title: 'Find Next',
defaultKey: {
win: 'Ctrl-P',
mac: 'Command-P',
},
exec: function(editor) {
editor.findNext();
},
readOnly: true
},
'findprevious': {
title: 'Find Previous',
defaultKey: {
win: 'Ctrl-Shift-P',
mac: 'Command-Shift-P',
},
exec: function(editor) {
editor.findPrevious();
},
readOnly: true
},
2013-09-29 22:28:59 +00:00
'togglerecording': {
title: 'Toggle Recording',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Alt-E',
mac: 'Command-Option-E',
},
exec: function(editor) {
editor.commands.toggleRecording(editor);
},
readOnly: true
},
'replaymacro': {
title: 'Replay Macro',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Shift-E',
mac: 'Command-Shift-E',
},
exec: function(editor) {
editor.commands.replay(editor);
},
readOnly: true
},
};
2013-09-30 00:16:01 +00:00
2013-09-29 22:28:59 +00:00
_.each(shortcuts, function(shortcut, key) {
2013-09-30 00:16:01 +00:00
shortcut.name = key;
shortcut.bindKey = settings.shortcuts[key] || shortcut.defaultKey;
2013-09-29 22:28:59 +00:00
});
2013-09-30 00:16:01 +00:00
shortcutMgr.configureAce = function(aceEditor) {
_.each(shortcuts, function(shortcut) {
shortcut.exec && aceEditor.commands.addCommand(_.pick(shortcut, 'name', 'bindKey', 'exec', 'readOnly', 'multiSelectAction'));
});
2013-09-29 22:28:59 +00:00
};
2013-09-30 22:37:58 +00:00
shortcutMgr.addSettingEntries = function() {
var shortcutEntries = _.reduce(shortcuts, function(result, shortcut) {
return result + _.template(settingsShortcutEntryHTML, {
shortcut: shortcut
});
}, '');
var settingsFormElement = document.querySelector('#tabpane-settings-shortcuts .form-horizontal');
settingsFormElement && (settingsFormElement.innerHTML = shortcutEntries);
};
shortcutMgr.loadSettings = function() {
_.each(shortcuts, function(shortcut) {
utils.setInputValue("#input-settings-shortcut-" + shortcut.name, shortcut.bindKey.win);
utils.setInputValue("#input-settings-shortcut-" + shortcut.name + '-mac', shortcut.bindKey.mac);
});
};
2013-09-29 22:28:59 +00:00
return shortcutMgr;
});