stackprofiler 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +1 -1
- data/config.ru +3 -2
- data/lib/stackprofiler.rb +0 -1
- data/lib/stackprofiler/filters/build_tree.rb +3 -4
- data/lib/stackprofiler/filters/gem_removal.rb +3 -0
- data/lib/stackprofiler/web_ui.rb +34 -11
- data/lib/stackprofiler/web_ui/public/css/stackprofiler.css +77 -0
- data/lib/stackprofiler/web_ui/public/js/stackprofiler.js +129 -58
- data/lib/stackprofiler/web_ui/public/vendor/ace/ace.js +18298 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-beautify.js +334 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-chromevox.js +541 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-elastic_tabstops_lite.js +275 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-emmet.js +1190 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-error_marker.js +6 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-keybinding_menu.js +170 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-language_tools.js +1934 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-linking.js +52 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-modelist.js +187 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-old_ie.js +494 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-searchbox.js +409 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-settings_menu.js +637 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-spellcheck.js +71 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-split.js +246 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-static_highlight.js +154 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-statusbar.js +51 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-textarea.js +632 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-themelist.js +58 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-whitespace.js +181 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/keybinding-emacs.js +1182 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/keybinding-vim.js +5320 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-haml.js +525 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-html.js +2427 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-html_ruby.js +2955 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-javascript.js +1025 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-json.js +668 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-ruby.js +839 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-xml.js +637 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-yaml.js +256 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/theme-xcode.js +89 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/worker-coffee.js +7599 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/worker-css.js +8682 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/worker-html.js +11527 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/worker-javascript.js +10429 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/worker-json.js +2319 -0
- data/lib/stackprofiler/web_ui/views/index.erb +1 -1
- data/lib/stackprofiler/web_ui/views/layout.erb +2 -55
- data/stackprofiler.gemspec +2 -4
- metadata +42 -19
- data/lib/stackprofiler/web_ui/views/code.erb +0 -17
@@ -0,0 +1,170 @@
|
|
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
|
+
-webkit-transition: all 0.5s;\
|
26
|
+
transition: all 0.3s\
|
27
|
+
}\
|
28
|
+
.ace_closeButton {\
|
29
|
+
background: rgba(245, 146, 146, 0.5);\
|
30
|
+
border: 1px solid #F48A8A;\
|
31
|
+
border-radius: 50%;\
|
32
|
+
padding: 7px;\
|
33
|
+
position: absolute;\
|
34
|
+
right: -8px;\
|
35
|
+
top: -8px;\
|
36
|
+
z-index: 1000;\
|
37
|
+
}\
|
38
|
+
.ace_closeButton{\
|
39
|
+
background: rgba(245, 146, 146, 0.9);\
|
40
|
+
}\
|
41
|
+
.ace_optionsMenuKey {\
|
42
|
+
color: darkslateblue;\
|
43
|
+
font-weight: bold;\
|
44
|
+
}\
|
45
|
+
.ace_optionsMenuCommand {\
|
46
|
+
color: darkcyan;\
|
47
|
+
font-weight: normal;\
|
48
|
+
}";
|
49
|
+
dom.importCssString(cssText);
|
50
|
+
module.exports.overlayPage = function overlayPage(editor, contentElement, top, right, bottom, left) {
|
51
|
+
top = top ? 'top: ' + top + ';' : '';
|
52
|
+
bottom = bottom ? 'bottom: ' + bottom + ';' : '';
|
53
|
+
right = right ? 'right: ' + right + ';' : '';
|
54
|
+
left = left ? 'left: ' + left + ';' : '';
|
55
|
+
|
56
|
+
var closer = document.createElement('div');
|
57
|
+
var contentContainer = document.createElement('div');
|
58
|
+
|
59
|
+
function documentEscListener(e) {
|
60
|
+
if (e.keyCode === 27) {
|
61
|
+
closer.click();
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
closer.style.cssText = 'margin: 0; padding: 0; ' +
|
66
|
+
'position: fixed; top:0; bottom:0; left:0; right:0;' +
|
67
|
+
'z-index: 9990; ' +
|
68
|
+
'background-color: rgba(0, 0, 0, 0.3);';
|
69
|
+
closer.addEventListener('click', function() {
|
70
|
+
document.removeEventListener('keydown', documentEscListener);
|
71
|
+
closer.parentNode.removeChild(closer);
|
72
|
+
editor.focus();
|
73
|
+
closer = null;
|
74
|
+
});
|
75
|
+
document.addEventListener('keydown', documentEscListener);
|
76
|
+
|
77
|
+
contentContainer.style.cssText = top + right + bottom + left;
|
78
|
+
contentContainer.addEventListener('click', function(e) {
|
79
|
+
e.stopPropagation();
|
80
|
+
});
|
81
|
+
|
82
|
+
var wrapper = dom.createElement("div");
|
83
|
+
wrapper.style.position = "relative";
|
84
|
+
|
85
|
+
var closeButton = dom.createElement("div");
|
86
|
+
closeButton.className = "ace_closeButton";
|
87
|
+
closeButton.addEventListener('click', function() {
|
88
|
+
closer.click();
|
89
|
+
});
|
90
|
+
|
91
|
+
wrapper.appendChild(closeButton);
|
92
|
+
contentContainer.appendChild(wrapper);
|
93
|
+
|
94
|
+
contentContainer.appendChild(contentElement);
|
95
|
+
closer.appendChild(contentContainer);
|
96
|
+
document.body.appendChild(closer);
|
97
|
+
editor.blur();
|
98
|
+
};
|
99
|
+
|
100
|
+
});
|
101
|
+
|
102
|
+
ace.define("ace/ext/menu_tools/get_editor_keyboard_shortcuts",["require","exports","module","ace/lib/keys"], function(require, exports, module) {
|
103
|
+
"use strict";
|
104
|
+
var keys = require("../../lib/keys");
|
105
|
+
module.exports.getEditorKeybordShortcuts = function(editor) {
|
106
|
+
var KEY_MODS = keys.KEY_MODS;
|
107
|
+
var keybindings = [];
|
108
|
+
var commandMap = {};
|
109
|
+
editor.keyBinding.$handlers.forEach(function(handler) {
|
110
|
+
var ckb = handler.commandKeyBinding;
|
111
|
+
for (var i in ckb) {
|
112
|
+
var key = i.replace(/(^|-)\w/g, function(x) { return x.toUpperCase(); });
|
113
|
+
var commands = ckb[i];
|
114
|
+
if (!Array.isArray(commands))
|
115
|
+
commands = [commands];
|
116
|
+
commands.forEach(function(command) {
|
117
|
+
if (typeof command != "string")
|
118
|
+
command = command.name
|
119
|
+
if (commandMap[command]) {
|
120
|
+
commandMap[command].key += "|" + key;
|
121
|
+
} else {
|
122
|
+
commandMap[command] = {key: key, command: command};
|
123
|
+
keybindings.push(commandMap[command]);
|
124
|
+
}
|
125
|
+
});
|
126
|
+
}
|
127
|
+
});
|
128
|
+
return keybindings;
|
129
|
+
};
|
130
|
+
|
131
|
+
});
|
132
|
+
|
133
|
+
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) {
|
134
|
+
"use strict";
|
135
|
+
var Editor = require("ace/editor").Editor;
|
136
|
+
function showKeyboardShortcuts (editor) {
|
137
|
+
if(!document.getElementById('kbshortcutmenu')) {
|
138
|
+
var overlayPage = require('./menu_tools/overlay_page').overlayPage;
|
139
|
+
var getEditorKeybordShortcuts = require('./menu_tools/get_editor_keyboard_shortcuts').getEditorKeybordShortcuts;
|
140
|
+
var kb = getEditorKeybordShortcuts(editor);
|
141
|
+
var el = document.createElement('div');
|
142
|
+
var commands = kb.reduce(function(previous, current) {
|
143
|
+
return previous + '<div class="ace_optionsMenuEntry"><span class="ace_optionsMenuCommand">'
|
144
|
+
+ current.command + '</span> : '
|
145
|
+
+ '<span class="ace_optionsMenuKey">' + current.key + '</span></div>';
|
146
|
+
}, '');
|
147
|
+
|
148
|
+
el.id = 'kbshortcutmenu';
|
149
|
+
el.innerHTML = '<h1>Keyboard Shortcuts</h1>' + commands + '</div>';
|
150
|
+
overlayPage(editor, el, '0', '0', '0', null);
|
151
|
+
}
|
152
|
+
};
|
153
|
+
module.exports.init = function(editor) {
|
154
|
+
Editor.prototype.showKeyboardShortcuts = function() {
|
155
|
+
showKeyboardShortcuts(this);
|
156
|
+
};
|
157
|
+
editor.commands.addCommands([{
|
158
|
+
name: "showKeyboardShortcuts",
|
159
|
+
bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"},
|
160
|
+
exec: function(editor, line) {
|
161
|
+
editor.showKeyboardShortcuts();
|
162
|
+
}
|
163
|
+
}]);
|
164
|
+
};
|
165
|
+
|
166
|
+
});
|
167
|
+
(function() {
|
168
|
+
ace.require(["ace/ext/keybinding_menu"], function() {});
|
169
|
+
})();
|
170
|
+
|
@@ -0,0 +1,1934 @@
|
|
1
|
+
ace.define("ace/snippets",["require","exports","module","ace/lib/oop","ace/lib/event_emitter","ace/lib/lang","ace/range","ace/anchor","ace/keyboard/hash_handler","ace/tokenizer","ace/lib/dom","ace/editor"], function(require, exports, module) {
|
2
|
+
"use strict";
|
3
|
+
var oop = require("./lib/oop");
|
4
|
+
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
5
|
+
var lang = require("./lib/lang");
|
6
|
+
var Range = require("./range").Range;
|
7
|
+
var Anchor = require("./anchor").Anchor;
|
8
|
+
var HashHandler = require("./keyboard/hash_handler").HashHandler;
|
9
|
+
var Tokenizer = require("./tokenizer").Tokenizer;
|
10
|
+
var comparePoints = Range.comparePoints;
|
11
|
+
|
12
|
+
var SnippetManager = function() {
|
13
|
+
this.snippetMap = {};
|
14
|
+
this.snippetNameMap = {};
|
15
|
+
};
|
16
|
+
|
17
|
+
(function() {
|
18
|
+
oop.implement(this, EventEmitter);
|
19
|
+
|
20
|
+
this.getTokenizer = function() {
|
21
|
+
function TabstopToken(str, _, stack) {
|
22
|
+
str = str.substr(1);
|
23
|
+
if (/^\d+$/.test(str) && !stack.inFormatString)
|
24
|
+
return [{tabstopId: parseInt(str, 10)}];
|
25
|
+
return [{text: str}];
|
26
|
+
}
|
27
|
+
function escape(ch) {
|
28
|
+
return "(?:[^\\\\" + ch + "]|\\\\.)";
|
29
|
+
}
|
30
|
+
SnippetManager.$tokenizer = new Tokenizer({
|
31
|
+
start: [
|
32
|
+
{regex: /:/, onMatch: function(val, state, stack) {
|
33
|
+
if (stack.length && stack[0].expectIf) {
|
34
|
+
stack[0].expectIf = false;
|
35
|
+
stack[0].elseBranch = stack[0];
|
36
|
+
return [stack[0]];
|
37
|
+
}
|
38
|
+
return ":";
|
39
|
+
}},
|
40
|
+
{regex: /\\./, onMatch: function(val, state, stack) {
|
41
|
+
var ch = val[1];
|
42
|
+
if (ch == "}" && stack.length) {
|
43
|
+
val = ch;
|
44
|
+
}else if ("`$\\".indexOf(ch) != -1) {
|
45
|
+
val = ch;
|
46
|
+
} else if (stack.inFormatString) {
|
47
|
+
if (ch == "n")
|
48
|
+
val = "\n";
|
49
|
+
else if (ch == "t")
|
50
|
+
val = "\n";
|
51
|
+
else if ("ulULE".indexOf(ch) != -1) {
|
52
|
+
val = {changeCase: ch, local: ch > "a"};
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
return [val];
|
57
|
+
}},
|
58
|
+
{regex: /}/, onMatch: function(val, state, stack) {
|
59
|
+
return [stack.length ? stack.shift() : val];
|
60
|
+
}},
|
61
|
+
{regex: /\$(?:\d+|\w+)/, onMatch: TabstopToken},
|
62
|
+
{regex: /\$\{[\dA-Z_a-z]+/, onMatch: function(str, state, stack) {
|
63
|
+
var t = TabstopToken(str.substr(1), state, stack);
|
64
|
+
stack.unshift(t[0]);
|
65
|
+
return t;
|
66
|
+
}, next: "snippetVar"},
|
67
|
+
{regex: /\n/, token: "newline", merge: false}
|
68
|
+
],
|
69
|
+
snippetVar: [
|
70
|
+
{regex: "\\|" + escape("\\|") + "*\\|", onMatch: function(val, state, stack) {
|
71
|
+
stack[0].choices = val.slice(1, -1).split(",");
|
72
|
+
}, next: "start"},
|
73
|
+
{regex: "/(" + escape("/") + "+)/(?:(" + escape("/") + "*)/)(\\w*):?",
|
74
|
+
onMatch: function(val, state, stack) {
|
75
|
+
var ts = stack[0];
|
76
|
+
ts.fmtString = val;
|
77
|
+
|
78
|
+
val = this.splitRegex.exec(val);
|
79
|
+
ts.guard = val[1];
|
80
|
+
ts.fmt = val[2];
|
81
|
+
ts.flag = val[3];
|
82
|
+
return "";
|
83
|
+
}, next: "start"},
|
84
|
+
{regex: "`" + escape("`") + "*`", onMatch: function(val, state, stack) {
|
85
|
+
stack[0].code = val.splice(1, -1);
|
86
|
+
return "";
|
87
|
+
}, next: "start"},
|
88
|
+
{regex: "\\?", onMatch: function(val, state, stack) {
|
89
|
+
if (stack[0])
|
90
|
+
stack[0].expectIf = true;
|
91
|
+
}, next: "start"},
|
92
|
+
{regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "start"}
|
93
|
+
],
|
94
|
+
formatString: [
|
95
|
+
{regex: "/(" + escape("/") + "+)/", token: "regex"},
|
96
|
+
{regex: "", onMatch: function(val, state, stack) {
|
97
|
+
stack.inFormatString = true;
|
98
|
+
}, next: "start"}
|
99
|
+
]
|
100
|
+
});
|
101
|
+
SnippetManager.prototype.getTokenizer = function() {
|
102
|
+
return SnippetManager.$tokenizer;
|
103
|
+
};
|
104
|
+
return SnippetManager.$tokenizer;
|
105
|
+
};
|
106
|
+
|
107
|
+
this.tokenizeTmSnippet = function(str, startState) {
|
108
|
+
return this.getTokenizer().getLineTokens(str, startState).tokens.map(function(x) {
|
109
|
+
return x.value || x;
|
110
|
+
});
|
111
|
+
};
|
112
|
+
|
113
|
+
this.$getDefaultValue = function(editor, name) {
|
114
|
+
if (/^[A-Z]\d+$/.test(name)) {
|
115
|
+
var i = name.substr(1);
|
116
|
+
return (this.variables[name[0] + "__"] || {})[i];
|
117
|
+
}
|
118
|
+
if (/^\d+$/.test(name)) {
|
119
|
+
return (this.variables.__ || {})[name];
|
120
|
+
}
|
121
|
+
name = name.replace(/^TM_/, "");
|
122
|
+
|
123
|
+
if (!editor)
|
124
|
+
return;
|
125
|
+
var s = editor.session;
|
126
|
+
switch(name) {
|
127
|
+
case "CURRENT_WORD":
|
128
|
+
var r = s.getWordRange();
|
129
|
+
case "SELECTION":
|
130
|
+
case "SELECTED_TEXT":
|
131
|
+
return s.getTextRange(r);
|
132
|
+
case "CURRENT_LINE":
|
133
|
+
return s.getLine(editor.getCursorPosition().row);
|
134
|
+
case "PREV_LINE": // not possible in textmate
|
135
|
+
return s.getLine(editor.getCursorPosition().row - 1);
|
136
|
+
case "LINE_INDEX":
|
137
|
+
return editor.getCursorPosition().column;
|
138
|
+
case "LINE_NUMBER":
|
139
|
+
return editor.getCursorPosition().row + 1;
|
140
|
+
case "SOFT_TABS":
|
141
|
+
return s.getUseSoftTabs() ? "YES" : "NO";
|
142
|
+
case "TAB_SIZE":
|
143
|
+
return s.getTabSize();
|
144
|
+
case "FILENAME":
|
145
|
+
case "FILEPATH":
|
146
|
+
return "";
|
147
|
+
case "FULLNAME":
|
148
|
+
return "Ace";
|
149
|
+
}
|
150
|
+
};
|
151
|
+
this.variables = {};
|
152
|
+
this.getVariableValue = function(editor, varName) {
|
153
|
+
if (this.variables.hasOwnProperty(varName))
|
154
|
+
return this.variables[varName](editor, varName) || "";
|
155
|
+
return this.$getDefaultValue(editor, varName) || "";
|
156
|
+
};
|
157
|
+
this.tmStrFormat = function(str, ch, editor) {
|
158
|
+
var flag = ch.flag || "";
|
159
|
+
var re = ch.guard;
|
160
|
+
re = new RegExp(re, flag.replace(/[^gi]/, ""));
|
161
|
+
var fmtTokens = this.tokenizeTmSnippet(ch.fmt, "formatString");
|
162
|
+
var _self = this;
|
163
|
+
var formatted = str.replace(re, function() {
|
164
|
+
_self.variables.__ = arguments;
|
165
|
+
var fmtParts = _self.resolveVariables(fmtTokens, editor);
|
166
|
+
var gChangeCase = "E";
|
167
|
+
for (var i = 0; i < fmtParts.length; i++) {
|
168
|
+
var ch = fmtParts[i];
|
169
|
+
if (typeof ch == "object") {
|
170
|
+
fmtParts[i] = "";
|
171
|
+
if (ch.changeCase && ch.local) {
|
172
|
+
var next = fmtParts[i + 1];
|
173
|
+
if (next && typeof next == "string") {
|
174
|
+
if (ch.changeCase == "u")
|
175
|
+
fmtParts[i] = next[0].toUpperCase();
|
176
|
+
else
|
177
|
+
fmtParts[i] = next[0].toLowerCase();
|
178
|
+
fmtParts[i + 1] = next.substr(1);
|
179
|
+
}
|
180
|
+
} else if (ch.changeCase) {
|
181
|
+
gChangeCase = ch.changeCase;
|
182
|
+
}
|
183
|
+
} else if (gChangeCase == "U") {
|
184
|
+
fmtParts[i] = ch.toUpperCase();
|
185
|
+
} else if (gChangeCase == "L") {
|
186
|
+
fmtParts[i] = ch.toLowerCase();
|
187
|
+
}
|
188
|
+
}
|
189
|
+
return fmtParts.join("");
|
190
|
+
});
|
191
|
+
this.variables.__ = null;
|
192
|
+
return formatted;
|
193
|
+
};
|
194
|
+
|
195
|
+
this.resolveVariables = function(snippet, editor) {
|
196
|
+
var result = [];
|
197
|
+
for (var i = 0; i < snippet.length; i++) {
|
198
|
+
var ch = snippet[i];
|
199
|
+
if (typeof ch == "string") {
|
200
|
+
result.push(ch);
|
201
|
+
} else if (typeof ch != "object") {
|
202
|
+
continue;
|
203
|
+
} else if (ch.skip) {
|
204
|
+
gotoNext(ch);
|
205
|
+
} else if (ch.processed < i) {
|
206
|
+
continue;
|
207
|
+
} else if (ch.text) {
|
208
|
+
var value = this.getVariableValue(editor, ch.text);
|
209
|
+
if (value && ch.fmtString)
|
210
|
+
value = this.tmStrFormat(value, ch);
|
211
|
+
ch.processed = i;
|
212
|
+
if (ch.expectIf == null) {
|
213
|
+
if (value) {
|
214
|
+
result.push(value);
|
215
|
+
gotoNext(ch);
|
216
|
+
}
|
217
|
+
} else {
|
218
|
+
if (value) {
|
219
|
+
ch.skip = ch.elseBranch;
|
220
|
+
} else
|
221
|
+
gotoNext(ch);
|
222
|
+
}
|
223
|
+
} else if (ch.tabstopId != null) {
|
224
|
+
result.push(ch);
|
225
|
+
} else if (ch.changeCase != null) {
|
226
|
+
result.push(ch);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
function gotoNext(ch) {
|
230
|
+
var i1 = snippet.indexOf(ch, i + 1);
|
231
|
+
if (i1 != -1)
|
232
|
+
i = i1;
|
233
|
+
}
|
234
|
+
return result;
|
235
|
+
};
|
236
|
+
|
237
|
+
this.insertSnippetForSelection = function(editor, snippetText) {
|
238
|
+
var cursor = editor.getCursorPosition();
|
239
|
+
var line = editor.session.getLine(cursor.row);
|
240
|
+
var tabString = editor.session.getTabString();
|
241
|
+
var indentString = line.match(/^\s*/)[0];
|
242
|
+
|
243
|
+
if (cursor.column < indentString.length)
|
244
|
+
indentString = indentString.slice(0, cursor.column);
|
245
|
+
|
246
|
+
var tokens = this.tokenizeTmSnippet(snippetText);
|
247
|
+
tokens = this.resolveVariables(tokens, editor);
|
248
|
+
tokens = tokens.map(function(x) {
|
249
|
+
if (x == "\n")
|
250
|
+
return x + indentString;
|
251
|
+
if (typeof x == "string")
|
252
|
+
return x.replace(/\t/g, tabString);
|
253
|
+
return x;
|
254
|
+
});
|
255
|
+
var tabstops = [];
|
256
|
+
tokens.forEach(function(p, i) {
|
257
|
+
if (typeof p != "object")
|
258
|
+
return;
|
259
|
+
var id = p.tabstopId;
|
260
|
+
var ts = tabstops[id];
|
261
|
+
if (!ts) {
|
262
|
+
ts = tabstops[id] = [];
|
263
|
+
ts.index = id;
|
264
|
+
ts.value = "";
|
265
|
+
}
|
266
|
+
if (ts.indexOf(p) !== -1)
|
267
|
+
return;
|
268
|
+
ts.push(p);
|
269
|
+
var i1 = tokens.indexOf(p, i + 1);
|
270
|
+
if (i1 === -1)
|
271
|
+
return;
|
272
|
+
|
273
|
+
var value = tokens.slice(i + 1, i1);
|
274
|
+
var isNested = value.some(function(t) {return typeof t === "object"});
|
275
|
+
if (isNested && !ts.value) {
|
276
|
+
ts.value = value;
|
277
|
+
} else if (value.length && (!ts.value || typeof ts.value !== "string")) {
|
278
|
+
ts.value = value.join("");
|
279
|
+
}
|
280
|
+
});
|
281
|
+
tabstops.forEach(function(ts) {ts.length = 0});
|
282
|
+
var expanding = {};
|
283
|
+
function copyValue(val) {
|
284
|
+
var copy = [];
|
285
|
+
for (var i = 0; i < val.length; i++) {
|
286
|
+
var p = val[i];
|
287
|
+
if (typeof p == "object") {
|
288
|
+
if (expanding[p.tabstopId])
|
289
|
+
continue;
|
290
|
+
var j = val.lastIndexOf(p, i - 1);
|
291
|
+
p = copy[j] || {tabstopId: p.tabstopId};
|
292
|
+
}
|
293
|
+
copy[i] = p;
|
294
|
+
}
|
295
|
+
return copy;
|
296
|
+
}
|
297
|
+
for (var i = 0; i < tokens.length; i++) {
|
298
|
+
var p = tokens[i];
|
299
|
+
if (typeof p != "object")
|
300
|
+
continue;
|
301
|
+
var id = p.tabstopId;
|
302
|
+
var i1 = tokens.indexOf(p, i + 1);
|
303
|
+
if (expanding[id]) {
|
304
|
+
if (expanding[id] === p)
|
305
|
+
expanding[id] = null;
|
306
|
+
continue;
|
307
|
+
}
|
308
|
+
|
309
|
+
var ts = tabstops[id];
|
310
|
+
var arg = typeof ts.value == "string" ? [ts.value] : copyValue(ts.value);
|
311
|
+
arg.unshift(i + 1, Math.max(0, i1 - i));
|
312
|
+
arg.push(p);
|
313
|
+
expanding[id] = p;
|
314
|
+
tokens.splice.apply(tokens, arg);
|
315
|
+
|
316
|
+
if (ts.indexOf(p) === -1)
|
317
|
+
ts.push(p);
|
318
|
+
}
|
319
|
+
var row = 0, column = 0;
|
320
|
+
var text = "";
|
321
|
+
tokens.forEach(function(t) {
|
322
|
+
if (typeof t === "string") {
|
323
|
+
if (t[0] === "\n"){
|
324
|
+
column = t.length - 1;
|
325
|
+
row ++;
|
326
|
+
} else
|
327
|
+
column += t.length;
|
328
|
+
text += t;
|
329
|
+
} else {
|
330
|
+
if (!t.start)
|
331
|
+
t.start = {row: row, column: column};
|
332
|
+
else
|
333
|
+
t.end = {row: row, column: column};
|
334
|
+
}
|
335
|
+
});
|
336
|
+
var range = editor.getSelectionRange();
|
337
|
+
var end = editor.session.replace(range, text);
|
338
|
+
|
339
|
+
var tabstopManager = new TabstopManager(editor);
|
340
|
+
var selectionId = editor.inVirtualSelectionMode && editor.selection.index;
|
341
|
+
tabstopManager.addTabstops(tabstops, range.start, end, selectionId);
|
342
|
+
};
|
343
|
+
|
344
|
+
this.insertSnippet = function(editor, snippetText) {
|
345
|
+
var self = this;
|
346
|
+
if (editor.inVirtualSelectionMode)
|
347
|
+
return self.insertSnippetForSelection(editor, snippetText);
|
348
|
+
|
349
|
+
editor.forEachSelection(function() {
|
350
|
+
self.insertSnippetForSelection(editor, snippetText);
|
351
|
+
}, null, {keepOrder: true});
|
352
|
+
|
353
|
+
if (editor.tabstopManager)
|
354
|
+
editor.tabstopManager.tabNext();
|
355
|
+
};
|
356
|
+
|
357
|
+
this.$getScope = function(editor) {
|
358
|
+
var scope = editor.session.$mode.$id || "";
|
359
|
+
scope = scope.split("/").pop();
|
360
|
+
if (scope === "html" || scope === "php") {
|
361
|
+
if (scope === "php" && !editor.session.$mode.inlinePhp)
|
362
|
+
scope = "html";
|
363
|
+
var c = editor.getCursorPosition();
|
364
|
+
var state = editor.session.getState(c.row);
|
365
|
+
if (typeof state === "object") {
|
366
|
+
state = state[0];
|
367
|
+
}
|
368
|
+
if (state.substring) {
|
369
|
+
if (state.substring(0, 3) == "js-")
|
370
|
+
scope = "javascript";
|
371
|
+
else if (state.substring(0, 4) == "css-")
|
372
|
+
scope = "css";
|
373
|
+
else if (state.substring(0, 4) == "php-")
|
374
|
+
scope = "php";
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
return scope;
|
379
|
+
};
|
380
|
+
|
381
|
+
this.getActiveScopes = function(editor) {
|
382
|
+
var scope = this.$getScope(editor);
|
383
|
+
var scopes = [scope];
|
384
|
+
var snippetMap = this.snippetMap;
|
385
|
+
if (snippetMap[scope] && snippetMap[scope].includeScopes) {
|
386
|
+
scopes.push.apply(scopes, snippetMap[scope].includeScopes);
|
387
|
+
}
|
388
|
+
scopes.push("_");
|
389
|
+
return scopes;
|
390
|
+
};
|
391
|
+
|
392
|
+
this.expandWithTab = function(editor, options) {
|
393
|
+
var self = this;
|
394
|
+
var result = editor.forEachSelection(function() {
|
395
|
+
return self.expandSnippetForSelection(editor, options);
|
396
|
+
}, null, {keepOrder: true});
|
397
|
+
if (result && editor.tabstopManager)
|
398
|
+
editor.tabstopManager.tabNext();
|
399
|
+
return result;
|
400
|
+
};
|
401
|
+
|
402
|
+
this.expandSnippetForSelection = function(editor, options) {
|
403
|
+
var cursor = editor.getCursorPosition();
|
404
|
+
var line = editor.session.getLine(cursor.row);
|
405
|
+
var before = line.substring(0, cursor.column);
|
406
|
+
var after = line.substr(cursor.column);
|
407
|
+
|
408
|
+
var snippetMap = this.snippetMap;
|
409
|
+
var snippet;
|
410
|
+
this.getActiveScopes(editor).some(function(scope) {
|
411
|
+
var snippets = snippetMap[scope];
|
412
|
+
if (snippets)
|
413
|
+
snippet = this.findMatchingSnippet(snippets, before, after);
|
414
|
+
return !!snippet;
|
415
|
+
}, this);
|
416
|
+
if (!snippet)
|
417
|
+
return false;
|
418
|
+
if (options && options.dryRun)
|
419
|
+
return true;
|
420
|
+
editor.session.doc.removeInLine(cursor.row,
|
421
|
+
cursor.column - snippet.replaceBefore.length,
|
422
|
+
cursor.column + snippet.replaceAfter.length
|
423
|
+
);
|
424
|
+
|
425
|
+
this.variables.M__ = snippet.matchBefore;
|
426
|
+
this.variables.T__ = snippet.matchAfter;
|
427
|
+
this.insertSnippetForSelection(editor, snippet.content);
|
428
|
+
|
429
|
+
this.variables.M__ = this.variables.T__ = null;
|
430
|
+
return true;
|
431
|
+
};
|
432
|
+
|
433
|
+
this.findMatchingSnippet = function(snippetList, before, after) {
|
434
|
+
for (var i = snippetList.length; i--;) {
|
435
|
+
var s = snippetList[i];
|
436
|
+
if (s.startRe && !s.startRe.test(before))
|
437
|
+
continue;
|
438
|
+
if (s.endRe && !s.endRe.test(after))
|
439
|
+
continue;
|
440
|
+
if (!s.startRe && !s.endRe)
|
441
|
+
continue;
|
442
|
+
|
443
|
+
s.matchBefore = s.startRe ? s.startRe.exec(before) : [""];
|
444
|
+
s.matchAfter = s.endRe ? s.endRe.exec(after) : [""];
|
445
|
+
s.replaceBefore = s.triggerRe ? s.triggerRe.exec(before)[0] : "";
|
446
|
+
s.replaceAfter = s.endTriggerRe ? s.endTriggerRe.exec(after)[0] : "";
|
447
|
+
return s;
|
448
|
+
}
|
449
|
+
};
|
450
|
+
|
451
|
+
this.snippetMap = {};
|
452
|
+
this.snippetNameMap = {};
|
453
|
+
this.register = function(snippets, scope) {
|
454
|
+
var snippetMap = this.snippetMap;
|
455
|
+
var snippetNameMap = this.snippetNameMap;
|
456
|
+
var self = this;
|
457
|
+
|
458
|
+
if (!snippets)
|
459
|
+
snippets = [];
|
460
|
+
|
461
|
+
function wrapRegexp(src) {
|
462
|
+
if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src))
|
463
|
+
src = "(?:" + src + ")";
|
464
|
+
|
465
|
+
return src || "";
|
466
|
+
}
|
467
|
+
function guardedRegexp(re, guard, opening) {
|
468
|
+
re = wrapRegexp(re);
|
469
|
+
guard = wrapRegexp(guard);
|
470
|
+
if (opening) {
|
471
|
+
re = guard + re;
|
472
|
+
if (re && re[re.length - 1] != "$")
|
473
|
+
re = re + "$";
|
474
|
+
} else {
|
475
|
+
re = re + guard;
|
476
|
+
if (re && re[0] != "^")
|
477
|
+
re = "^" + re;
|
478
|
+
}
|
479
|
+
return new RegExp(re);
|
480
|
+
}
|
481
|
+
|
482
|
+
function addSnippet(s) {
|
483
|
+
if (!s.scope)
|
484
|
+
s.scope = scope || "_";
|
485
|
+
scope = s.scope;
|
486
|
+
if (!snippetMap[scope]) {
|
487
|
+
snippetMap[scope] = [];
|
488
|
+
snippetNameMap[scope] = {};
|
489
|
+
}
|
490
|
+
|
491
|
+
var map = snippetNameMap[scope];
|
492
|
+
if (s.name) {
|
493
|
+
var old = map[s.name];
|
494
|
+
if (old)
|
495
|
+
self.unregister(old);
|
496
|
+
map[s.name] = s;
|
497
|
+
}
|
498
|
+
snippetMap[scope].push(s);
|
499
|
+
|
500
|
+
if (s.tabTrigger && !s.trigger) {
|
501
|
+
if (!s.guard && /^\w/.test(s.tabTrigger))
|
502
|
+
s.guard = "\\b";
|
503
|
+
s.trigger = lang.escapeRegExp(s.tabTrigger);
|
504
|
+
}
|
505
|
+
|
506
|
+
s.startRe = guardedRegexp(s.trigger, s.guard, true);
|
507
|
+
s.triggerRe = new RegExp(s.trigger, "", true);
|
508
|
+
|
509
|
+
s.endRe = guardedRegexp(s.endTrigger, s.endGuard, true);
|
510
|
+
s.endTriggerRe = new RegExp(s.endTrigger, "", true);
|
511
|
+
}
|
512
|
+
|
513
|
+
if (snippets && snippets.content)
|
514
|
+
addSnippet(snippets);
|
515
|
+
else if (Array.isArray(snippets))
|
516
|
+
snippets.forEach(addSnippet);
|
517
|
+
|
518
|
+
this._signal("registerSnippets", {scope: scope});
|
519
|
+
};
|
520
|
+
this.unregister = function(snippets, scope) {
|
521
|
+
var snippetMap = this.snippetMap;
|
522
|
+
var snippetNameMap = this.snippetNameMap;
|
523
|
+
|
524
|
+
function removeSnippet(s) {
|
525
|
+
var nameMap = snippetNameMap[s.scope||scope];
|
526
|
+
if (nameMap && nameMap[s.name]) {
|
527
|
+
delete nameMap[s.name];
|
528
|
+
var map = snippetMap[s.scope||scope];
|
529
|
+
var i = map && map.indexOf(s);
|
530
|
+
if (i >= 0)
|
531
|
+
map.splice(i, 1);
|
532
|
+
}
|
533
|
+
}
|
534
|
+
if (snippets.content)
|
535
|
+
removeSnippet(snippets);
|
536
|
+
else if (Array.isArray(snippets))
|
537
|
+
snippets.forEach(removeSnippet);
|
538
|
+
};
|
539
|
+
this.parseSnippetFile = function(str) {
|
540
|
+
str = str.replace(/\r/g, "");
|
541
|
+
var list = [], snippet = {};
|
542
|
+
var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
|
543
|
+
var m;
|
544
|
+
while (m = re.exec(str)) {
|
545
|
+
if (m[1]) {
|
546
|
+
try {
|
547
|
+
snippet = JSON.parse(m[1]);
|
548
|
+
list.push(snippet);
|
549
|
+
} catch (e) {}
|
550
|
+
} if (m[4]) {
|
551
|
+
snippet.content = m[4].replace(/^\t/gm, "");
|
552
|
+
list.push(snippet);
|
553
|
+
snippet = {};
|
554
|
+
} else {
|
555
|
+
var key = m[2], val = m[3];
|
556
|
+
if (key == "regex") {
|
557
|
+
var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g;
|
558
|
+
snippet.guard = guardRe.exec(val)[1];
|
559
|
+
snippet.trigger = guardRe.exec(val)[1];
|
560
|
+
snippet.endTrigger = guardRe.exec(val)[1];
|
561
|
+
snippet.endGuard = guardRe.exec(val)[1];
|
562
|
+
} else if (key == "snippet") {
|
563
|
+
snippet.tabTrigger = val.match(/^\S*/)[0];
|
564
|
+
if (!snippet.name)
|
565
|
+
snippet.name = val;
|
566
|
+
} else {
|
567
|
+
snippet[key] = val;
|
568
|
+
}
|
569
|
+
}
|
570
|
+
}
|
571
|
+
return list;
|
572
|
+
};
|
573
|
+
this.getSnippetByName = function(name, editor) {
|
574
|
+
var snippetMap = this.snippetNameMap;
|
575
|
+
var snippet;
|
576
|
+
this.getActiveScopes(editor).some(function(scope) {
|
577
|
+
var snippets = snippetMap[scope];
|
578
|
+
if (snippets)
|
579
|
+
snippet = snippets[name];
|
580
|
+
return !!snippet;
|
581
|
+
}, this);
|
582
|
+
return snippet;
|
583
|
+
};
|
584
|
+
|
585
|
+
}).call(SnippetManager.prototype);
|
586
|
+
|
587
|
+
|
588
|
+
var TabstopManager = function(editor) {
|
589
|
+
if (editor.tabstopManager)
|
590
|
+
return editor.tabstopManager;
|
591
|
+
editor.tabstopManager = this;
|
592
|
+
this.$onChange = this.onChange.bind(this);
|
593
|
+
this.$onChangeSelection = lang.delayedCall(this.onChangeSelection.bind(this)).schedule;
|
594
|
+
this.$onChangeSession = this.onChangeSession.bind(this);
|
595
|
+
this.$onAfterExec = this.onAfterExec.bind(this);
|
596
|
+
this.attach(editor);
|
597
|
+
};
|
598
|
+
(function() {
|
599
|
+
this.attach = function(editor) {
|
600
|
+
this.index = 0;
|
601
|
+
this.ranges = [];
|
602
|
+
this.tabstops = [];
|
603
|
+
this.$openTabstops = null;
|
604
|
+
this.selectedTabstop = null;
|
605
|
+
|
606
|
+
this.editor = editor;
|
607
|
+
this.editor.on("change", this.$onChange);
|
608
|
+
this.editor.on("changeSelection", this.$onChangeSelection);
|
609
|
+
this.editor.on("changeSession", this.$onChangeSession);
|
610
|
+
this.editor.commands.on("afterExec", this.$onAfterExec);
|
611
|
+
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
612
|
+
};
|
613
|
+
this.detach = function() {
|
614
|
+
this.tabstops.forEach(this.removeTabstopMarkers, this);
|
615
|
+
this.ranges = null;
|
616
|
+
this.tabstops = null;
|
617
|
+
this.selectedTabstop = null;
|
618
|
+
this.editor.removeListener("change", this.$onChange);
|
619
|
+
this.editor.removeListener("changeSelection", this.$onChangeSelection);
|
620
|
+
this.editor.removeListener("changeSession", this.$onChangeSession);
|
621
|
+
this.editor.commands.removeListener("afterExec", this.$onAfterExec);
|
622
|
+
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
|
623
|
+
this.editor.tabstopManager = null;
|
624
|
+
this.editor = null;
|
625
|
+
};
|
626
|
+
|
627
|
+
this.onChange = function(e) {
|
628
|
+
var changeRange = e.data.range;
|
629
|
+
var isRemove = e.data.action[0] == "r";
|
630
|
+
var start = changeRange.start;
|
631
|
+
var end = changeRange.end;
|
632
|
+
var startRow = start.row;
|
633
|
+
var endRow = end.row;
|
634
|
+
var lineDif = endRow - startRow;
|
635
|
+
var colDiff = end.column - start.column;
|
636
|
+
|
637
|
+
if (isRemove) {
|
638
|
+
lineDif = -lineDif;
|
639
|
+
colDiff = -colDiff;
|
640
|
+
}
|
641
|
+
if (!this.$inChange && isRemove) {
|
642
|
+
var ts = this.selectedTabstop;
|
643
|
+
var changedOutside = ts && !ts.some(function(r) {
|
644
|
+
return comparePoints(r.start, start) <= 0 && comparePoints(r.end, end) >= 0;
|
645
|
+
});
|
646
|
+
if (changedOutside)
|
647
|
+
return this.detach();
|
648
|
+
}
|
649
|
+
var ranges = this.ranges;
|
650
|
+
for (var i = 0; i < ranges.length; i++) {
|
651
|
+
var r = ranges[i];
|
652
|
+
if (r.end.row < start.row)
|
653
|
+
continue;
|
654
|
+
|
655
|
+
if (isRemove && comparePoints(start, r.start) < 0 && comparePoints(end, r.end) > 0) {
|
656
|
+
this.removeRange(r);
|
657
|
+
i--;
|
658
|
+
continue;
|
659
|
+
}
|
660
|
+
|
661
|
+
if (r.start.row == startRow && r.start.column > start.column)
|
662
|
+
r.start.column += colDiff;
|
663
|
+
if (r.end.row == startRow && r.end.column >= start.column)
|
664
|
+
r.end.column += colDiff;
|
665
|
+
if (r.start.row >= startRow)
|
666
|
+
r.start.row += lineDif;
|
667
|
+
if (r.end.row >= startRow)
|
668
|
+
r.end.row += lineDif;
|
669
|
+
|
670
|
+
if (comparePoints(r.start, r.end) > 0)
|
671
|
+
this.removeRange(r);
|
672
|
+
}
|
673
|
+
if (!ranges.length)
|
674
|
+
this.detach();
|
675
|
+
};
|
676
|
+
this.updateLinkedFields = function() {
|
677
|
+
var ts = this.selectedTabstop;
|
678
|
+
if (!ts || !ts.hasLinkedRanges)
|
679
|
+
return;
|
680
|
+
this.$inChange = true;
|
681
|
+
var session = this.editor.session;
|
682
|
+
var text = session.getTextRange(ts.firstNonLinked);
|
683
|
+
for (var i = ts.length; i--;) {
|
684
|
+
var range = ts[i];
|
685
|
+
if (!range.linked)
|
686
|
+
continue;
|
687
|
+
var fmt = exports.snippetManager.tmStrFormat(text, range.original);
|
688
|
+
session.replace(range, fmt);
|
689
|
+
}
|
690
|
+
this.$inChange = false;
|
691
|
+
};
|
692
|
+
this.onAfterExec = function(e) {
|
693
|
+
if (e.command && !e.command.readOnly)
|
694
|
+
this.updateLinkedFields();
|
695
|
+
};
|
696
|
+
this.onChangeSelection = function() {
|
697
|
+
if (!this.editor)
|
698
|
+
return;
|
699
|
+
var lead = this.editor.selection.lead;
|
700
|
+
var anchor = this.editor.selection.anchor;
|
701
|
+
var isEmpty = this.editor.selection.isEmpty();
|
702
|
+
for (var i = this.ranges.length; i--;) {
|
703
|
+
if (this.ranges[i].linked)
|
704
|
+
continue;
|
705
|
+
var containsLead = this.ranges[i].contains(lead.row, lead.column);
|
706
|
+
var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column);
|
707
|
+
if (containsLead && containsAnchor)
|
708
|
+
return;
|
709
|
+
}
|
710
|
+
this.detach();
|
711
|
+
};
|
712
|
+
this.onChangeSession = function() {
|
713
|
+
this.detach();
|
714
|
+
};
|
715
|
+
this.tabNext = function(dir) {
|
716
|
+
var max = this.tabstops.length;
|
717
|
+
var index = this.index + (dir || 1);
|
718
|
+
index = Math.min(Math.max(index, 1), max);
|
719
|
+
if (index == max)
|
720
|
+
index = 0;
|
721
|
+
this.selectTabstop(index);
|
722
|
+
if (index === 0)
|
723
|
+
this.detach();
|
724
|
+
};
|
725
|
+
this.selectTabstop = function(index) {
|
726
|
+
this.$openTabstops = null;
|
727
|
+
var ts = this.tabstops[this.index];
|
728
|
+
if (ts)
|
729
|
+
this.addTabstopMarkers(ts);
|
730
|
+
this.index = index;
|
731
|
+
ts = this.tabstops[this.index];
|
732
|
+
if (!ts || !ts.length)
|
733
|
+
return;
|
734
|
+
|
735
|
+
this.selectedTabstop = ts;
|
736
|
+
if (!this.editor.inVirtualSelectionMode) {
|
737
|
+
var sel = this.editor.multiSelect;
|
738
|
+
sel.toSingleRange(ts.firstNonLinked.clone());
|
739
|
+
for (var i = ts.length; i--;) {
|
740
|
+
if (ts.hasLinkedRanges && ts[i].linked)
|
741
|
+
continue;
|
742
|
+
sel.addRange(ts[i].clone(), true);
|
743
|
+
}
|
744
|
+
if (sel.ranges[0])
|
745
|
+
sel.addRange(sel.ranges[0].clone());
|
746
|
+
} else {
|
747
|
+
this.editor.selection.setRange(ts.firstNonLinked);
|
748
|
+
}
|
749
|
+
|
750
|
+
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
751
|
+
};
|
752
|
+
this.addTabstops = function(tabstops, start, end) {
|
753
|
+
if (!this.$openTabstops)
|
754
|
+
this.$openTabstops = [];
|
755
|
+
if (!tabstops[0]) {
|
756
|
+
var p = Range.fromPoints(end, end);
|
757
|
+
moveRelative(p.start, start);
|
758
|
+
moveRelative(p.end, start);
|
759
|
+
tabstops[0] = [p];
|
760
|
+
tabstops[0].index = 0;
|
761
|
+
}
|
762
|
+
|
763
|
+
var i = this.index;
|
764
|
+
var arg = [i + 1, 0];
|
765
|
+
var ranges = this.ranges;
|
766
|
+
tabstops.forEach(function(ts, index) {
|
767
|
+
var dest = this.$openTabstops[index] || ts;
|
768
|
+
|
769
|
+
for (var i = ts.length; i--;) {
|
770
|
+
var p = ts[i];
|
771
|
+
var range = Range.fromPoints(p.start, p.end || p.start);
|
772
|
+
movePoint(range.start, start);
|
773
|
+
movePoint(range.end, start);
|
774
|
+
range.original = p;
|
775
|
+
range.tabstop = dest;
|
776
|
+
ranges.push(range);
|
777
|
+
if (dest != ts)
|
778
|
+
dest.unshift(range);
|
779
|
+
else
|
780
|
+
dest[i] = range;
|
781
|
+
if (p.fmtString) {
|
782
|
+
range.linked = true;
|
783
|
+
dest.hasLinkedRanges = true;
|
784
|
+
} else if (!dest.firstNonLinked)
|
785
|
+
dest.firstNonLinked = range;
|
786
|
+
}
|
787
|
+
if (!dest.firstNonLinked)
|
788
|
+
dest.hasLinkedRanges = false;
|
789
|
+
if (dest === ts) {
|
790
|
+
arg.push(dest);
|
791
|
+
this.$openTabstops[index] = dest;
|
792
|
+
}
|
793
|
+
this.addTabstopMarkers(dest);
|
794
|
+
}, this);
|
795
|
+
|
796
|
+
if (arg.length > 2) {
|
797
|
+
if (this.tabstops.length)
|
798
|
+
arg.push(arg.splice(2, 1)[0]);
|
799
|
+
this.tabstops.splice.apply(this.tabstops, arg);
|
800
|
+
}
|
801
|
+
};
|
802
|
+
|
803
|
+
this.addTabstopMarkers = function(ts) {
|
804
|
+
var session = this.editor.session;
|
805
|
+
ts.forEach(function(range) {
|
806
|
+
if (!range.markerId)
|
807
|
+
range.markerId = session.addMarker(range, "ace_snippet-marker", "text");
|
808
|
+
});
|
809
|
+
};
|
810
|
+
this.removeTabstopMarkers = function(ts) {
|
811
|
+
var session = this.editor.session;
|
812
|
+
ts.forEach(function(range) {
|
813
|
+
session.removeMarker(range.markerId);
|
814
|
+
range.markerId = null;
|
815
|
+
});
|
816
|
+
};
|
817
|
+
this.removeRange = function(range) {
|
818
|
+
var i = range.tabstop.indexOf(range);
|
819
|
+
range.tabstop.splice(i, 1);
|
820
|
+
i = this.ranges.indexOf(range);
|
821
|
+
this.ranges.splice(i, 1);
|
822
|
+
this.editor.session.removeMarker(range.markerId);
|
823
|
+
if (!range.tabstop.length) {
|
824
|
+
i = this.tabstops.indexOf(range.tabstop);
|
825
|
+
if (i != -1)
|
826
|
+
this.tabstops.splice(i, 1);
|
827
|
+
if (!this.tabstops.length)
|
828
|
+
this.detach();
|
829
|
+
}
|
830
|
+
};
|
831
|
+
|
832
|
+
this.keyboardHandler = new HashHandler();
|
833
|
+
this.keyboardHandler.bindKeys({
|
834
|
+
"Tab": function(ed) {
|
835
|
+
if (exports.snippetManager && exports.snippetManager.expandWithTab(ed)) {
|
836
|
+
return;
|
837
|
+
}
|
838
|
+
|
839
|
+
ed.tabstopManager.tabNext(1);
|
840
|
+
},
|
841
|
+
"Shift-Tab": function(ed) {
|
842
|
+
ed.tabstopManager.tabNext(-1);
|
843
|
+
},
|
844
|
+
"Esc": function(ed) {
|
845
|
+
ed.tabstopManager.detach();
|
846
|
+
},
|
847
|
+
"Return": function(ed) {
|
848
|
+
return false;
|
849
|
+
}
|
850
|
+
});
|
851
|
+
}).call(TabstopManager.prototype);
|
852
|
+
|
853
|
+
|
854
|
+
|
855
|
+
var changeTracker = {};
|
856
|
+
changeTracker.onChange = Anchor.prototype.onChange;
|
857
|
+
changeTracker.setPosition = function(row, column) {
|
858
|
+
this.pos.row = row;
|
859
|
+
this.pos.column = column;
|
860
|
+
};
|
861
|
+
changeTracker.update = function(pos, delta, $insertRight) {
|
862
|
+
this.$insertRight = $insertRight;
|
863
|
+
this.pos = pos;
|
864
|
+
this.onChange(delta);
|
865
|
+
};
|
866
|
+
|
867
|
+
var movePoint = function(point, diff) {
|
868
|
+
if (point.row == 0)
|
869
|
+
point.column += diff.column;
|
870
|
+
point.row += diff.row;
|
871
|
+
};
|
872
|
+
|
873
|
+
var moveRelative = function(point, start) {
|
874
|
+
if (point.row == start.row)
|
875
|
+
point.column -= start.column;
|
876
|
+
point.row -= start.row;
|
877
|
+
};
|
878
|
+
|
879
|
+
|
880
|
+
require("./lib/dom").importCssString("\
|
881
|
+
.ace_snippet-marker {\
|
882
|
+
-moz-box-sizing: border-box;\
|
883
|
+
box-sizing: border-box;\
|
884
|
+
background: rgba(194, 193, 208, 0.09);\
|
885
|
+
border: 1px dotted rgba(211, 208, 235, 0.62);\
|
886
|
+
position: absolute;\
|
887
|
+
}");
|
888
|
+
|
889
|
+
exports.snippetManager = new SnippetManager();
|
890
|
+
|
891
|
+
|
892
|
+
var Editor = require("./editor").Editor;
|
893
|
+
(function() {
|
894
|
+
this.insertSnippet = function(content, options) {
|
895
|
+
return exports.snippetManager.insertSnippet(this, content, options);
|
896
|
+
};
|
897
|
+
this.expandSnippet = function(options) {
|
898
|
+
return exports.snippetManager.expandWithTab(this, options);
|
899
|
+
};
|
900
|
+
}).call(Editor.prototype);
|
901
|
+
|
902
|
+
});
|
903
|
+
|
904
|
+
ace.define("ace/autocomplete/popup",["require","exports","module","ace/edit_session","ace/virtual_renderer","ace/editor","ace/range","ace/lib/event","ace/lib/lang","ace/lib/dom"], function(require, exports, module) {
|
905
|
+
"use strict";
|
906
|
+
|
907
|
+
var EditSession = require("../edit_session").EditSession;
|
908
|
+
var Renderer = require("../virtual_renderer").VirtualRenderer;
|
909
|
+
var Editor = require("../editor").Editor;
|
910
|
+
var Range = require("../range").Range;
|
911
|
+
var event = require("../lib/event");
|
912
|
+
var lang = require("../lib/lang");
|
913
|
+
var dom = require("../lib/dom");
|
914
|
+
|
915
|
+
var $singleLineEditor = function(el) {
|
916
|
+
var renderer = new Renderer(el);
|
917
|
+
|
918
|
+
renderer.$maxLines = 4;
|
919
|
+
|
920
|
+
var editor = new Editor(renderer);
|
921
|
+
|
922
|
+
editor.setHighlightActiveLine(false);
|
923
|
+
editor.setShowPrintMargin(false);
|
924
|
+
editor.renderer.setShowGutter(false);
|
925
|
+
editor.renderer.setHighlightGutterLine(false);
|
926
|
+
|
927
|
+
editor.$mouseHandler.$focusWaitTimout = 0;
|
928
|
+
editor.$highlightTagPending = true;
|
929
|
+
|
930
|
+
return editor;
|
931
|
+
};
|
932
|
+
|
933
|
+
var AcePopup = function(parentNode) {
|
934
|
+
var el = dom.createElement("div");
|
935
|
+
var popup = new $singleLineEditor(el);
|
936
|
+
|
937
|
+
if (parentNode)
|
938
|
+
parentNode.appendChild(el);
|
939
|
+
el.style.display = "none";
|
940
|
+
popup.renderer.content.style.cursor = "default";
|
941
|
+
popup.renderer.setStyle("ace_autocomplete");
|
942
|
+
|
943
|
+
popup.setOption("displayIndentGuides", false);
|
944
|
+
popup.setOption("dragDelay", 150);
|
945
|
+
|
946
|
+
var noop = function(){};
|
947
|
+
|
948
|
+
popup.focus = noop;
|
949
|
+
popup.$isFocused = true;
|
950
|
+
|
951
|
+
popup.renderer.$cursorLayer.restartTimer = noop;
|
952
|
+
popup.renderer.$cursorLayer.element.style.opacity = 0;
|
953
|
+
|
954
|
+
popup.renderer.$maxLines = 8;
|
955
|
+
popup.renderer.$keepTextAreaAtCursor = false;
|
956
|
+
|
957
|
+
popup.setHighlightActiveLine(false);
|
958
|
+
popup.session.highlight("");
|
959
|
+
popup.session.$searchHighlight.clazz = "ace_highlight-marker";
|
960
|
+
|
961
|
+
popup.on("mousedown", function(e) {
|
962
|
+
var pos = e.getDocumentPosition();
|
963
|
+
popup.selection.moveToPosition(pos);
|
964
|
+
selectionMarker.start.row = selectionMarker.end.row = pos.row;
|
965
|
+
e.stop();
|
966
|
+
});
|
967
|
+
|
968
|
+
var lastMouseEvent;
|
969
|
+
var hoverMarker = new Range(-1,0,-1,Infinity);
|
970
|
+
var selectionMarker = new Range(-1,0,-1,Infinity);
|
971
|
+
selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine");
|
972
|
+
popup.setSelectOnHover = function(val) {
|
973
|
+
if (!val) {
|
974
|
+
hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
|
975
|
+
} else if (hoverMarker.id) {
|
976
|
+
popup.session.removeMarker(hoverMarker.id);
|
977
|
+
hoverMarker.id = null;
|
978
|
+
}
|
979
|
+
};
|
980
|
+
popup.setSelectOnHover(false);
|
981
|
+
popup.on("mousemove", function(e) {
|
982
|
+
if (!lastMouseEvent) {
|
983
|
+
lastMouseEvent = e;
|
984
|
+
return;
|
985
|
+
}
|
986
|
+
if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) {
|
987
|
+
return;
|
988
|
+
}
|
989
|
+
lastMouseEvent = e;
|
990
|
+
lastMouseEvent.scrollTop = popup.renderer.scrollTop;
|
991
|
+
var row = lastMouseEvent.getDocumentPosition().row;
|
992
|
+
if (hoverMarker.start.row != row) {
|
993
|
+
if (!hoverMarker.id)
|
994
|
+
popup.setRow(row);
|
995
|
+
setHoverMarker(row);
|
996
|
+
}
|
997
|
+
});
|
998
|
+
popup.renderer.on("beforeRender", function() {
|
999
|
+
if (lastMouseEvent && hoverMarker.start.row != -1) {
|
1000
|
+
lastMouseEvent.$pos = null;
|
1001
|
+
var row = lastMouseEvent.getDocumentPosition().row;
|
1002
|
+
if (!hoverMarker.id)
|
1003
|
+
popup.setRow(row);
|
1004
|
+
setHoverMarker(row, true);
|
1005
|
+
}
|
1006
|
+
});
|
1007
|
+
popup.renderer.on("afterRender", function() {
|
1008
|
+
var row = popup.getRow();
|
1009
|
+
var t = popup.renderer.$textLayer;
|
1010
|
+
var selected = t.element.childNodes[row - t.config.firstRow];
|
1011
|
+
if (selected == t.selectedNode)
|
1012
|
+
return;
|
1013
|
+
if (t.selectedNode)
|
1014
|
+
dom.removeCssClass(t.selectedNode, "ace_selected");
|
1015
|
+
t.selectedNode = selected;
|
1016
|
+
if (selected)
|
1017
|
+
dom.addCssClass(selected, "ace_selected");
|
1018
|
+
});
|
1019
|
+
var hideHoverMarker = function() { setHoverMarker(-1) };
|
1020
|
+
var setHoverMarker = function(row, suppressRedraw) {
|
1021
|
+
if (row !== hoverMarker.start.row) {
|
1022
|
+
hoverMarker.start.row = hoverMarker.end.row = row;
|
1023
|
+
if (!suppressRedraw)
|
1024
|
+
popup.session._emit("changeBackMarker");
|
1025
|
+
popup._emit("changeHoverMarker");
|
1026
|
+
}
|
1027
|
+
};
|
1028
|
+
popup.getHoveredRow = function() {
|
1029
|
+
return hoverMarker.start.row;
|
1030
|
+
};
|
1031
|
+
|
1032
|
+
event.addListener(popup.container, "mouseout", hideHoverMarker);
|
1033
|
+
popup.on("hide", hideHoverMarker);
|
1034
|
+
popup.on("changeSelection", hideHoverMarker);
|
1035
|
+
|
1036
|
+
popup.session.doc.getLength = function() {
|
1037
|
+
return popup.data.length;
|
1038
|
+
};
|
1039
|
+
popup.session.doc.getLine = function(i) {
|
1040
|
+
var data = popup.data[i];
|
1041
|
+
if (typeof data == "string")
|
1042
|
+
return data;
|
1043
|
+
return (data && data.value) || "";
|
1044
|
+
};
|
1045
|
+
|
1046
|
+
var bgTokenizer = popup.session.bgTokenizer;
|
1047
|
+
bgTokenizer.$tokenizeRow = function(row) {
|
1048
|
+
var data = popup.data[row];
|
1049
|
+
var tokens = [];
|
1050
|
+
if (!data)
|
1051
|
+
return tokens;
|
1052
|
+
if (typeof data == "string")
|
1053
|
+
data = {value: data};
|
1054
|
+
if (!data.caption)
|
1055
|
+
data.caption = data.value || data.name;
|
1056
|
+
|
1057
|
+
var last = -1;
|
1058
|
+
var flag, c;
|
1059
|
+
for (var i = 0; i < data.caption.length; i++) {
|
1060
|
+
c = data.caption[i];
|
1061
|
+
flag = data.matchMask & (1 << i) ? 1 : 0;
|
1062
|
+
if (last !== flag) {
|
1063
|
+
tokens.push({type: data.className || "" + ( flag ? "completion-highlight" : ""), value: c});
|
1064
|
+
last = flag;
|
1065
|
+
} else {
|
1066
|
+
tokens[tokens.length - 1].value += c;
|
1067
|
+
}
|
1068
|
+
}
|
1069
|
+
|
1070
|
+
if (data.meta) {
|
1071
|
+
var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth;
|
1072
|
+
if (data.meta.length + data.caption.length < maxW - 2)
|
1073
|
+
tokens.push({type: "rightAlignedText", value: data.meta});
|
1074
|
+
}
|
1075
|
+
return tokens;
|
1076
|
+
};
|
1077
|
+
bgTokenizer.$updateOnChange = noop;
|
1078
|
+
bgTokenizer.start = noop;
|
1079
|
+
|
1080
|
+
popup.session.$computeWidth = function() {
|
1081
|
+
return this.screenWidth = 0;
|
1082
|
+
};
|
1083
|
+
|
1084
|
+
popup.$blockScrolling = Infinity;
|
1085
|
+
popup.isOpen = false;
|
1086
|
+
popup.isTopdown = false;
|
1087
|
+
|
1088
|
+
popup.data = [];
|
1089
|
+
popup.setData = function(list) {
|
1090
|
+
popup.data = list || [];
|
1091
|
+
popup.setValue(lang.stringRepeat("\n", list.length), -1);
|
1092
|
+
popup.setRow(0);
|
1093
|
+
};
|
1094
|
+
popup.getData = function(row) {
|
1095
|
+
return popup.data[row];
|
1096
|
+
};
|
1097
|
+
|
1098
|
+
popup.getRow = function() {
|
1099
|
+
return selectionMarker.start.row;
|
1100
|
+
};
|
1101
|
+
popup.setRow = function(line) {
|
1102
|
+
line = Math.max(-1, Math.min(this.data.length, line));
|
1103
|
+
if (selectionMarker.start.row != line) {
|
1104
|
+
popup.selection.clearSelection();
|
1105
|
+
selectionMarker.start.row = selectionMarker.end.row = line || 0;
|
1106
|
+
popup.session._emit("changeBackMarker");
|
1107
|
+
popup.moveCursorTo(line || 0, 0);
|
1108
|
+
if (popup.isOpen)
|
1109
|
+
popup._signal("select");
|
1110
|
+
}
|
1111
|
+
};
|
1112
|
+
|
1113
|
+
popup.on("changeSelection", function() {
|
1114
|
+
if (popup.isOpen)
|
1115
|
+
popup.setRow(popup.selection.lead.row);
|
1116
|
+
popup.renderer.scrollCursorIntoView();
|
1117
|
+
});
|
1118
|
+
|
1119
|
+
popup.hide = function() {
|
1120
|
+
this.container.style.display = "none";
|
1121
|
+
this._signal("hide");
|
1122
|
+
popup.isOpen = false;
|
1123
|
+
};
|
1124
|
+
popup.show = function(pos, lineHeight, topdownOnly) {
|
1125
|
+
var el = this.container;
|
1126
|
+
var screenHeight = window.innerHeight;
|
1127
|
+
var screenWidth = window.innerWidth;
|
1128
|
+
var renderer = this.renderer;
|
1129
|
+
var maxH = renderer.$maxLines * lineHeight * 1.4;
|
1130
|
+
var top = pos.top + this.$borderSize;
|
1131
|
+
if (top + maxH > screenHeight - lineHeight && !topdownOnly) {
|
1132
|
+
el.style.top = "";
|
1133
|
+
el.style.bottom = screenHeight - top + "px";
|
1134
|
+
popup.isTopdown = false;
|
1135
|
+
} else {
|
1136
|
+
top += lineHeight;
|
1137
|
+
el.style.top = top + "px";
|
1138
|
+
el.style.bottom = "";
|
1139
|
+
popup.isTopdown = true;
|
1140
|
+
}
|
1141
|
+
|
1142
|
+
el.style.display = "";
|
1143
|
+
this.renderer.$textLayer.checkForSizeChanges();
|
1144
|
+
|
1145
|
+
var left = pos.left;
|
1146
|
+
if (left + el.offsetWidth > screenWidth)
|
1147
|
+
left = screenWidth - el.offsetWidth;
|
1148
|
+
|
1149
|
+
el.style.left = left + "px";
|
1150
|
+
|
1151
|
+
this._signal("show");
|
1152
|
+
lastMouseEvent = null;
|
1153
|
+
popup.isOpen = true;
|
1154
|
+
};
|
1155
|
+
|
1156
|
+
popup.getTextLeftOffset = function() {
|
1157
|
+
return this.$borderSize + this.renderer.$padding + this.$imageSize;
|
1158
|
+
};
|
1159
|
+
|
1160
|
+
popup.$imageSize = 0;
|
1161
|
+
popup.$borderSize = 1;
|
1162
|
+
|
1163
|
+
return popup;
|
1164
|
+
};
|
1165
|
+
|
1166
|
+
dom.importCssString("\
|
1167
|
+
.ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line {\
|
1168
|
+
background-color: #CAD6FA;\
|
1169
|
+
z-index: 1;\
|
1170
|
+
}\
|
1171
|
+
.ace_editor.ace_autocomplete .ace_line-hover {\
|
1172
|
+
border: 1px solid #abbffe;\
|
1173
|
+
margin-top: -1px;\
|
1174
|
+
background: rgba(233,233,253,0.4);\
|
1175
|
+
}\
|
1176
|
+
.ace_editor.ace_autocomplete .ace_line-hover {\
|
1177
|
+
position: absolute;\
|
1178
|
+
z-index: 2;\
|
1179
|
+
}\
|
1180
|
+
.ace_editor.ace_autocomplete .ace_scroller {\
|
1181
|
+
background: none;\
|
1182
|
+
border: none;\
|
1183
|
+
box-shadow: none;\
|
1184
|
+
}\
|
1185
|
+
.ace_rightAlignedText {\
|
1186
|
+
color: gray;\
|
1187
|
+
display: inline-block;\
|
1188
|
+
position: absolute;\
|
1189
|
+
right: 4px;\
|
1190
|
+
text-align: right;\
|
1191
|
+
z-index: -1;\
|
1192
|
+
}\
|
1193
|
+
.ace_editor.ace_autocomplete .ace_completion-highlight{\
|
1194
|
+
color: #000;\
|
1195
|
+
text-shadow: 0 0 0.01em;\
|
1196
|
+
}\
|
1197
|
+
.ace_editor.ace_autocomplete {\
|
1198
|
+
width: 280px;\
|
1199
|
+
z-index: 200000;\
|
1200
|
+
background: #fbfbfb;\
|
1201
|
+
color: #444;\
|
1202
|
+
border: 1px lightgray solid;\
|
1203
|
+
position: fixed;\
|
1204
|
+
box-shadow: 2px 3px 5px rgba(0,0,0,.2);\
|
1205
|
+
line-height: 1.4;\
|
1206
|
+
}");
|
1207
|
+
|
1208
|
+
exports.AcePopup = AcePopup;
|
1209
|
+
|
1210
|
+
});
|
1211
|
+
|
1212
|
+
ace.define("ace/autocomplete/util",["require","exports","module"], function(require, exports, module) {
|
1213
|
+
"use strict";
|
1214
|
+
|
1215
|
+
exports.parForEach = function(array, fn, callback) {
|
1216
|
+
var completed = 0;
|
1217
|
+
var arLength = array.length;
|
1218
|
+
if (arLength === 0)
|
1219
|
+
callback();
|
1220
|
+
for (var i = 0; i < arLength; i++) {
|
1221
|
+
fn(array[i], function(result, err) {
|
1222
|
+
completed++;
|
1223
|
+
if (completed === arLength)
|
1224
|
+
callback(result, err);
|
1225
|
+
});
|
1226
|
+
}
|
1227
|
+
};
|
1228
|
+
|
1229
|
+
var ID_REGEX = /[a-zA-Z_0-9\$\-\u00A2-\uFFFF]/;
|
1230
|
+
|
1231
|
+
exports.retrievePrecedingIdentifier = function(text, pos, regex) {
|
1232
|
+
regex = regex || ID_REGEX;
|
1233
|
+
var buf = [];
|
1234
|
+
for (var i = pos-1; i >= 0; i--) {
|
1235
|
+
if (regex.test(text[i]))
|
1236
|
+
buf.push(text[i]);
|
1237
|
+
else
|
1238
|
+
break;
|
1239
|
+
}
|
1240
|
+
return buf.reverse().join("");
|
1241
|
+
};
|
1242
|
+
|
1243
|
+
exports.retrieveFollowingIdentifier = function(text, pos, regex) {
|
1244
|
+
regex = regex || ID_REGEX;
|
1245
|
+
var buf = [];
|
1246
|
+
for (var i = pos; i < text.length; i++) {
|
1247
|
+
if (regex.test(text[i]))
|
1248
|
+
buf.push(text[i]);
|
1249
|
+
else
|
1250
|
+
break;
|
1251
|
+
}
|
1252
|
+
return buf;
|
1253
|
+
};
|
1254
|
+
|
1255
|
+
});
|
1256
|
+
|
1257
|
+
ace.define("ace/autocomplete",["require","exports","module","ace/keyboard/hash_handler","ace/autocomplete/popup","ace/autocomplete/util","ace/lib/event","ace/lib/lang","ace/lib/dom","ace/snippets"], function(require, exports, module) {
|
1258
|
+
"use strict";
|
1259
|
+
|
1260
|
+
var HashHandler = require("./keyboard/hash_handler").HashHandler;
|
1261
|
+
var AcePopup = require("./autocomplete/popup").AcePopup;
|
1262
|
+
var util = require("./autocomplete/util");
|
1263
|
+
var event = require("./lib/event");
|
1264
|
+
var lang = require("./lib/lang");
|
1265
|
+
var dom = require("./lib/dom");
|
1266
|
+
var snippetManager = require("./snippets").snippetManager;
|
1267
|
+
|
1268
|
+
var Autocomplete = function() {
|
1269
|
+
this.autoInsert = true;
|
1270
|
+
this.autoSelect = true;
|
1271
|
+
this.exactMatch = false;
|
1272
|
+
this.keyboardHandler = new HashHandler();
|
1273
|
+
this.keyboardHandler.bindKeys(this.commands);
|
1274
|
+
|
1275
|
+
this.blurListener = this.blurListener.bind(this);
|
1276
|
+
this.changeListener = this.changeListener.bind(this);
|
1277
|
+
this.mousedownListener = this.mousedownListener.bind(this);
|
1278
|
+
this.mousewheelListener = this.mousewheelListener.bind(this);
|
1279
|
+
|
1280
|
+
this.changeTimer = lang.delayedCall(function() {
|
1281
|
+
this.updateCompletions(true);
|
1282
|
+
}.bind(this));
|
1283
|
+
|
1284
|
+
this.tooltipTimer = lang.delayedCall(this.updateDocTooltip.bind(this), 50);
|
1285
|
+
};
|
1286
|
+
|
1287
|
+
(function() {
|
1288
|
+
this.gatherCompletionsId = 0;
|
1289
|
+
|
1290
|
+
this.$init = function() {
|
1291
|
+
this.popup = new AcePopup(document.body || document.documentElement);
|
1292
|
+
this.popup.on("click", function(e) {
|
1293
|
+
this.insertMatch();
|
1294
|
+
e.stop();
|
1295
|
+
}.bind(this));
|
1296
|
+
this.popup.focus = this.editor.focus.bind(this.editor);
|
1297
|
+
this.popup.on("show", this.tooltipTimer.bind(null, null));
|
1298
|
+
this.popup.on("select", this.tooltipTimer.bind(null, null));
|
1299
|
+
this.popup.on("changeHoverMarker", this.tooltipTimer.bind(null, null));
|
1300
|
+
return this.popup;
|
1301
|
+
};
|
1302
|
+
|
1303
|
+
this.getPopup = function() {
|
1304
|
+
return this.popup || this.$init();
|
1305
|
+
};
|
1306
|
+
|
1307
|
+
this.openPopup = function(editor, prefix, keepPopupPosition) {
|
1308
|
+
if (!this.popup)
|
1309
|
+
this.$init();
|
1310
|
+
|
1311
|
+
this.popup.setData(this.completions.filtered);
|
1312
|
+
|
1313
|
+
var renderer = editor.renderer;
|
1314
|
+
this.popup.setRow(this.autoSelect ? 0 : -1);
|
1315
|
+
if (!keepPopupPosition) {
|
1316
|
+
this.popup.setTheme(editor.getTheme());
|
1317
|
+
this.popup.setFontSize(editor.getFontSize());
|
1318
|
+
|
1319
|
+
var lineHeight = renderer.layerConfig.lineHeight;
|
1320
|
+
|
1321
|
+
var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
|
1322
|
+
pos.left -= this.popup.getTextLeftOffset();
|
1323
|
+
|
1324
|
+
var rect = editor.container.getBoundingClientRect();
|
1325
|
+
pos.top += rect.top - renderer.layerConfig.offset;
|
1326
|
+
pos.left += rect.left - editor.renderer.scrollLeft;
|
1327
|
+
pos.left += renderer.$gutterLayer.gutterWidth;
|
1328
|
+
|
1329
|
+
this.popup.show(pos, lineHeight);
|
1330
|
+
} else if (keepPopupPosition && !prefix) {
|
1331
|
+
this.detach();
|
1332
|
+
}
|
1333
|
+
};
|
1334
|
+
|
1335
|
+
this.detach = function() {
|
1336
|
+
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
|
1337
|
+
this.editor.off("changeSelection", this.changeListener);
|
1338
|
+
this.editor.off("blur", this.blurListener);
|
1339
|
+
this.editor.off("mousedown", this.mousedownListener);
|
1340
|
+
this.editor.off("mousewheel", this.mousewheelListener);
|
1341
|
+
this.changeTimer.cancel();
|
1342
|
+
this.hideDocTooltip();
|
1343
|
+
|
1344
|
+
if (this.popup && this.popup.isOpen) {
|
1345
|
+
this.gatherCompletionsId += 1;
|
1346
|
+
this.popup.hide();
|
1347
|
+
}
|
1348
|
+
|
1349
|
+
if (this.base)
|
1350
|
+
this.base.detach();
|
1351
|
+
this.activated = false;
|
1352
|
+
this.completions = this.base = null;
|
1353
|
+
};
|
1354
|
+
|
1355
|
+
this.changeListener = function(e) {
|
1356
|
+
var cursor = this.editor.selection.lead;
|
1357
|
+
if (cursor.row != this.base.row || cursor.column < this.base.column) {
|
1358
|
+
this.detach();
|
1359
|
+
}
|
1360
|
+
if (this.activated)
|
1361
|
+
this.changeTimer.schedule();
|
1362
|
+
else
|
1363
|
+
this.detach();
|
1364
|
+
};
|
1365
|
+
|
1366
|
+
this.blurListener = function(e) {
|
1367
|
+
var el = document.activeElement;
|
1368
|
+
var text = this.editor.textInput.getElement()
|
1369
|
+
if (el != text && el.parentNode != this.popup.container
|
1370
|
+
&& el != this.tooltipNode && e.relatedTarget != this.tooltipNode
|
1371
|
+
&& e.relatedTarget != text
|
1372
|
+
) {
|
1373
|
+
this.detach();
|
1374
|
+
}
|
1375
|
+
};
|
1376
|
+
|
1377
|
+
this.mousedownListener = function(e) {
|
1378
|
+
this.detach();
|
1379
|
+
};
|
1380
|
+
|
1381
|
+
this.mousewheelListener = function(e) {
|
1382
|
+
this.detach();
|
1383
|
+
};
|
1384
|
+
|
1385
|
+
this.goTo = function(where) {
|
1386
|
+
var row = this.popup.getRow();
|
1387
|
+
var max = this.popup.session.getLength() - 1;
|
1388
|
+
|
1389
|
+
switch(where) {
|
1390
|
+
case "up": row = row <= 0 ? max : row - 1; break;
|
1391
|
+
case "down": row = row >= max ? -1 : row + 1; break;
|
1392
|
+
case "start": row = 0; break;
|
1393
|
+
case "end": row = max; break;
|
1394
|
+
}
|
1395
|
+
|
1396
|
+
this.popup.setRow(row);
|
1397
|
+
};
|
1398
|
+
|
1399
|
+
this.insertMatch = function(data) {
|
1400
|
+
if (!data)
|
1401
|
+
data = this.popup.getData(this.popup.getRow());
|
1402
|
+
if (!data)
|
1403
|
+
return false;
|
1404
|
+
|
1405
|
+
if (data.completer && data.completer.insertMatch) {
|
1406
|
+
data.completer.insertMatch(this.editor, data);
|
1407
|
+
} else {
|
1408
|
+
if (this.completions.filterText) {
|
1409
|
+
var ranges = this.editor.selection.getAllRanges();
|
1410
|
+
for (var i = 0, range; range = ranges[i]; i++) {
|
1411
|
+
range.start.column -= this.completions.filterText.length;
|
1412
|
+
this.editor.session.remove(range);
|
1413
|
+
}
|
1414
|
+
}
|
1415
|
+
if (data.snippet)
|
1416
|
+
snippetManager.insertSnippet(this.editor, data.snippet);
|
1417
|
+
else
|
1418
|
+
this.editor.execCommand("insertstring", data.value || data);
|
1419
|
+
}
|
1420
|
+
this.detach();
|
1421
|
+
};
|
1422
|
+
|
1423
|
+
|
1424
|
+
this.commands = {
|
1425
|
+
"Up": function(editor) { editor.completer.goTo("up"); },
|
1426
|
+
"Down": function(editor) { editor.completer.goTo("down"); },
|
1427
|
+
"Ctrl-Up|Ctrl-Home": function(editor) { editor.completer.goTo("start"); },
|
1428
|
+
"Ctrl-Down|Ctrl-End": function(editor) { editor.completer.goTo("end"); },
|
1429
|
+
|
1430
|
+
"Esc": function(editor) { editor.completer.detach(); },
|
1431
|
+
"Space": function(editor) { editor.completer.detach(); editor.insert(" ");},
|
1432
|
+
"Return": function(editor) { return editor.completer.insertMatch(); },
|
1433
|
+
"Shift-Return": function(editor) { editor.completer.insertMatch(true); },
|
1434
|
+
"Tab": function(editor) {
|
1435
|
+
var result = editor.completer.insertMatch();
|
1436
|
+
if (!result && !editor.tabstopManager)
|
1437
|
+
editor.completer.goTo("down");
|
1438
|
+
else
|
1439
|
+
return result;
|
1440
|
+
},
|
1441
|
+
|
1442
|
+
"PageUp": function(editor) { editor.completer.popup.gotoPageUp(); },
|
1443
|
+
"PageDown": function(editor) { editor.completer.popup.gotoPageDown(); }
|
1444
|
+
};
|
1445
|
+
|
1446
|
+
this.gatherCompletions = function(editor, callback) {
|
1447
|
+
var session = editor.getSession();
|
1448
|
+
var pos = editor.getCursorPosition();
|
1449
|
+
|
1450
|
+
var line = session.getLine(pos.row);
|
1451
|
+
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
1452
|
+
|
1453
|
+
this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
|
1454
|
+
this.base.$insertRight = true;
|
1455
|
+
|
1456
|
+
var matches = [];
|
1457
|
+
var total = editor.completers.length;
|
1458
|
+
editor.completers.forEach(function(completer, i) {
|
1459
|
+
completer.getCompletions(editor, session, pos, prefix, function(err, results) {
|
1460
|
+
if (!err)
|
1461
|
+
matches = matches.concat(results);
|
1462
|
+
var pos = editor.getCursorPosition();
|
1463
|
+
var line = session.getLine(pos.row);
|
1464
|
+
callback(null, {
|
1465
|
+
prefix: util.retrievePrecedingIdentifier(line, pos.column, results[0] && results[0].identifierRegex),
|
1466
|
+
matches: matches,
|
1467
|
+
finished: (--total === 0)
|
1468
|
+
});
|
1469
|
+
});
|
1470
|
+
});
|
1471
|
+
return true;
|
1472
|
+
};
|
1473
|
+
|
1474
|
+
this.showPopup = function(editor) {
|
1475
|
+
if (this.editor)
|
1476
|
+
this.detach();
|
1477
|
+
|
1478
|
+
this.activated = true;
|
1479
|
+
|
1480
|
+
this.editor = editor;
|
1481
|
+
if (editor.completer != this) {
|
1482
|
+
if (editor.completer)
|
1483
|
+
editor.completer.detach();
|
1484
|
+
editor.completer = this;
|
1485
|
+
}
|
1486
|
+
|
1487
|
+
editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
1488
|
+
editor.on("changeSelection", this.changeListener);
|
1489
|
+
editor.on("blur", this.blurListener);
|
1490
|
+
editor.on("mousedown", this.mousedownListener);
|
1491
|
+
editor.on("mousewheel", this.mousewheelListener);
|
1492
|
+
|
1493
|
+
this.updateCompletions();
|
1494
|
+
};
|
1495
|
+
|
1496
|
+
this.updateCompletions = function(keepPopupPosition) {
|
1497
|
+
if (keepPopupPosition && this.base && this.completions) {
|
1498
|
+
var pos = this.editor.getCursorPosition();
|
1499
|
+
var prefix = this.editor.session.getTextRange({start: this.base, end: pos});
|
1500
|
+
if (prefix == this.completions.filterText)
|
1501
|
+
return;
|
1502
|
+
this.completions.setFilter(prefix);
|
1503
|
+
if (!this.completions.filtered.length)
|
1504
|
+
return this.detach();
|
1505
|
+
if (this.completions.filtered.length == 1
|
1506
|
+
&& this.completions.filtered[0].value == prefix
|
1507
|
+
&& !this.completions.filtered[0].snippet)
|
1508
|
+
return this.detach();
|
1509
|
+
this.openPopup(this.editor, prefix, keepPopupPosition);
|
1510
|
+
return;
|
1511
|
+
}
|
1512
|
+
var _id = this.gatherCompletionsId;
|
1513
|
+
this.gatherCompletions(this.editor, function(err, results) {
|
1514
|
+
var detachIfFinished = function() {
|
1515
|
+
if (!results.finished) return;
|
1516
|
+
return this.detach();
|
1517
|
+
}.bind(this);
|
1518
|
+
|
1519
|
+
var prefix = results.prefix;
|
1520
|
+
var matches = results && results.matches;
|
1521
|
+
|
1522
|
+
if (!matches || !matches.length)
|
1523
|
+
return detachIfFinished();
|
1524
|
+
if (prefix.indexOf(results.prefix) !== 0 || _id != this.gatherCompletionsId)
|
1525
|
+
return;
|
1526
|
+
|
1527
|
+
this.completions = new FilteredList(matches);
|
1528
|
+
|
1529
|
+
if (this.exactMatch)
|
1530
|
+
this.completions.exactMatch = true;
|
1531
|
+
|
1532
|
+
this.completions.setFilter(prefix);
|
1533
|
+
var filtered = this.completions.filtered;
|
1534
|
+
if (!filtered.length)
|
1535
|
+
return detachIfFinished();
|
1536
|
+
if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet)
|
1537
|
+
return detachIfFinished();
|
1538
|
+
if (this.autoInsert && filtered.length == 1 && results.finished)
|
1539
|
+
return this.insertMatch(filtered[0]);
|
1540
|
+
|
1541
|
+
this.openPopup(this.editor, prefix, keepPopupPosition);
|
1542
|
+
}.bind(this));
|
1543
|
+
};
|
1544
|
+
|
1545
|
+
this.cancelContextMenu = function() {
|
1546
|
+
this.editor.$mouseHandler.cancelContextMenu();
|
1547
|
+
};
|
1548
|
+
|
1549
|
+
this.updateDocTooltip = function() {
|
1550
|
+
var popup = this.popup;
|
1551
|
+
var all = popup.data;
|
1552
|
+
var selected = all && (all[popup.getHoveredRow()] || all[popup.getRow()]);
|
1553
|
+
var doc = null;
|
1554
|
+
if (!selected || !this.editor || !this.popup.isOpen)
|
1555
|
+
return this.hideDocTooltip();
|
1556
|
+
this.editor.completers.some(function(completer) {
|
1557
|
+
if (completer.getDocTooltip)
|
1558
|
+
doc = completer.getDocTooltip(selected);
|
1559
|
+
return doc;
|
1560
|
+
});
|
1561
|
+
if (!doc)
|
1562
|
+
doc = selected;
|
1563
|
+
|
1564
|
+
if (typeof doc == "string")
|
1565
|
+
doc = {docText: doc}
|
1566
|
+
if (!doc || !(doc.docHTML || doc.docText))
|
1567
|
+
return this.hideDocTooltip();
|
1568
|
+
this.showDocTooltip(doc);
|
1569
|
+
};
|
1570
|
+
|
1571
|
+
this.showDocTooltip = function(item) {
|
1572
|
+
if (!this.tooltipNode) {
|
1573
|
+
this.tooltipNode = dom.createElement("div");
|
1574
|
+
this.tooltipNode.className = "ace_tooltip ace_doc-tooltip";
|
1575
|
+
this.tooltipNode.style.margin = 0;
|
1576
|
+
this.tooltipNode.style.pointerEvents = "auto";
|
1577
|
+
this.tooltipNode.tabIndex = -1;
|
1578
|
+
this.tooltipNode.onblur = this.blurListener.bind(this);
|
1579
|
+
}
|
1580
|
+
|
1581
|
+
var tooltipNode = this.tooltipNode;
|
1582
|
+
if (item.docHTML) {
|
1583
|
+
tooltipNode.innerHTML = item.docHTML;
|
1584
|
+
} else if (item.docText) {
|
1585
|
+
tooltipNode.textContent = item.docText;
|
1586
|
+
}
|
1587
|
+
|
1588
|
+
if (!tooltipNode.parentNode)
|
1589
|
+
document.body.appendChild(tooltipNode);
|
1590
|
+
var popup = this.popup;
|
1591
|
+
var rect = popup.container.getBoundingClientRect();
|
1592
|
+
tooltipNode.style.top = popup.container.style.top;
|
1593
|
+
tooltipNode.style.bottom = popup.container.style.bottom;
|
1594
|
+
|
1595
|
+
if (window.innerWidth - rect.right < 320) {
|
1596
|
+
tooltipNode.style.right = window.innerWidth - rect.left + "px";
|
1597
|
+
tooltipNode.style.left = "";
|
1598
|
+
} else {
|
1599
|
+
tooltipNode.style.left = (rect.right + 1) + "px";
|
1600
|
+
tooltipNode.style.right = "";
|
1601
|
+
}
|
1602
|
+
tooltipNode.style.display = "block";
|
1603
|
+
};
|
1604
|
+
|
1605
|
+
this.hideDocTooltip = function() {
|
1606
|
+
this.tooltipTimer.cancel();
|
1607
|
+
if (!this.tooltipNode) return;
|
1608
|
+
var el = this.tooltipNode;
|
1609
|
+
if (!this.editor.isFocused() && document.activeElement == el)
|
1610
|
+
this.editor.focus();
|
1611
|
+
this.tooltipNode = null;
|
1612
|
+
if (el.parentNode)
|
1613
|
+
el.parentNode.removeChild(el);
|
1614
|
+
};
|
1615
|
+
|
1616
|
+
}).call(Autocomplete.prototype);
|
1617
|
+
|
1618
|
+
Autocomplete.startCommand = {
|
1619
|
+
name: "startAutocomplete",
|
1620
|
+
exec: function(editor) {
|
1621
|
+
if (!editor.completer)
|
1622
|
+
editor.completer = new Autocomplete();
|
1623
|
+
editor.completer.autoInsert =
|
1624
|
+
editor.completer.autoSelect = true;
|
1625
|
+
editor.completer.showPopup(editor);
|
1626
|
+
editor.completer.cancelContextMenu();
|
1627
|
+
},
|
1628
|
+
bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
|
1629
|
+
};
|
1630
|
+
|
1631
|
+
var FilteredList = function(array, filterText, mutateData) {
|
1632
|
+
this.all = array;
|
1633
|
+
this.filtered = array;
|
1634
|
+
this.filterText = filterText || "";
|
1635
|
+
this.exactMatch = false;
|
1636
|
+
};
|
1637
|
+
(function(){
|
1638
|
+
this.setFilter = function(str) {
|
1639
|
+
if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0)
|
1640
|
+
var matches = this.filtered;
|
1641
|
+
else
|
1642
|
+
var matches = this.all;
|
1643
|
+
|
1644
|
+
this.filterText = str;
|
1645
|
+
matches = this.filterCompletions(matches, this.filterText);
|
1646
|
+
matches = matches.sort(function(a, b) {
|
1647
|
+
return b.exactMatch - a.exactMatch || b.score - a.score;
|
1648
|
+
});
|
1649
|
+
var prev = null;
|
1650
|
+
matches = matches.filter(function(item){
|
1651
|
+
var caption = item.snippet || item.caption || item.value;
|
1652
|
+
if (caption === prev) return false;
|
1653
|
+
prev = caption;
|
1654
|
+
return true;
|
1655
|
+
});
|
1656
|
+
|
1657
|
+
this.filtered = matches;
|
1658
|
+
};
|
1659
|
+
this.filterCompletions = function(items, needle) {
|
1660
|
+
var results = [];
|
1661
|
+
var upper = needle.toUpperCase();
|
1662
|
+
var lower = needle.toLowerCase();
|
1663
|
+
loop: for (var i = 0, item; item = items[i]; i++) {
|
1664
|
+
var caption = item.value || item.caption || item.snippet;
|
1665
|
+
if (!caption) continue;
|
1666
|
+
var lastIndex = -1;
|
1667
|
+
var matchMask = 0;
|
1668
|
+
var penalty = 0;
|
1669
|
+
var index, distance;
|
1670
|
+
|
1671
|
+
if (this.exactMatch) {
|
1672
|
+
if (needle !== caption.substr(0, needle.length))
|
1673
|
+
continue loop;
|
1674
|
+
}else{
|
1675
|
+
for (var j = 0; j < needle.length; j++) {
|
1676
|
+
var i1 = caption.indexOf(lower[j], lastIndex + 1);
|
1677
|
+
var i2 = caption.indexOf(upper[j], lastIndex + 1);
|
1678
|
+
index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
|
1679
|
+
if (index < 0)
|
1680
|
+
continue loop;
|
1681
|
+
distance = index - lastIndex - 1;
|
1682
|
+
if (distance > 0) {
|
1683
|
+
if (lastIndex === -1)
|
1684
|
+
penalty += 10;
|
1685
|
+
penalty += distance;
|
1686
|
+
}
|
1687
|
+
matchMask = matchMask | (1 << index);
|
1688
|
+
lastIndex = index;
|
1689
|
+
}
|
1690
|
+
}
|
1691
|
+
item.matchMask = matchMask;
|
1692
|
+
item.exactMatch = penalty ? 0 : 1;
|
1693
|
+
item.score = (item.score || 0) - penalty;
|
1694
|
+
results.push(item);
|
1695
|
+
}
|
1696
|
+
return results;
|
1697
|
+
};
|
1698
|
+
}).call(FilteredList.prototype);
|
1699
|
+
|
1700
|
+
exports.Autocomplete = Autocomplete;
|
1701
|
+
exports.FilteredList = FilteredList;
|
1702
|
+
|
1703
|
+
});
|
1704
|
+
|
1705
|
+
ace.define("ace/autocomplete/text_completer",["require","exports","module","ace/range"], function(require, exports, module) {
|
1706
|
+
var Range = require("../range").Range;
|
1707
|
+
|
1708
|
+
var splitRegex = /[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/;
|
1709
|
+
|
1710
|
+
function getWordIndex(doc, pos) {
|
1711
|
+
var textBefore = doc.getTextRange(Range.fromPoints({row: 0, column:0}, pos));
|
1712
|
+
return textBefore.split(splitRegex).length - 1;
|
1713
|
+
}
|
1714
|
+
function wordDistance(doc, pos) {
|
1715
|
+
var prefixPos = getWordIndex(doc, pos);
|
1716
|
+
var words = doc.getValue().split(splitRegex);
|
1717
|
+
var wordScores = Object.create(null);
|
1718
|
+
|
1719
|
+
var currentWord = words[prefixPos];
|
1720
|
+
|
1721
|
+
words.forEach(function(word, idx) {
|
1722
|
+
if (!word || word === currentWord) return;
|
1723
|
+
|
1724
|
+
var distance = Math.abs(prefixPos - idx);
|
1725
|
+
var score = words.length - distance;
|
1726
|
+
if (wordScores[word]) {
|
1727
|
+
wordScores[word] = Math.max(score, wordScores[word]);
|
1728
|
+
} else {
|
1729
|
+
wordScores[word] = score;
|
1730
|
+
}
|
1731
|
+
});
|
1732
|
+
return wordScores;
|
1733
|
+
}
|
1734
|
+
|
1735
|
+
exports.getCompletions = function(editor, session, pos, prefix, callback) {
|
1736
|
+
var wordScore = wordDistance(session, pos, prefix);
|
1737
|
+
var wordList = Object.keys(wordScore);
|
1738
|
+
callback(null, wordList.map(function(word) {
|
1739
|
+
return {
|
1740
|
+
caption: word,
|
1741
|
+
value: word,
|
1742
|
+
score: wordScore[word],
|
1743
|
+
meta: "local"
|
1744
|
+
};
|
1745
|
+
}));
|
1746
|
+
};
|
1747
|
+
});
|
1748
|
+
|
1749
|
+
ace.define("ace/ext/language_tools",["require","exports","module","ace/snippets","ace/autocomplete","ace/config","ace/lib/lang","ace/autocomplete/util","ace/autocomplete/text_completer","ace/editor","ace/config"], function(require, exports, module) {
|
1750
|
+
"use strict";
|
1751
|
+
|
1752
|
+
var snippetManager = require("../snippets").snippetManager;
|
1753
|
+
var Autocomplete = require("../autocomplete").Autocomplete;
|
1754
|
+
var config = require("../config");
|
1755
|
+
var lang = require("../lib/lang");
|
1756
|
+
var util = require("../autocomplete/util");
|
1757
|
+
|
1758
|
+
var textCompleter = require("../autocomplete/text_completer");
|
1759
|
+
var keyWordCompleter = {
|
1760
|
+
getCompletions: function(editor, session, pos, prefix, callback) {
|
1761
|
+
if (session.$mode.completer) {
|
1762
|
+
return session.$mode.completer.getCompletions(editor, session, pos, prefix, callback);
|
1763
|
+
}
|
1764
|
+
var state = editor.session.getState(pos.row);
|
1765
|
+
var completions = session.$mode.getCompletions(state, session, pos, prefix);
|
1766
|
+
callback(null, completions);
|
1767
|
+
}
|
1768
|
+
};
|
1769
|
+
|
1770
|
+
var snippetCompleter = {
|
1771
|
+
getCompletions: function(editor, session, pos, prefix, callback) {
|
1772
|
+
var snippetMap = snippetManager.snippetMap;
|
1773
|
+
var completions = [];
|
1774
|
+
snippetManager.getActiveScopes(editor).forEach(function(scope) {
|
1775
|
+
var snippets = snippetMap[scope] || [];
|
1776
|
+
for (var i = snippets.length; i--;) {
|
1777
|
+
var s = snippets[i];
|
1778
|
+
var caption = s.name || s.tabTrigger;
|
1779
|
+
if (!caption)
|
1780
|
+
continue;
|
1781
|
+
completions.push({
|
1782
|
+
caption: caption,
|
1783
|
+
snippet: s.content,
|
1784
|
+
meta: s.tabTrigger && !s.name ? s.tabTrigger + "\u21E5 " : "snippet",
|
1785
|
+
type: "snippet"
|
1786
|
+
});
|
1787
|
+
}
|
1788
|
+
}, this);
|
1789
|
+
callback(null, completions);
|
1790
|
+
},
|
1791
|
+
getDocTooltip: function(item) {
|
1792
|
+
if (item.type == "snippet" && !item.docHTML) {
|
1793
|
+
item.docHTML = [
|
1794
|
+
"<b>", lang.escapeHTML(item.caption), "</b>", "<hr></hr>",
|
1795
|
+
lang.escapeHTML(item.snippet)
|
1796
|
+
].join("");
|
1797
|
+
}
|
1798
|
+
}
|
1799
|
+
};
|
1800
|
+
|
1801
|
+
var completers = [snippetCompleter, textCompleter, keyWordCompleter];
|
1802
|
+
exports.setCompleters = function(val) {
|
1803
|
+
completers = val || [];
|
1804
|
+
};
|
1805
|
+
exports.addCompleter = function(completer) {
|
1806
|
+
completers.push(completer);
|
1807
|
+
};
|
1808
|
+
exports.textCompleter = textCompleter;
|
1809
|
+
exports.keyWordCompleter = keyWordCompleter;
|
1810
|
+
exports.snippetCompleter = snippetCompleter;
|
1811
|
+
|
1812
|
+
var expandSnippet = {
|
1813
|
+
name: "expandSnippet",
|
1814
|
+
exec: function(editor) {
|
1815
|
+
return snippetManager.expandWithTab(editor);
|
1816
|
+
},
|
1817
|
+
bindKey: "Tab"
|
1818
|
+
};
|
1819
|
+
|
1820
|
+
var onChangeMode = function(e, editor) {
|
1821
|
+
loadSnippetsForMode(editor.session.$mode);
|
1822
|
+
};
|
1823
|
+
|
1824
|
+
var loadSnippetsForMode = function(mode) {
|
1825
|
+
var id = mode.$id;
|
1826
|
+
if (!snippetManager.files)
|
1827
|
+
snippetManager.files = {};
|
1828
|
+
loadSnippetFile(id);
|
1829
|
+
if (mode.modes)
|
1830
|
+
mode.modes.forEach(loadSnippetsForMode);
|
1831
|
+
};
|
1832
|
+
|
1833
|
+
var loadSnippetFile = function(id) {
|
1834
|
+
if (!id || snippetManager.files[id])
|
1835
|
+
return;
|
1836
|
+
var snippetFilePath = id.replace("mode", "snippets");
|
1837
|
+
snippetManager.files[id] = {};
|
1838
|
+
config.loadModule(snippetFilePath, function(m) {
|
1839
|
+
if (m) {
|
1840
|
+
snippetManager.files[id] = m;
|
1841
|
+
if (!m.snippets && m.snippetText)
|
1842
|
+
m.snippets = snippetManager.parseSnippetFile(m.snippetText);
|
1843
|
+
snippetManager.register(m.snippets || [], m.scope);
|
1844
|
+
if (m.includeScopes) {
|
1845
|
+
snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
|
1846
|
+
m.includeScopes.forEach(function(x) {
|
1847
|
+
loadSnippetFile("ace/mode/" + x);
|
1848
|
+
});
|
1849
|
+
}
|
1850
|
+
}
|
1851
|
+
});
|
1852
|
+
};
|
1853
|
+
|
1854
|
+
function getCompletionPrefix(editor) {
|
1855
|
+
var pos = editor.getCursorPosition();
|
1856
|
+
var line = editor.session.getLine(pos.row);
|
1857
|
+
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
1858
|
+
editor.completers.forEach(function(completer) {
|
1859
|
+
if (completer.identifierRegexps) {
|
1860
|
+
completer.identifierRegexps.forEach(function(identifierRegex) {
|
1861
|
+
if (!prefix && identifierRegex)
|
1862
|
+
prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
|
1863
|
+
});
|
1864
|
+
}
|
1865
|
+
});
|
1866
|
+
return prefix;
|
1867
|
+
}
|
1868
|
+
|
1869
|
+
var doLiveAutocomplete = function(e) {
|
1870
|
+
var editor = e.editor;
|
1871
|
+
var text = e.args || "";
|
1872
|
+
var hasCompleter = editor.completer && editor.completer.activated;
|
1873
|
+
if (e.command.name === "backspace") {
|
1874
|
+
if (hasCompleter && !getCompletionPrefix(editor))
|
1875
|
+
editor.completer.detach();
|
1876
|
+
}
|
1877
|
+
else if (e.command.name === "insertstring") {
|
1878
|
+
var prefix = getCompletionPrefix(editor);
|
1879
|
+
if (prefix && !hasCompleter) {
|
1880
|
+
if (!editor.completer) {
|
1881
|
+
editor.completer = new Autocomplete();
|
1882
|
+
}
|
1883
|
+
editor.completer.autoSelect = false;
|
1884
|
+
editor.completer.autoInsert = false;
|
1885
|
+
editor.completer.showPopup(editor);
|
1886
|
+
}
|
1887
|
+
}
|
1888
|
+
};
|
1889
|
+
|
1890
|
+
var Editor = require("../editor").Editor;
|
1891
|
+
require("../config").defineOptions(Editor.prototype, "editor", {
|
1892
|
+
enableBasicAutocompletion: {
|
1893
|
+
set: function(val) {
|
1894
|
+
if (val) {
|
1895
|
+
if (!this.completers)
|
1896
|
+
this.completers = Array.isArray(val)? val: completers;
|
1897
|
+
this.commands.addCommand(Autocomplete.startCommand);
|
1898
|
+
} else {
|
1899
|
+
this.commands.removeCommand(Autocomplete.startCommand);
|
1900
|
+
}
|
1901
|
+
},
|
1902
|
+
value: false
|
1903
|
+
},
|
1904
|
+
enableLiveAutocompletion: {
|
1905
|
+
set: function(val) {
|
1906
|
+
if (val) {
|
1907
|
+
if (!this.completers)
|
1908
|
+
this.completers = Array.isArray(val)? val: completers;
|
1909
|
+
this.commands.on('afterExec', doLiveAutocomplete);
|
1910
|
+
} else {
|
1911
|
+
this.commands.removeListener('afterExec', doLiveAutocomplete);
|
1912
|
+
}
|
1913
|
+
},
|
1914
|
+
value: false
|
1915
|
+
},
|
1916
|
+
enableSnippets: {
|
1917
|
+
set: function(val) {
|
1918
|
+
if (val) {
|
1919
|
+
this.commands.addCommand(expandSnippet);
|
1920
|
+
this.on("changeMode", onChangeMode);
|
1921
|
+
onChangeMode(null, this);
|
1922
|
+
} else {
|
1923
|
+
this.commands.removeCommand(expandSnippet);
|
1924
|
+
this.off("changeMode", onChangeMode);
|
1925
|
+
}
|
1926
|
+
},
|
1927
|
+
value: false
|
1928
|
+
}
|
1929
|
+
});
|
1930
|
+
});
|
1931
|
+
(function() {
|
1932
|
+
ace.require(["ace/ext/language_tools"], function() {});
|
1933
|
+
})();
|
1934
|
+
|