Added shortcuts extension
This commit is contained in:
parent
a608c2e0fe
commit
6b5014b6f7
@ -111,6 +111,8 @@ define([
|
||||
$themeInputElt.change();
|
||||
// Lazy rendering
|
||||
utils.setInputChecked("#input-settings-lazy-rendering", settings.lazyRendering);
|
||||
// Editor font class
|
||||
utils.setInputRadio("radio-settings-editor-font-class", settings.editorFontClass);
|
||||
// Editor font family
|
||||
utils.setInputValue("#input-settings-editor-font-family", settings.editorFontFamily);
|
||||
// Editor font size
|
||||
@ -157,6 +159,8 @@ define([
|
||||
var theme = utils.getInputValue($themeInputElt);
|
||||
// Lazy Rendering
|
||||
newSettings.lazyRendering = utils.getInputChecked("#input-settings-lazy-rendering");
|
||||
// Editor font class
|
||||
newSettings.editorFontClass = utils.getInputRadio("radio-settings-editor-font-class");
|
||||
// Editor font family
|
||||
newSettings.editorFontFamily = utils.getInputTextValue("#input-settings-editor-font-family", event);
|
||||
// Editor font size
|
||||
@ -280,7 +284,6 @@ define([
|
||||
|
||||
// Create the PageDown editor
|
||||
var pagedownEditor;
|
||||
var $editorElt;
|
||||
var fileDesc;
|
||||
core.initEditor = function(fileDescParam) {
|
||||
if(fileDesc !== undefined) {
|
||||
@ -401,10 +404,7 @@ define([
|
||||
// Create UI layout
|
||||
createLayout();
|
||||
|
||||
// Editor
|
||||
$editorElt = $('#wmd-input');
|
||||
|
||||
editor.init(document.querySelector('#wmd-input'), document.querySelector('.preview-container'));
|
||||
editor.init();
|
||||
|
||||
// Do periodic tasks
|
||||
intervalId = window.setInterval(function() {
|
||||
|
@ -39,8 +39,8 @@ define([
|
||||
setTimeout(refreshPreview, elapsedTime < 2000 ? elapsedTime : 2000);
|
||||
};
|
||||
})();
|
||||
eventMgr.addListener('onPagedownConfigure', function(editor) {
|
||||
pagedownEditor = editor;
|
||||
eventMgr.addListener('onPagedownConfigure', function(pagedownEditorParam) {
|
||||
pagedownEditor = pagedownEditorParam;
|
||||
});
|
||||
|
||||
eventMgr.addListener('onSectionsCreated', function(newSectionList) {
|
||||
@ -573,17 +573,16 @@ define([
|
||||
}
|
||||
editor.adjustCommentOffsets = adjustCommentOffsets;
|
||||
|
||||
editor.init = function(inputEltParam, previewEltParam) {
|
||||
inputElt = inputEltParam;
|
||||
editor.init = function() {
|
||||
inputElt = document.getElementById('wmd-input');
|
||||
$inputElt = $(inputElt);
|
||||
previewElt = previewEltParam;
|
||||
|
||||
contentElt = inputElt.querySelector('.editor-content');
|
||||
$contentElt = $(contentElt);
|
||||
editor.$contentElt = $contentElt;
|
||||
marginElt = inputElt.querySelector('.editor-margin');
|
||||
$marginElt = $(marginElt);
|
||||
editor.$marginElt = $marginElt;
|
||||
previewElt = document.querySelector('.preview-container');
|
||||
|
||||
$inputElt.addClass(settings.editorFontClass);
|
||||
|
||||
watcher.startWatching();
|
||||
|
||||
|
@ -35,6 +35,7 @@ define([
|
||||
"extensions/buttonHtmlCode",
|
||||
"extensions/buttonViewer",
|
||||
"extensions/welcomeTour",
|
||||
"extensions/shortcuts",
|
||||
"extensions/userCustom",
|
||||
"extensions/comments",
|
||||
"bootstrap",
|
||||
|
60
public/res/extensions/shortcuts.js
Normal file
60
public/res/extensions/shortcuts.js
Normal file
@ -0,0 +1,60 @@
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"utils",
|
||||
"mousetrap",
|
||||
"classes/Extension",
|
||||
"text!extensions/shortcutsDefaultMapping.js",
|
||||
"text!html/shortcutsSettingsBlock.html",
|
||||
], function($, _, utils, mousetrap, Extension, shortcutsDefaultMapping, shortcutsSettingsBlockHTML) {
|
||||
|
||||
var shortcuts = new Extension("shortcuts", "Shortcuts", true, true);
|
||||
shortcuts.settingsBlock = shortcutsSettingsBlockHTML;
|
||||
shortcuts.defaultConfig = {
|
||||
mapping: shortcutsDefaultMapping,
|
||||
};
|
||||
|
||||
var eventMgr;
|
||||
var clickPagedownButton;
|
||||
shortcuts.onEventMgrCreated = function(eventMgrParameter) {
|
||||
eventMgr = eventMgrParameter;
|
||||
eventMgr.addListener('onPagedownConfigure', function(pagedownEditor) {
|
||||
clickPagedownButton = function(buttonName) {
|
||||
pagedownEditor.uiManager.doClick(pagedownEditor.uiManager.buttons[buttonName]);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
shortcuts.onLoadSettings = function() {
|
||||
utils.setInputValue("#textarea-shortcuts-mapping", shortcuts.config.mapping);
|
||||
};
|
||||
|
||||
shortcuts.onSaveSettings = function(newConfig, event) {
|
||||
newConfig.code = utils.getInputValue("#textarea-shortcuts-mapping");
|
||||
try {
|
||||
/*jshint evil: true */
|
||||
eval('var test = ' + newConfig.code);
|
||||
}
|
||||
catch(e) {
|
||||
eventMgr.onError(e);
|
||||
// Mark the textarea as error
|
||||
utils.getInputTextValue("#textarea-shortcuts-mapping", event, /^$/);
|
||||
}
|
||||
};
|
||||
|
||||
shortcuts.onInit = function() {
|
||||
try {
|
||||
/*jshint evil: true */
|
||||
var shortcutMap;
|
||||
eval('shortcutMap = ' + shortcuts.config.mapping);
|
||||
_.each(shortcutMap, function(func, shortcut) {
|
||||
mousetrap.bind(shortcut, func);
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
return shortcuts;
|
||||
});
|
17
public/res/extensions/shortcutsDefaultMapping.js
Normal file
17
public/res/extensions/shortcutsDefaultMapping.js
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
'mod+r': function() {
|
||||
clickPagedownButton('hr');
|
||||
},
|
||||
'mod+z': function() {
|
||||
require('editor').undoMgr.undo();
|
||||
},
|
||||
'mod+y': function() {
|
||||
require('editor').undoMgr.redo();
|
||||
},
|
||||
'mod+shift+z': function() {
|
||||
require('editor').undoMgr.redo();
|
||||
},
|
||||
'S t a c k E d i t': function() {
|
||||
eventMgr.onMessage('StackEdit is so good!!!');
|
||||
}
|
||||
}
|
@ -1017,6 +1017,23 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">Editor's font style</label>
|
||||
<div class="col-sm-7">
|
||||
<div class="radio">
|
||||
<label> <input type="radio"
|
||||
name="radio-settings-editor-font-class" value="font-rich">
|
||||
Rich
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label> <input type="radio"
|
||||
name="radio-settings-editor-font-class" value="font-monospaced">
|
||||
Monospaced
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label"
|
||||
for="input-settings-editor-font-family">Editor font</label>
|
||||
@ -1270,5 +1287,4 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div class="lock-ui hide"></div>
|
||||
<div id="dropboxjs" data-app-key="x0k2l8puemfvg0o"></div>
|
||||
|
11
public/res/html/shortcutsSettingsBlock.html
Normal file
11
public/res/html/shortcutsSettingsBlock.html
Normal file
@ -0,0 +1,11 @@
|
||||
<p>Maps keyboard shortcuts to JavaScript functions.</p>
|
||||
<div class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label" for="textarea-shortcuts-mapping">Mapping
|
||||
<a href="#" class="tooltip-shortcuts-extension">(?)</a>
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
<textarea id="textarea-shortcuts-mapping" class="form-control"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1252,6 +1252,7 @@
|
||||
keyEvent = "keypress";
|
||||
}
|
||||
|
||||
/*
|
||||
util.addEvent(inputBox, keyEvent, function (key) {
|
||||
|
||||
// Check to see if we have a button key and, if so execute the callback.
|
||||
@ -1322,6 +1323,7 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
// Auto-indent on shift-enter
|
||||
util.addEvent(inputBox, "keyup", function (key) {
|
||||
@ -1559,7 +1561,7 @@
|
||||
|
||||
this.setUndoRedoButtonStates = setUndoRedoButtonStates;
|
||||
this.buttons = buttons;
|
||||
this.setButtonState = setupButton;
|
||||
this.doClick = doClick;
|
||||
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -36,7 +36,6 @@ requirejs.config({
|
||||
'jquery-ui-draggable': 'bower-libs/jquery-ui/ui/jquery.ui.draggable',
|
||||
'jquery-ui-effect': 'bower-libs/jquery-ui/ui/jquery.ui.effect',
|
||||
'jquery-ui-effect-slide': 'bower-libs/jquery-ui/ui/jquery.ui.effect-slide',
|
||||
uilayout: 'libs/layout',
|
||||
FileSaver: 'bower-libs/FileSaver/FileSaver',
|
||||
stacktrace: 'bower-libs/stacktrace/stacktrace',
|
||||
'requirejs-text': 'bower-libs/requirejs-text/text',
|
||||
|
@ -8,6 +8,7 @@ define([
|
||||
layoutOrientation: "horizontal",
|
||||
mode: 'ltr',
|
||||
lazyRendering: true,
|
||||
editorFontClass: 'font-rich',
|
||||
editorFontFamily: 'Menlo, Consolas, "Courier New", Courier, monospace',
|
||||
editorFontSize: 13,
|
||||
maxWidth: 960,
|
||||
|
@ -15,7 +15,6 @@ define([
|
||||
win: 'Ctrl-B',
|
||||
mac: 'Command-B|Ctrl-B',
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'italic': {
|
||||
title: 'Emphasis',
|
||||
@ -23,7 +22,6 @@ define([
|
||||
win: 'Ctrl-I',
|
||||
mac: 'Command-I|Ctrl-I',
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'link': {
|
||||
title: 'Hyperlink',
|
||||
@ -31,7 +29,6 @@ define([
|
||||
win: 'Ctrl-L',
|
||||
mac: 'Command-L|Ctrl-L',
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'quote': {
|
||||
title: 'Blockquote',
|
||||
@ -39,7 +36,6 @@ define([
|
||||
win: 'Ctrl-Q',
|
||||
mac: 'Command-Q|Ctrl-Q',
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'code': {
|
||||
title: 'Code Sample',
|
||||
@ -47,7 +43,6 @@ define([
|
||||
win: 'Ctrl-K',
|
||||
mac: 'Command-K|Ctrl-K',
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'image': {
|
||||
title: 'Image',
|
||||
@ -55,7 +50,6 @@ define([
|
||||
win: 'Ctrl-G',
|
||||
mac: 'Command-G|Ctrl-G',
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'olist': {
|
||||
title: 'Numbered List',
|
||||
@ -63,7 +57,6 @@ define([
|
||||
win: 'Ctrl-O',
|
||||
mac: 'Command-O|Ctrl-O',
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'ulist': {
|
||||
title: 'Bulleted List',
|
||||
@ -71,7 +64,6 @@ define([
|
||||
win: 'Ctrl-U',
|
||||
mac: 'Command-U|Ctrl-U',
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'heading': {
|
||||
title: 'Heading',
|
||||
@ -79,7 +71,6 @@ define([
|
||||
win: 'Ctrl-H',
|
||||
mac: 'Command-H|Ctrl-H',
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'hr': {
|
||||
title: 'Horizontal Rule',
|
||||
@ -87,7 +78,6 @@ define([
|
||||
win: 'Ctrl-R',
|
||||
mac: 'Command-R|Ctrl-R',
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'undo': {
|
||||
title: 'Undo',
|
||||
@ -95,10 +85,6 @@ define([
|
||||
win: 'Ctrl-Z',
|
||||
mac: 'Command-Z',
|
||||
},
|
||||
exec: function(editor) {
|
||||
editor.undo();
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'redo': {
|
||||
title: 'Redo',
|
||||
@ -106,148 +92,6 @@ define([
|
||||
win: 'Ctrl-Y|Ctrl-Shift-Z',
|
||||
mac: 'Command-Y|Command-Shift-Z',
|
||||
},
|
||||
exec: function(editor) {
|
||||
editor.redo();
|
||||
},
|
||||
isPageDown: true
|
||||
},
|
||||
'selectall': {
|
||||
title: 'Select All',
|
||||
defaultKey: {
|
||||
win: 'Ctrl-A',
|
||||
mac: 'Command-A',
|
||||
},
|
||||
exec: function(editor) {
|
||||
editor.selectAll();
|
||||
},
|
||||
readOnly: true
|
||||
},
|
||||
'removeline': {
|
||||
title: 'Remove Line',
|
||||
defaultKey: {
|
||||
win: 'Ctrl-D',
|
||||
mac: 'Command-D',
|
||||
},
|
||||
exec: function(editor) {
|
||||
editor.removeLines();
|
||||
},
|
||||
multiSelectAction: "forEachLine"
|
||||
},
|
||||
'duplicateSelection': {
|
||||
title: 'Duplicate Selection',
|
||||
defaultKey: {
|
||||
win: 'Ctrl-Shift-D',
|
||||
mac: 'Command-Shift-D',
|
||||
},
|
||||
exec: function(editor) {
|
||||
editor.duplicateSelection();
|
||||
},
|
||||
multiSelectAction: "forEach"
|
||||
},
|
||||
'sortlines': {
|
||||
title: 'Sort Lines',
|
||||
defaultKey: {
|
||||
win: 'Ctrl-Alt-S',
|
||||
mac: 'Command-Alt-S',
|
||||
},
|
||||
exec: function(editor) {
|
||||
editor.sortLines();
|
||||
},
|
||||
multiSelectAction: "forEachLine"
|
||||
},
|
||||
'modifyNumberUp': {
|
||||
title: 'Number Up',
|
||||
defaultKey: {
|
||||
win: 'Ctrl-Shift-Up',
|
||||
mac: 'Alt-Shift-Up',
|
||||
},
|
||||
exec: function(editor) {
|
||||
editor.modifyNumber(1);
|
||||
},
|
||||
multiSelectAction: "forEach"
|
||||
},
|
||||
'modifyNumberDown': {
|
||||
title: 'Number Down',
|
||||
defaultKey: {
|
||||
win: 'Ctrl-Shift-Down',
|
||||
mac: 'Alt-Shift-Down',
|
||||
},
|
||||
exec: function(editor) {
|
||||
editor.modifyNumber(-1);
|
||||
},
|
||||
multiSelectAction: "forEach"
|
||||
},
|
||||
'find': {
|
||||
title: 'Find',
|
||||
defaultKey: {
|
||||
win: 'Ctrl-F',
|
||||
mac: 'Command-F',
|
||||
},
|
||||
exec: function(editor) {
|
||||
var config = require("ace/config");
|
||||
config.loadModule("ace/ext/searchbox", function(e) {
|
||||
e.Search(editor);
|
||||
});
|
||||
},
|
||||
readOnly: true
|
||||
},
|
||||
'replace': {
|
||||
title: 'Replace',
|
||||
defaultKey: {
|
||||
win: 'Ctrl-Shift-F',
|
||||
mac: 'Command-Option-F',
|
||||
},
|
||||
exec: function(editor) {
|
||||
var config = require("ace/config");
|
||||
config.loadModule("ace/ext/searchbox", function(e) {
|
||||
e.Search(editor, true);
|
||||
});
|
||||
},
|
||||
readOnly: true
|
||||
},
|
||||
'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
|
||||
},
|
||||
'togglerecording': {
|
||||
title: 'Toggle Recording',
|
||||
defaultKey: {
|
||||
win: 'Ctrl-Alt-E',
|
||||
mac: 'Command-Option-E',
|
||||
},
|
||||
exec: function(editor) {
|
||||
editor.commands.toggleRecording(editor);
|
||||
},
|
||||
readOnly: true
|
||||
},
|
||||
'replaymacro': {
|
||||
title: 'Replay Macro',
|
||||
defaultKey: {
|
||||
win: 'Ctrl-Shift-E',
|
||||
mac: 'Command-Shift-E',
|
||||
},
|
||||
exec: function(editor) {
|
||||
editor.commands.replay(editor);
|
||||
},
|
||||
readOnly: true
|
||||
},
|
||||
};
|
||||
|
||||
@ -256,12 +100,6 @@ define([
|
||||
shortcut.bindKey = settings.shortcuts[key] || shortcut.defaultKey;
|
||||
});
|
||||
|
||||
shortcutMgr.configureAce = function(aceEditor) {
|
||||
_.each(shortcuts, function(shortcut) {
|
||||
shortcut.exec && aceEditor.commands.addCommand(_.pick(shortcut, 'name', 'bindKey', 'exec', 'readOnly', 'multiSelectAction'));
|
||||
});
|
||||
};
|
||||
|
||||
shortcutMgr.getPagedownKeyStrokes = function() {
|
||||
return _.chain(shortcuts).where({
|
||||
isPageDown: true
|
||||
@ -298,4 +136,4 @@ define([
|
||||
};
|
||||
|
||||
return shortcutMgr;
|
||||
});
|
||||
});
|
||||
|
@ -1165,6 +1165,12 @@ a {
|
||||
}
|
||||
}
|
||||
|
||||
&.font-monospaced * {
|
||||
font-family: @font-family-monospace !important;
|
||||
line-height: @editor-line-weight !important;
|
||||
font-size: 1em !important;
|
||||
}
|
||||
|
||||
.comment-highlight {
|
||||
background-color: fade(@label-warning-bg, 30%);
|
||||
}
|
||||
@ -1285,10 +1291,6 @@ a {
|
||||
}
|
||||
}
|
||||
|
||||
.md-li, .md-li2, .md-li3, .md-li4, .md-li5, .md-li6, .md-li7, .md-li8, .md-li9, .md-li10, .md-li11 {
|
||||
//white-space: pre-line;
|
||||
}
|
||||
|
||||
.md-li {
|
||||
padding-left: 1.2em;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user