Keyboard shortcut settings

This commit is contained in:
benweet 2013-09-30 01:16:01 +01:00
parent 8ef1e6ae3b
commit 1229f9f06d
4 changed files with 86 additions and 49 deletions

View File

@ -6,6 +6,7 @@ define([
"utils", "utils",
"settings", "settings",
"eventMgr", "eventMgr",
"shortcutMgr",
"mousetrap", "mousetrap",
"text!html/bodyIndex.html", "text!html/bodyIndex.html",
"text!html/bodyViewer.html", "text!html/bodyViewer.html",
@ -21,7 +22,7 @@ define([
'ace/ext/spellcheck', 'ace/ext/spellcheck',
'ace/ext/searchbox' 'ace/ext/searchbox'
], function($, _, crel, ace, utils, settings, eventMgr, mousetrap, bodyIndexHTML, bodyViewerHTML, settingsTemplateTooltipHTML, settingsUserCustomExtensionTooltipHTML) { ], function($, _, crel, ace, utils, settings, eventMgr, shortcutMgr, mousetrap, bodyIndexHTML, bodyViewerHTML, settingsTemplateTooltipHTML, settingsUserCustomExtensionTooltipHTML) {
var core = {}; var core = {};
@ -58,9 +59,9 @@ define([
} }
if(windowId === undefined) { if(windowId === undefined) {
windowId = utils.randomString(); windowId = utils.randomString();
localStorage["frontWindowId"] = windowId; localStorage.frontWindowId = windowId;
} }
var frontWindowId = localStorage["frontWindowId"]; var frontWindowId = localStorage.frontWindowId;
if(frontWindowId != windowId) { if(frontWindowId != windowId) {
windowUnique = false; windowUnique = false;
if(intervalId !== undefined) { if(intervalId !== undefined) {
@ -260,7 +261,7 @@ define([
// only check every 5 lines // only check every 5 lines
processedLines++; processedLines++;
if((processedLines % 5 == 0) && (new Date() - workerStart) > 20) { if((processedLines % 5 === 0) && (new Date() - workerStart) > 20) {
self.running = setTimeout(customWorker, 20); // benweet self.running = setTimeout(customWorker, 20); // benweet
self.currentLine = currentLine; self.currentLine = currentLine;
return; return;
@ -271,7 +272,6 @@ define([
if(startLine <= endLine) if(startLine <= endLine)
self.fireUpdateEvent(startLine, endLine); self.fireUpdateEvent(startLine, endLine);
} }
;
self.$worker = function() { self.$worker = function() {
self.lines.splice(0, self.lines.length); self.lines.splice(0, self.lines.length);
self.states.splice(0, self.states.length); self.states.splice(0, self.states.length);
@ -281,10 +281,12 @@ define([
})(aceEditor.session.bgTokenizer); })(aceEditor.session.bgTokenizer);
shortcutMgr.configureAce(aceEditor);
eventMgr.onAceCreated(aceEditor); eventMgr.onAceCreated(aceEditor);
} }
// Create the layout // Create the layout
var $editorButtonsElt = undefined;
function createLayout() { function createLayout() {
var layoutGlobalConfig = { var layoutGlobalConfig = {
closable: true, closable: true,
@ -340,7 +342,7 @@ define([
$(".preview-container").html('<div id="preview-contents"><div id="wmd-preview" class="preview-content"></div></div>'); $(".preview-container").html('<div id="preview-contents"><div id="wmd-preview" class="preview-content"></div></div>');
layout = $('body').layout($.extend(layoutGlobalConfig, { layout = $('body').layout($.extend(layoutGlobalConfig, {
east__resizable: true, east__resizable: true,
east__size: .5, east__size: 0.5,
east__minSize: 260 east__minSize: 260
})); }));
} }
@ -349,7 +351,7 @@ define([
$(".preview-container").html('<div id="preview-contents"><div id="wmd-preview" class="preview-content"></div></div>'); $(".preview-container").html('<div id="preview-contents"><div id="wmd-preview" class="preview-content"></div></div>');
layout = $('body').layout($.extend(layoutGlobalConfig, { layout = $('body').layout($.extend(layoutGlobalConfig, {
south__resizable: true, south__resizable: true,
south__size: .5, south__size: 0.5,
south__minSize: 200 south__minSize: 200
})); }));
} }
@ -367,7 +369,7 @@ define([
// north resizer is very small // north resizer is very small
// var $previewButtonsContainerElt = $('<div // var $previewButtonsContainerElt = $('<div
// class="preview-button-container">'); // class="preview-button-container">');
$resizerDecorator = $('<div class="resizer-decorator">'); var $resizerDecorator = $('<div class="resizer-decorator">');
$previewButtonsElt = $('<div class="extension-preview-buttons">'); $previewButtonsElt = $('<div class="extension-preview-buttons">');
$editorButtonsElt = $('<div class="extension-editor-buttons">'); $editorButtonsElt = $('<div class="extension-editor-buttons">');
if(viewerMode || settings.layoutOrientation == "horizontal") { if(viewerMode || settings.layoutOrientation == "horizontal") {

View File

@ -48,6 +48,7 @@ define([
'</html>' '</html>'
].join(""), ].join(""),
sshProxy: SSH_PROXY_URL, sshProxy: SSH_PROXY_URL,
shortcuts: {},
extensionSettings: {} extensionSettings: {}
}; };

View File

@ -9,87 +9,87 @@ define([
var shortcuts = { var shortcuts = {
'bold': { 'bold': {
title: 'Strong', title: 'Strong',
defaults: { defaultKey: {
win: 'Ctrl-B', win: 'Ctrl-B',
mac: 'Command-B|Ctrl-B', mac: 'Command-B|Ctrl-B',
}, },
isPageDown: true isPageDown: true
}, },
'italic': { 'italic': {
title: 'Emphasis', name: 'Emphasis',
defaults: { defaultKey: {
win: 'Ctrl-I', win: 'Ctrl-I',
mac: 'Command-I|Ctrl-I', mac: 'Command-I|Ctrl-I',
}, },
isPageDown: true isPageDown: true
}, },
'link': { 'link': {
title: 'Hyperlink', name: 'Hyperlink',
defaults: { defaultKey: {
win: 'Ctrl-L', win: 'Ctrl-L',
mac: 'Command-L|Ctrl-L', mac: 'Command-L|Ctrl-L',
}, },
isPageDown: true isPageDown: true
}, },
'quote': { 'quote': {
title: 'Blockquote', name: 'Blockquote',
defaults: { defaultKey: {
win: 'Ctrl-Q', win: 'Ctrl-Q',
mac: 'Command-Q|Ctrl-Q', mac: 'Command-Q|Ctrl-Q',
}, },
isPageDown: true isPageDown: true
}, },
'code': { 'code': {
title: 'Code Sample', name: 'Code Sample',
defaults: { defaultKey: {
win: 'Ctrl-K', win: 'Ctrl-K',
mac: 'Command-K|Ctrl-K', mac: 'Command-K|Ctrl-K',
}, },
isPageDown: true isPageDown: true
}, },
'image': { 'image': {
title: 'Image', name: 'Image',
defaults: { defaultKey: {
win: 'Ctrl-G', win: 'Ctrl-G',
mac: 'Command-G|Ctrl-G', mac: 'Command-G|Ctrl-G',
}, },
isPageDown: true isPageDown: true
}, },
'olist': { 'olist': {
title: 'Numbered List', name: 'Numbered List',
defaults: { defaultKey: {
win: 'Ctrl-O', win: 'Ctrl-O',
mac: 'Command-O|Ctrl-O', mac: 'Command-O|Ctrl-O',
}, },
isPageDown: true isPageDown: true
}, },
'ulist': { 'ulist': {
title: 'Bulleted List', name: 'Bulleted List',
defaults: { defaultKey: {
win: 'Ctrl-U', win: 'Ctrl-U',
mac: 'Command-U|Ctrl-U', mac: 'Command-U|Ctrl-U',
}, },
isPageDown: true isPageDown: true
}, },
'heading': { 'heading': {
title: 'Heading', name: 'Heading',
defaults: { defaultKey: {
win: 'Ctrl-H', win: 'Ctrl-H',
mac: 'Command-H|Ctrl-H', mac: 'Command-H|Ctrl-H',
}, },
isPageDown: true isPageDown: true
}, },
'hr': { 'hr': {
title: 'Horizontal Rule', name: 'Horizontal Rule',
defaults: { defaultKey: {
win: 'Ctrl-R', win: 'Ctrl-R',
mac: 'Command-R|Ctrl-R', mac: 'Command-R|Ctrl-R',
}, },
isPageDown: true isPageDown: true
}, },
'undo': { 'undo': {
title: 'Undo', name: 'Undo',
defaults: { defaultKey: {
win: 'Ctrl-Z', win: 'Ctrl-Z',
mac: 'Command-Z', mac: 'Command-Z',
}, },
@ -100,7 +100,7 @@ define([
}, },
'redo': { 'redo': {
title: 'Redo', title: 'Redo',
defaults: { defaultKey: {
win: 'Ctrl-Shift-Z|Ctrl-Y', win: 'Ctrl-Shift-Z|Ctrl-Y',
mac: 'Command-Shift-Z|Command-Y', mac: 'Command-Shift-Z|Command-Y',
}, },
@ -111,7 +111,7 @@ define([
}, },
'selectall': { 'selectall': {
title: 'Select All', title: 'Select All',
defaults: { defaultKey: {
win: 'Ctrl-A', win: 'Ctrl-A',
mac: 'Command-A', mac: 'Command-A',
}, },
@ -122,7 +122,7 @@ define([
}, },
'removeline': { 'removeline': {
title: 'Remove Line', title: 'Remove Line',
defaults: { defaultKey: {
win: 'Ctrl-D', win: 'Ctrl-D',
mac: 'Command-D', mac: 'Command-D',
}, },
@ -133,7 +133,7 @@ define([
}, },
'duplicateSelection': { 'duplicateSelection': {
title: 'Duplicate Selection', title: 'Duplicate Selection',
defaults: { defaultKey: {
win: 'Ctrl-Shift-D', win: 'Ctrl-Shift-D',
mac: 'Command-Shift-D', mac: 'Command-Shift-D',
}, },
@ -144,7 +144,7 @@ define([
}, },
'sortlines': { 'sortlines': {
title: 'Sort Lines', title: 'Sort Lines',
defaults: { defaultKey: {
win: 'Ctrl-Alt-S', win: 'Ctrl-Alt-S',
mac: 'Command-Alt-S', mac: 'Command-Alt-S',
}, },
@ -155,7 +155,7 @@ define([
}, },
'indent': { 'indent': {
title: 'Sort Lines', title: 'Sort Lines',
defaults: { defaultKey: {
win: 'Ctrl-Alt-S', win: 'Ctrl-Alt-S',
mac: 'Command-Alt-S', mac: 'Command-Alt-S',
}, },
@ -166,7 +166,7 @@ define([
}, },
'modifyNumberUp': { 'modifyNumberUp': {
title: 'Number Up', title: 'Number Up',
defaults: { defaultKey: {
win: 'Ctrl-Shift-Up', win: 'Ctrl-Shift-Up',
mac: 'Alt-Shift-Up', mac: 'Alt-Shift-Up',
}, },
@ -177,7 +177,7 @@ define([
}, },
'modifyNumberDown': { 'modifyNumberDown': {
title: 'Number Down', title: 'Number Down',
defaults: { defaultKey: {
win: 'Ctrl-Shift-Down', win: 'Ctrl-Shift-Down',
mac: 'Alt-Shift-Down', mac: 'Alt-Shift-Down',
}, },
@ -188,33 +188,35 @@ define([
}, },
'find': { 'find': {
title: 'Find', title: 'Find',
defaults: { defaultKey: {
win: 'Ctrl-F', win: 'Ctrl-F',
mac: 'Command-F', mac: 'Command-F',
}, },
exec: function(editor) { exec: function(editor) {
var config = require("ace/config"); var config = require("ace/config");
config.loadModule("ace/ext/searchbox", function(e) { config.loadModule("ace/ext/searchbox", function(e) {
e.Search(editor) e.Search(editor);
}); });
}, },
readOnly: true readOnly: true
}, },
'replace': { 'replace': {
title: 'Replace', title: 'Replace',
defaults: { defaultKey: {
win: 'Ctrl-Shift-F', win: 'Ctrl-Shift-F',
mac: 'Command-Option-F', mac: 'Command-Option-F',
}, },
exec: function(editor) { exec: function(editor) {
var config = require("ace/config"); var config = require("ace/config");
config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)}); config.loadModule("ace/ext/searchbox", function(e) {
e.Search(editor, true);
});
}, },
readOnly: true readOnly: true
}, },
'togglerecording': { 'togglerecording': {
title: 'Toggle Recording', title: 'Toggle Recording',
defaults: { defaultKey: {
win: 'Ctrl-Alt-E', win: 'Ctrl-Alt-E',
mac: 'Command-Option-E', mac: 'Command-Option-E',
}, },
@ -225,7 +227,7 @@ define([
}, },
'replaymacro': { 'replaymacro': {
title: 'Replay Macro', title: 'Replay Macro',
defaults: { defaultKey: {
win: 'Ctrl-Shift-E', win: 'Ctrl-Shift-E',
mac: 'Command-Shift-E', mac: 'Command-Shift-E',
}, },
@ -237,11 +239,14 @@ define([
}; };
_.each(shortcuts, function(shortcut, key) { _.each(shortcuts, function(shortcut, key) {
shortcut.values = settings.shortcuts[key] || shortcut.defaults; shortcut.name = key;
shortcut.bindKey = settings.shortcuts[key] || shortcut.defaultKey;
}); });
shortcutMgr.configureAce = function() { shortcutMgr.configureAce = function(aceEditor) {
_.each(shortcuts, function(shortcut) {
shortcut.exec && aceEditor.commands.addCommand(_.pick(shortcut, 'name', 'bindKey', 'exec', 'readOnly', 'multiSelectAction'));
});
}; };
return shortcutMgr; return shortcutMgr;

View File

@ -1028,7 +1028,36 @@ ul,ol {
.ace_search { .ace_search {
background-color: @primary-bg; background-color: @primary-bg;
border: 0; border: 6px solid @panel-bg;
border-top: 0;
padding: 10px 15px 5px;
font-family: @font-family-base;
min-width: 318px;
.ace_search_field {
width: 200px;
}
.ace_replacebtn {
padding: 0 4px;
}
.ace_searchbtn_close {
background: transparent;
margin: 0;
font-size: (@font-size-base * 1.5);
font-weight: @close-font-weight;
text-shadow: @close-text-shadow;
.opacity(.3);
&:before {
content: '\d7';
}
&:hover,
&:focus {
color: @close-color;
text-decoration: none;
cursor: pointer;
.opacity(.5);
background: transparent;
}
}
} }
#wmd-input { #wmd-input {