1
|
ace.define("ace/ext/menu_tools/overlay_page",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
|
2
|
'use strict';
|
3
|
var dom = require("../../lib/dom");
|
4
|
var cssText = "#ace_settingsmenu, #kbshortcutmenu {\
|
5
|
background-color: #F7F7F7;\
|
6
|
color: black;\
|
7
|
box-shadow: -5px 4px 5px rgba(126, 126, 126, 0.55);\
|
8
|
padding: 1em 0.5em 2em 1em;\
|
9
|
overflow: auto;\
|
10
|
position: absolute;\
|
11
|
margin: 0;\
|
12
|
bottom: 0;\
|
13
|
right: 0;\
|
14
|
top: 0;\
|
15
|
z-index: 9991;\
|
16
|
cursor: default;\
|
17
|
}\
|
18
|
.ace_dark #ace_settingsmenu, .ace_dark #kbshortcutmenu {\
|
19
|
box-shadow: -20px 10px 25px rgba(126, 126, 126, 0.25);\
|
20
|
background-color: rgba(255, 255, 255, 0.6);\
|
21
|
color: black;\
|
22
|
}\
|
23
|
.ace_optionsMenuEntry:hover {\
|
24
|
background-color: rgba(100, 100, 100, 0.1);\
|
25
|
transition: all 0.3s\
|
26
|
}\
|
27
|
.ace_closeButton {\
|
28
|
background: rgba(245, 146, 146, 0.5);\
|
29
|
border: 1px solid #F48A8A;\
|
30
|
border-radius: 50%;\
|
31
|
padding: 7px;\
|
32
|
position: absolute;\
|
33
|
right: -8px;\
|
34
|
top: -8px;\
|
35
|
z-index: 100000;\
|
36
|
}\
|
37
|
.ace_closeButton{\
|
38
|
background: rgba(245, 146, 146, 0.9);\
|
39
|
}\
|
40
|
.ace_optionsMenuKey {\
|
41
|
color: darkslateblue;\
|
42
|
font-weight: bold;\
|
43
|
}\
|
44
|
.ace_optionsMenuCommand {\
|
45
|
color: darkcyan;\
|
46
|
font-weight: normal;\
|
47
|
}\
|
48
|
.ace_optionsMenuEntry input, .ace_optionsMenuEntry button {\
|
49
|
vertical-align: middle;\
|
50
|
}\
|
51
|
.ace_optionsMenuEntry button[ace_selected_button=true] {\
|
52
|
background: #e7e7e7;\
|
53
|
box-shadow: 1px 0px 2px 0px #adadad inset;\
|
54
|
border-color: #adadad;\
|
55
|
}\
|
56
|
.ace_optionsMenuEntry button {\
|
57
|
background: white;\
|
58
|
border: 1px solid lightgray;\
|
59
|
margin: 0px;\
|
60
|
}\
|
61
|
.ace_optionsMenuEntry button:hover{\
|
62
|
background: #f0f0f0;\
|
63
|
}";
|
64
|
dom.importCssString(cssText);
|
65
|
|
66
|
module.exports.overlayPage = function overlayPage(editor, contentElement, callback) {
|
67
|
var closer = document.createElement('div');
|
68
|
var ignoreFocusOut = false;
|
69
|
|
70
|
function documentEscListener(e) {
|
71
|
if (e.keyCode === 27) {
|
72
|
close();
|
73
|
}
|
74
|
}
|
75
|
|
76
|
function close() {
|
77
|
if (!closer) return;
|
78
|
document.removeEventListener('keydown', documentEscListener);
|
79
|
closer.parentNode.removeChild(closer);
|
80
|
if (editor) {
|
81
|
editor.focus();
|
82
|
}
|
83
|
closer = null;
|
84
|
callback && callback();
|
85
|
}
|
86
|
function setIgnoreFocusOut(ignore) {
|
87
|
ignoreFocusOut = ignore;
|
88
|
if (ignore) {
|
89
|
closer.style.pointerEvents = "none";
|
90
|
contentElement.style.pointerEvents = "auto";
|
91
|
}
|
92
|
}
|
93
|
|
94
|
closer.style.cssText = 'margin: 0; padding: 0; ' +
|
95
|
'position: fixed; top:0; bottom:0; left:0; right:0;' +
|
96
|
'z-index: 9990; ' +
|
97
|
(editor ? 'background-color: rgba(0, 0, 0, 0.3);' : '');
|
98
|
closer.addEventListener('click', function(e) {
|
99
|
if (!ignoreFocusOut) {
|
100
|
close();
|
101
|
}
|
102
|
});
|
103
|
document.addEventListener('keydown', documentEscListener);
|
104
|
|
105
|
contentElement.addEventListener('click', function (e) {
|
106
|
e.stopPropagation();
|
107
|
});
|
108
|
|
109
|
closer.appendChild(contentElement);
|
110
|
document.body.appendChild(closer);
|
111
|
if (editor) {
|
112
|
editor.blur();
|
113
|
}
|
114
|
return {
|
115
|
close: close,
|
116
|
setIgnoreFocusOut: setIgnoreFocusOut
|
117
|
};
|
118
|
};
|
119
|
|
120
|
});
|
121
|
|
122
|
ace.define("ace/ext/menu_tools/get_editor_keyboard_shortcuts",["require","exports","module","ace/lib/keys"], function(require, exports, module) {
|
123
|
"use strict";
|
124
|
var keys = require("../../lib/keys");
|
125
|
module.exports.getEditorKeybordShortcuts = function(editor) {
|
126
|
var KEY_MODS = keys.KEY_MODS;
|
127
|
var keybindings = [];
|
128
|
var commandMap = {};
|
129
|
editor.keyBinding.$handlers.forEach(function(handler) {
|
130
|
var ckb = handler.commandKeyBinding;
|
131
|
for (var i in ckb) {
|
132
|
var key = i.replace(/(^|-)\w/g, function(x) { return x.toUpperCase(); });
|
133
|
var commands = ckb[i];
|
134
|
if (!Array.isArray(commands))
|
135
|
commands = [commands];
|
136
|
commands.forEach(function(command) {
|
137
|
if (typeof command != "string")
|
138
|
command = command.name;
|
139
|
if (commandMap[command]) {
|
140
|
commandMap[command].key += "|" + key;
|
141
|
} else {
|
142
|
commandMap[command] = {key: key, command: command};
|
143
|
keybindings.push(commandMap[command]);
|
144
|
}
|
145
|
});
|
146
|
}
|
147
|
});
|
148
|
return keybindings;
|
149
|
};
|
150
|
|
151
|
});
|
152
|
|
153
|
ace.define("ace/ext/keybinding_menu",["require","exports","module","ace/editor","ace/ext/menu_tools/overlay_page","ace/ext/menu_tools/get_editor_keyboard_shortcuts"], function(require, exports, module) {
|
154
|
"use strict";
|
155
|
var Editor = require("../editor").Editor;
|
156
|
function showKeyboardShortcuts (editor) {
|
157
|
if(!document.getElementById('kbshortcutmenu')) {
|
158
|
var overlayPage = require('./menu_tools/overlay_page').overlayPage;
|
159
|
var getEditorKeybordShortcuts = require('./menu_tools/get_editor_keyboard_shortcuts').getEditorKeybordShortcuts;
|
160
|
var kb = getEditorKeybordShortcuts(editor);
|
161
|
var el = document.createElement('div');
|
162
|
var commands = kb.reduce(function(previous, current) {
|
163
|
return previous + '<div class="ace_optionsMenuEntry"><span class="ace_optionsMenuCommand">'
|
164
|
+ current.command + '</span> : '
|
165
|
+ '<span class="ace_optionsMenuKey">' + current.key + '</span></div>';
|
166
|
}, '');
|
167
|
|
168
|
el.id = 'kbshortcutmenu';
|
169
|
el.innerHTML = '<h1>Keyboard Shortcuts</h1>' + commands + '</div>';
|
170
|
overlayPage(editor, el);
|
171
|
}
|
172
|
}
|
173
|
module.exports.init = function(editor) {
|
174
|
Editor.prototype.showKeyboardShortcuts = function() {
|
175
|
showKeyboardShortcuts(this);
|
176
|
};
|
177
|
editor.commands.addCommands([{
|
178
|
name: "showKeyboardShortcuts",
|
179
|
bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"},
|
180
|
exec: function(editor, line) {
|
181
|
editor.showKeyboardShortcuts();
|
182
|
}
|
183
|
}]);
|
184
|
};
|
185
|
|
186
|
}); (function() {
|
187
|
ace.require(["ace/ext/keybinding_menu"], function(m) {
|
188
|
if (typeof module == "object" && typeof exports == "object" && module) {
|
189
|
module.exports = m;
|
190
|
}
|
191
|
});
|
192
|
})();
|
193
|
|