ace-rails-ap 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1 -1
  3. data/lib/ace/rails/version.rb +1 -1
  4. data/vendor/assets/javascripts/ace/ace.js +6911 -5290
  5. data/vendor/assets/javascripts/ace/ext-chromevox.js +537 -0
  6. data/vendor/assets/javascripts/ace/ext-elastic_tabstops_lite.js +301 -0
  7. data/vendor/assets/javascripts/ace/ext-emmet.js +1109 -0
  8. data/vendor/assets/javascripts/ace/ext-keybinding_menu.js +207 -0
  9. data/vendor/assets/javascripts/ace/ext-language_tools.js +1665 -0
  10. data/vendor/assets/javascripts/ace/ext-modelist.js +168 -0
  11. data/vendor/assets/javascripts/ace/ext-old_ie.js +500 -0
  12. data/vendor/assets/javascripts/ace/ext-options.js +252 -0
  13. data/vendor/assets/javascripts/ace/ext-searchbox.js +421 -0
  14. data/vendor/assets/javascripts/ace/ext-settings_menu.js +632 -0
  15. data/vendor/assets/javascripts/ace/ext-spellcheck.js +68 -0
  16. data/vendor/assets/javascripts/ace/ext-split.js +271 -0
  17. data/vendor/assets/javascripts/ace/ext-static_highlight.js +178 -0
  18. data/vendor/assets/javascripts/ace/ext-statusbar.js +47 -0
  19. data/vendor/assets/javascripts/ace/ext-textarea.js +478 -0
  20. data/vendor/assets/javascripts/ace/ext-themelist.js +86 -0
  21. data/vendor/assets/javascripts/ace/ext-whitespace.js +206 -0
  22. data/vendor/assets/javascripts/ace/keybinding-emacs.js +822 -131
  23. data/vendor/assets/javascripts/ace/keybinding-vim.js +382 -258
  24. data/vendor/assets/javascripts/ace/mode-abap.js +261 -0
  25. data/vendor/assets/javascripts/ace/mode-actionscript.js +257 -0
  26. data/vendor/assets/javascripts/ace/mode-ada.js +118 -0
  27. data/vendor/assets/javascripts/ace/mode-asciidoc.js +373 -0
  28. data/vendor/assets/javascripts/ace/mode-assembly_x86.js +217 -0
  29. data/vendor/assets/javascripts/ace/mode-autohotkey.js +225 -0
  30. data/vendor/assets/javascripts/ace/mode-batchfile.js +213 -0
  31. data/vendor/assets/javascripts/ace/mode-c9search.js +144 -124
  32. data/vendor/assets/javascripts/ace/mode-c_cpp.js +296 -254
  33. data/vendor/assets/javascripts/ace/mode-clojure.js +113 -177
  34. data/vendor/assets/javascripts/ace/mode-cobol.js +125 -0
  35. data/vendor/assets/javascripts/ace/mode-coffee.js +152 -235
  36. data/vendor/assets/javascripts/ace/mode-coldfusion.js +823 -835
  37. data/vendor/assets/javascripts/ace/mode-csharp.js +325 -187
  38. data/vendor/assets/javascripts/ace/mode-css.js +583 -297
  39. data/vendor/assets/javascripts/ace/mode-curly.js +2423 -0
  40. data/vendor/assets/javascripts/ace/mode-d.js +492 -0
  41. data/vendor/assets/javascripts/ace/mode-dart.js +993 -0
  42. data/vendor/assets/javascripts/ace/mode-diff.js +124 -204
  43. data/vendor/assets/javascripts/ace/mode-django.js +2448 -0
  44. data/vendor/assets/javascripts/ace/mode-dot.js +361 -0
  45. data/vendor/assets/javascripts/ace/mode-ejs.js +2817 -0
  46. data/vendor/assets/javascripts/ace/mode-erlang.js +987 -0
  47. data/vendor/assets/javascripts/ace/mode-forth.js +280 -0
  48. data/vendor/assets/javascripts/ace/mode-ftl.js +1061 -0
  49. data/vendor/assets/javascripts/ace/mode-glsl.js +313 -275
  50. data/vendor/assets/javascripts/ace/mode-golang.js +268 -275
  51. data/vendor/assets/javascripts/ace/mode-groovy.js +347 -492
  52. data/vendor/assets/javascripts/ace/mode-haml.js +498 -0
  53. data/vendor/assets/javascripts/ace/mode-handlebars.js +2433 -0
  54. data/vendor/assets/javascripts/ace/mode-haskell.js +362 -0
  55. data/vendor/assets/javascripts/ace/mode-haxe.js +226 -202
  56. data/vendor/assets/javascripts/ace/mode-html.js +1099 -802
  57. data/vendor/assets/javascripts/ace/mode-html_completions.js +309 -0
  58. data/vendor/assets/javascripts/ace/mode-html_ruby.js +2822 -0
  59. data/vendor/assets/javascripts/ace/mode-ini.js +185 -0
  60. data/vendor/assets/javascripts/ace/mode-jack.js +653 -0
  61. data/vendor/assets/javascripts/ace/mode-jade.js +2081 -0
  62. data/vendor/assets/javascripts/ace/mode-java.js +339 -488
  63. data/vendor/assets/javascripts/ace/mode-javascript.js +342 -478
  64. data/vendor/assets/javascripts/ace/mode-json.js +215 -178
  65. data/vendor/assets/javascripts/ace/mode-jsoniq.js +2761 -0
  66. data/vendor/assets/javascripts/ace/mode-jsp.js +1553 -0
  67. data/vendor/assets/javascripts/ace/mode-jsx.js +325 -289
  68. data/vendor/assets/javascripts/ace/mode-julia.js +286 -0
  69. data/vendor/assets/javascripts/ace/mode-latex.js +141 -46
  70. data/vendor/assets/javascripts/ace/mode-less.js +493 -151
  71. data/vendor/assets/javascripts/ace/mode-liquid.js +594 -656
  72. data/vendor/assets/javascripts/ace/mode-lisp.js +137 -0
  73. data/vendor/assets/javascripts/ace/mode-livescript.js +288 -0
  74. data/vendor/assets/javascripts/ace/mode-logiql.js +669 -0
  75. data/vendor/assets/javascripts/ace/mode-lsl.js +890 -0
  76. data/vendor/assets/javascripts/ace/mode-lua.js +274 -368
  77. data/vendor/assets/javascripts/ace/mode-luapage.js +1331 -1107
  78. data/vendor/assets/javascripts/ace/mode-lucene.js +64 -0
  79. data/vendor/assets/javascripts/ace/mode-makefile.js +332 -0
  80. data/vendor/assets/javascripts/ace/mode-markdown.js +1303 -948
  81. data/vendor/assets/javascripts/ace/mode-matlab.js +230 -0
  82. data/vendor/assets/javascripts/ace/mode-mushcode.js +705 -0
  83. data/vendor/assets/javascripts/ace/mode-mushcode_high_rules.js +569 -0
  84. data/vendor/assets/javascripts/ace/mode-mysql.js +185 -0
  85. data/vendor/assets/javascripts/ace/mode-nix.js +935 -0
  86. data/vendor/assets/javascripts/ace/mode-objectivec.js +699 -0
  87. data/vendor/assets/javascripts/ace/mode-ocaml.js +44 -63
  88. data/vendor/assets/javascripts/ace/mode-pascal.js +233 -0
  89. data/vendor/assets/javascripts/ace/mode-perl.js +116 -189
  90. data/vendor/assets/javascripts/ace/mode-pgsql.js +886 -500
  91. data/vendor/assets/javascripts/ace/mode-php.js +1158 -380
  92. data/vendor/assets/javascripts/ace/mode-plain_text.js +56 -0
  93. data/vendor/assets/javascripts/ace/mode-powershell.js +222 -167
  94. data/vendor/assets/javascripts/ace/mode-prolog.js +354 -0
  95. data/vendor/assets/javascripts/ace/mode-properties.js +100 -0
  96. data/vendor/assets/javascripts/ace/mode-protobuf.js +885 -0
  97. data/vendor/assets/javascripts/ace/mode-python.js +99 -201
  98. data/vendor/assets/javascripts/ace/mode-r.js +337 -0
  99. data/vendor/assets/javascripts/ace/mode-rdoc.js +210 -0
  100. data/vendor/assets/javascripts/ace/mode-rhtml.js +2663 -0
  101. data/vendor/assets/javascripts/ace/mode-ruby.js +262 -136
  102. data/vendor/assets/javascripts/ace/mode-rust.js +245 -0
  103. data/vendor/assets/javascripts/ace/mode-sass.js +443 -0
  104. data/vendor/assets/javascripts/ace/mode-scad.js +225 -240
  105. data/vendor/assets/javascripts/ace/mode-scala.js +340 -494
  106. data/vendor/assets/javascripts/ace/mode-scheme.js +143 -0
  107. data/vendor/assets/javascripts/ace/mode-scss.js +499 -157
  108. data/vendor/assets/javascripts/ace/mode-sh.js +180 -110
  109. data/vendor/assets/javascripts/ace/mode-sjs.js +1154 -0
  110. data/vendor/assets/javascripts/ace/mode-snippets.js +198 -0
  111. data/vendor/assets/javascripts/ace/mode-soy_template.js +2707 -0
  112. data/vendor/assets/javascripts/ace/mode-space.js +160 -0
  113. data/vendor/assets/javascripts/ace/mode-sql.js +48 -69
  114. data/vendor/assets/javascripts/ace/mode-stylus.js +447 -0
  115. data/vendor/assets/javascripts/ace/mode-svg.js +552 -605
  116. data/vendor/assets/javascripts/ace/mode-tcl.js +139 -98
  117. data/vendor/assets/javascripts/ace/mode-tex.js +187 -0
  118. data/vendor/assets/javascripts/ace/mode-textile.js +29 -40
  119. data/vendor/assets/javascripts/ace/mode-tmsnippet.js +200 -0
  120. data/vendor/assets/javascripts/ace/mode-toml.js +177 -0
  121. data/vendor/assets/javascripts/ace/mode-twig.js +2228 -0
  122. data/vendor/assets/javascripts/ace/mode-typescript.js +1018 -0
  123. data/vendor/assets/javascripts/ace/mode-vbscript.js +250 -0
  124. data/vendor/assets/javascripts/ace/mode-velocity.js +1621 -0
  125. data/vendor/assets/javascripts/ace/mode-verilog.js +127 -0
  126. data/vendor/assets/javascripts/ace/mode-vhdl.js +139 -0
  127. data/vendor/assets/javascripts/ace/mode-xml.js +350 -242
  128. data/vendor/assets/javascripts/ace/mode-xquery.js +2490 -300
  129. data/vendor/assets/javascripts/ace/mode-yaml.js +146 -45
  130. data/vendor/assets/javascripts/ace/theme-ambiance.js +202 -0
  131. data/vendor/assets/javascripts/ace/theme-chaos.js +179 -0
  132. data/vendor/assets/javascripts/ace/theme-chrome.js +97 -153
  133. data/vendor/assets/javascripts/ace/theme-clouds.js +78 -119
  134. data/vendor/assets/javascripts/ace/theme-clouds_midnight.js +79 -120
  135. data/vendor/assets/javascripts/ace/theme-cobalt.js +89 -140
  136. data/vendor/assets/javascripts/ace/theme-crimson_editor.js +93 -145
  137. data/vendor/assets/javascripts/ace/theme-dawn.js +84 -143
  138. data/vendor/assets/javascripts/ace/theme-dreamweaver.js +99 -162
  139. data/vendor/assets/javascripts/ace/theme-eclipse.js +78 -111
  140. data/vendor/assets/javascripts/ace/theme-github.js +70 -121
  141. data/vendor/assets/javascripts/ace/theme-idle_fingers.js +75 -134
  142. data/vendor/assets/javascripts/ace/theme-kr.js +135 -0
  143. data/vendor/assets/javascripts/ace/theme-merbivore.js +80 -143
  144. data/vendor/assets/javascripts/ace/theme-merbivore_soft.js +81 -149
  145. data/vendor/assets/javascripts/ace/theme-mono_industrial.js +87 -146
  146. data/vendor/assets/javascripts/ace/theme-monokai.js +88 -146
  147. data/vendor/assets/javascripts/ace/theme-pastel_on_dark.js +82 -142
  148. data/vendor/assets/javascripts/ace/theme-solarized_dark.js +83 -144
  149. data/vendor/assets/javascripts/ace/theme-solarized_light.js +76 -133
  150. data/vendor/assets/javascripts/ace/theme-terminal.js +145 -0
  151. data/vendor/assets/javascripts/ace/theme-textmate.js +101 -158
  152. data/vendor/assets/javascripts/ace/theme-tomorrow.js +89 -163
  153. data/vendor/assets/javascripts/ace/theme-tomorrow_night.js +89 -163
  154. data/vendor/assets/javascripts/ace/theme-tomorrow_night_blue.js +89 -165
  155. data/vendor/assets/javascripts/ace/theme-tomorrow_night_bright.js +101 -162
  156. data/vendor/assets/javascripts/ace/theme-tomorrow_night_eighties.js +90 -160
  157. data/vendor/assets/javascripts/ace/theme-twilight.js +87 -158
  158. data/vendor/assets/javascripts/ace/theme-vibrant_ink.js +75 -140
  159. data/vendor/assets/javascripts/ace/theme-xcode.js +120 -0
  160. data/vendor/assets/javascripts/ace/worker-coffee.js +3049 -2665
  161. data/vendor/assets/javascripts/ace/worker-css.js +1779 -4376
  162. data/vendor/assets/javascripts/ace/worker-javascript.js +8701 -9008
  163. data/vendor/assets/javascripts/ace/worker-json.js +709 -1340
  164. data/vendor/assets/javascripts/ace/worker-lua.js +3525 -0
  165. data/vendor/assets/javascripts/ace/worker-php.js +6893 -0
  166. data/vendor/assets/javascripts/ace/worker-xquery.js +19924 -64507
  167. metadata +100 -17
@@ -0,0 +1,207 @@
1
+ /* ***** BEGIN LICENSE BLOCK *****
2
+ * Distributed under the BSD license:
3
+ *
4
+ * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
5
+ * All rights reserved.
6
+ *
7
+ * Contributed to Ajax.org under the BSD license.
8
+ *
9
+ * Redistribution and use in source and binary forms, with or without
10
+ * modification, are permitted provided that the following conditions are met:
11
+ * * Redistributions of source code must retain the above copyright
12
+ * notice, this list of conditions and the following disclaimer.
13
+ * * Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ * * Neither the name of Ajax.org B.V. nor the
17
+ * names of its contributors may be used to endorse or promote products
18
+ * derived from this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
24
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ *
31
+ * ***** END LICENSE BLOCK ***** */
32
+
33
+ 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) {
34
+
35
+ var Editor = require("ace/editor").Editor;
36
+ function showKeyboardShortcuts (editor) {
37
+ if(!document.getElementById('kbshortcutmenu')) {
38
+ var overlayPage = require('./menu_tools/overlay_page').overlayPage;
39
+ var getEditorKeybordShortcuts = require('./menu_tools/get_editor_keyboard_shortcuts').getEditorKeybordShortcuts;
40
+ var kb = getEditorKeybordShortcuts(editor);
41
+ var el = document.createElement('div');
42
+ var commands = kb.reduce(function(previous, current) {
43
+ return previous + '<div class="ace_optionsMenuEntry"><span class="ace_optionsMenuCommand">'
44
+ + current.command + '</span> : '
45
+ + '<span class="ace_optionsMenuKey">' + current.key + '</span></div>';
46
+ }, '');
47
+
48
+ el.id = 'kbshortcutmenu';
49
+ el.innerHTML = '<h1>Keyboard Shortcuts</h1>' + commands + '</div>';
50
+ overlayPage(editor, el, '0', '0', '0', null);
51
+ }
52
+ };
53
+ module.exports.init = function(editor) {
54
+ Editor.prototype.showKeyboardShortcuts = function() {
55
+ showKeyboardShortcuts(this);
56
+ };
57
+ editor.commands.addCommands([{
58
+ name: "showKeyboardShortcuts",
59
+ bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"},
60
+ exec: function(editor, line) {
61
+ editor.showKeyboardShortcuts();
62
+ }
63
+ }]);
64
+ };
65
+
66
+ });
67
+
68
+ define('ace/ext/menu_tools/overlay_page', ['require', 'exports', 'module' , 'ace/lib/dom'], function(require, exports, module) {
69
+
70
+ var dom = require("../../lib/dom");
71
+ var cssText = "#ace_settingsmenu, #kbshortcutmenu {\
72
+ background-color: #F7F7F7;\
73
+ color: black;\
74
+ box-shadow: -5px 4px 5px rgba(126, 126, 126, 0.55);\
75
+ padding: 1em 0.5em 2em 1em;\
76
+ overflow: auto;\
77
+ position: absolute;\
78
+ margin: 0;\
79
+ bottom: 0;\
80
+ right: 0;\
81
+ top: 0;\
82
+ z-index: 9991;\
83
+ cursor: default;\
84
+ }\
85
+ .ace_dark #ace_settingsmenu, .ace_dark #kbshortcutmenu {\
86
+ box-shadow: -20px 10px 25px rgba(126, 126, 126, 0.25);\
87
+ background-color: rgba(255, 255, 255, 0.6);\
88
+ color: black;\
89
+ }\
90
+ .ace_optionsMenuEntry:hover {\
91
+ background-color: rgba(100, 100, 100, 0.1);\
92
+ -webkit-transition: all 0.5s;\
93
+ transition: all 0.3s\
94
+ }\
95
+ .ace_closeButton {\
96
+ background: rgba(245, 146, 146, 0.5);\
97
+ border: 1px solid #F48A8A;\
98
+ border-radius: 50%;\
99
+ padding: 7px;\
100
+ position: absolute;\
101
+ right: -8px;\
102
+ top: -8px;\
103
+ z-index: 1000;\
104
+ }\
105
+ .ace_closeButton{\
106
+ background: rgba(245, 146, 146, 0.9);\
107
+ }\
108
+ .ace_optionsMenuKey {\
109
+ color: darkslateblue;\
110
+ font-weight: bold;\
111
+ }\
112
+ .ace_optionsMenuCommand {\
113
+ color: darkcyan;\
114
+ font-weight: normal;\
115
+ }";
116
+ dom.importCssString(cssText);
117
+ module.exports.overlayPage = function overlayPage(editor, contentElement, top, right, bottom, left) {
118
+ top = top ? 'top: ' + top + ';' : '';
119
+ bottom = bottom ? 'bottom: ' + bottom + ';' : '';
120
+ right = right ? 'right: ' + right + ';' : '';
121
+ left = left ? 'left: ' + left + ';' : '';
122
+
123
+ var closer = document.createElement('div');
124
+ var contentContainer = document.createElement('div');
125
+
126
+ function documentEscListener(e) {
127
+ if (e.keyCode === 27) {
128
+ closer.click();
129
+ }
130
+ }
131
+
132
+ closer.style.cssText = 'margin: 0; padding: 0; ' +
133
+ 'position: fixed; top:0; bottom:0; left:0; right:0;' +
134
+ 'z-index: 9990; ' +
135
+ 'background-color: rgba(0, 0, 0, 0.3);';
136
+ closer.addEventListener('click', function() {
137
+ document.removeEventListener('keydown', documentEscListener);
138
+ closer.parentNode.removeChild(closer);
139
+ editor.focus();
140
+ closer = null;
141
+ });
142
+ document.addEventListener('keydown', documentEscListener);
143
+
144
+ contentContainer.style.cssText = top + right + bottom + left;
145
+ contentContainer.addEventListener('click', function(e) {
146
+ e.stopPropagation();
147
+ });
148
+
149
+ var wrapper = dom.createElement("div");
150
+ wrapper.style.position = "relative";
151
+
152
+ var closeButton = dom.createElement("div");
153
+ closeButton.className = "ace_closeButton";
154
+ closeButton.addEventListener('click', function() {
155
+ closer.click();
156
+ });
157
+
158
+ wrapper.appendChild(closeButton);
159
+ contentContainer.appendChild(wrapper);
160
+
161
+ contentContainer.appendChild(contentElement);
162
+ closer.appendChild(contentContainer);
163
+ document.body.appendChild(closer);
164
+ editor.blur();
165
+ };
166
+
167
+ });
168
+
169
+ define('ace/ext/menu_tools/get_editor_keyboard_shortcuts', ['require', 'exports', 'module' , 'ace/lib/keys'], function(require, exports, module) {
170
+
171
+ var keys = require("../../lib/keys");
172
+ module.exports.getEditorKeybordShortcuts = function(editor) {
173
+ var KEY_MODS = keys.KEY_MODS;
174
+ var keybindings = [];
175
+ var commandMap = {};
176
+ editor.keyBinding.$handlers.forEach(function(handler) {
177
+ var ckb = handler.commandKeyBinding;
178
+ for (var i in ckb) {
179
+ var modifier = parseInt(i);
180
+ if (modifier == -1) {
181
+ modifier = "";
182
+ } else if(isNaN(modifier)) {
183
+ modifier = i;
184
+ } else {
185
+ modifier = "" +
186
+ (modifier & KEY_MODS.command ? "Cmd-" : "") +
187
+ (modifier & KEY_MODS.ctrl ? "Ctrl-" : "") +
188
+ (modifier & KEY_MODS.alt ? "Alt-" : "") +
189
+ (modifier & KEY_MODS.shift ? "Shift-" : "");
190
+ }
191
+ for (var key in ckb[i]) {
192
+ var command = ckb[i][key]
193
+ if (typeof command != "string")
194
+ command = command.name
195
+ if (commandMap[command]) {
196
+ commandMap[command].key += "|" + modifier + key;
197
+ } else {
198
+ commandMap[command] = {key: modifier+key, command: command};
199
+ keybindings.push(commandMap[command]);
200
+ }
201
+ }
202
+ }
203
+ });
204
+ return keybindings;
205
+ };
206
+
207
+ });
@@ -0,0 +1,1665 @@
1
+ /* ***** BEGIN LICENSE BLOCK *****
2
+ * Distributed under the BSD license:
3
+ *
4
+ * Copyright (c) 2012, Ajax.org B.V.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ * * Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * * Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ * * Neither the name of Ajax.org B.V. nor the
15
+ * names of its contributors may be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ *
29
+ * ***** END LICENSE BLOCK ***** */
30
+
31
+ define('ace/ext/language_tools', ['require', 'exports', 'module' , 'ace/snippets', 'ace/autocomplete', 'ace/config', 'ace/autocomplete/text_completer', 'ace/editor'], function(require, exports, module) {
32
+
33
+
34
+ var snippetManager = require("../snippets").snippetManager;
35
+ var Autocomplete = require("../autocomplete").Autocomplete;
36
+ var config = require("../config");
37
+
38
+ var textCompleter = require("../autocomplete/text_completer");
39
+ var keyWordCompleter = {
40
+ getCompletions: function(editor, session, pos, prefix, callback) {
41
+ var state = editor.session.getState(pos.row);
42
+ var completions = session.$mode.getCompletions(state, session, pos, prefix);
43
+ callback(null, completions);
44
+ }
45
+ };
46
+
47
+ var snippetCompleter = {
48
+ getCompletions: function(editor, session, pos, prefix, callback) {
49
+ var snippetMap = snippetManager.snippetMap;
50
+ var completions = [];
51
+ snippetManager.getActiveScopes(editor).forEach(function(scope) {
52
+ var snippets = snippetMap[scope] || [];
53
+ for (var i = snippets.length; i--;) {
54
+ var s = snippets[i];
55
+ var caption = s.name || s.tabTrigger;
56
+ if (!caption)
57
+ continue;
58
+ completions.push({
59
+ caption: caption,
60
+ snippet: s.content,
61
+ meta: s.tabTrigger && !s.name ? s.tabTrigger + "\u21E5 " : "snippet"
62
+ });
63
+ }
64
+ }, this);
65
+ callback(null, completions);
66
+ }
67
+ };
68
+
69
+ var completers = [snippetCompleter, textCompleter, keyWordCompleter];
70
+ exports.addCompleter = function(completer) {
71
+ completers.push(completer);
72
+ };
73
+
74
+ var expandSnippet = {
75
+ name: "expandSnippet",
76
+ exec: function(editor) {
77
+ var success = snippetManager.expandWithTab(editor);
78
+ if (!success)
79
+ editor.execCommand("indent");
80
+ },
81
+ bindKey: "tab"
82
+ };
83
+
84
+ var onChangeMode = function(e, editor) {
85
+ loadSnippetsForMode(editor.session.$mode);
86
+ };
87
+
88
+ var loadSnippetsForMode = function(mode) {
89
+ var id = mode.$id;
90
+ if (!snippetManager.files)
91
+ snippetManager.files = {};
92
+ loadSnippetFile(id);
93
+ if (mode.modes)
94
+ mode.modes.forEach(loadSnippetsForMode);
95
+ };
96
+
97
+ var loadSnippetFile = function(id) {
98
+ if (!id || snippetManager.files[id])
99
+ return;
100
+ var snippetFilePath = id.replace("mode", "snippets");
101
+ snippetManager.files[id] = {};
102
+ config.loadModule(snippetFilePath, function(m) {
103
+ if (m) {
104
+ snippetManager.files[id] = m;
105
+ m.snippets = snippetManager.parseSnippetFile(m.snippetText);
106
+ snippetManager.register(m.snippets, m.scope);
107
+ if (m.includeScopes) {
108
+ snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
109
+ m.includeScopes.forEach(function(x) {
110
+ loadSnippetFile("ace/mode/" + x);
111
+ });
112
+ }
113
+ }
114
+ });
115
+ };
116
+
117
+ var Editor = require("../editor").Editor;
118
+ require("../config").defineOptions(Editor.prototype, "editor", {
119
+ enableBasicAutocompletion: {
120
+ set: function(val) {
121
+ if (val) {
122
+ this.completers = completers;
123
+ this.commands.addCommand(Autocomplete.startCommand);
124
+ } else {
125
+ this.commands.removeCommand(Autocomplete.startCommand);
126
+ }
127
+ },
128
+ value: false
129
+ },
130
+ enableSnippets: {
131
+ set: function(val) {
132
+ if (val) {
133
+ this.commands.addCommand(expandSnippet);
134
+ this.on("changeMode", onChangeMode);
135
+ onChangeMode(null, this);
136
+ } else {
137
+ this.commands.removeCommand(expandSnippet);
138
+ this.off("changeMode", onChangeMode);
139
+ }
140
+ },
141
+ value: false
142
+ }
143
+ });
144
+
145
+ });
146
+
147
+ define('ace/snippets', ['require', 'exports', 'module' , 'ace/lib/lang', 'ace/range', 'ace/keyboard/hash_handler', 'ace/tokenizer', 'ace/lib/dom'], function(require, exports, module) {
148
+
149
+ var lang = require("./lib/lang")
150
+ var Range = require("./range").Range
151
+ var HashHandler = require("./keyboard/hash_handler").HashHandler;
152
+ var Tokenizer = require("./tokenizer").Tokenizer;
153
+ var comparePoints = Range.comparePoints;
154
+
155
+ var SnippetManager = function() {
156
+ this.snippetMap = {};
157
+ this.snippetNameMap = {};
158
+ };
159
+
160
+ (function() {
161
+ this.getTokenizer = function() {
162
+ function TabstopToken(str, _, stack) {
163
+ str = str.substr(1);
164
+ if (/^\d+$/.test(str) && !stack.inFormatString)
165
+ return [{tabstopId: parseInt(str, 10)}];
166
+ return [{text: str}]
167
+ }
168
+ function escape(ch) {
169
+ return "(?:[^\\\\" + ch + "]|\\\\.)";
170
+ }
171
+ SnippetManager.$tokenizer = new Tokenizer({
172
+ start: [
173
+ {regex: /:/, onMatch: function(val, state, stack) {
174
+ if (stack.length && stack[0].expectIf) {
175
+ stack[0].expectIf = false;
176
+ stack[0].elseBranch = stack[0];
177
+ return [stack[0]];
178
+ }
179
+ return ":";
180
+ }},
181
+ {regex: /\\./, onMatch: function(val, state, stack) {
182
+ var ch = val[1];
183
+ if (ch == "}" && stack.length) {
184
+ val = ch;
185
+ }else if ("`$\\".indexOf(ch) != -1) {
186
+ val = ch;
187
+ } else if (stack.inFormatString) {
188
+ if (ch == "n")
189
+ val = "\n";
190
+ else if (ch == "t")
191
+ val = "\n";
192
+ else if ("ulULE".indexOf(ch) != -1) {
193
+ val = {changeCase: ch, local: ch > "a"};
194
+ }
195
+ }
196
+
197
+ return [val];
198
+ }},
199
+ {regex: /}/, onMatch: function(val, state, stack) {
200
+ return [stack.length ? stack.shift() : val];
201
+ }},
202
+ {regex: /\$(?:\d+|\w+)/, onMatch: TabstopToken},
203
+ {regex: /\$\{[\dA-Z_a-z]+/, onMatch: function(str, state, stack) {
204
+ var t = TabstopToken(str.substr(1), state, stack);
205
+ stack.unshift(t[0]);
206
+ return t;
207
+ }, next: "snippetVar"},
208
+ {regex: /\n/, token: "newline", merge: false}
209
+ ],
210
+ snippetVar: [
211
+ {regex: "\\|" + escape("\\|") + "*\\|", onMatch: function(val, state, stack) {
212
+ stack[0].choices = val.slice(1, -1).split(",");
213
+ }, next: "start"},
214
+ {regex: "/(" + escape("/") + "+)/(?:(" + escape("/") + "*)/)(\\w*):?",
215
+ onMatch: function(val, state, stack) {
216
+ var ts = stack[0];
217
+ ts.fmtString = val;
218
+
219
+ val = this.splitRegex.exec(val);
220
+ ts.guard = val[1];
221
+ ts.fmt = val[2];
222
+ ts.flag = val[3];
223
+ return "";
224
+ }, next: "start"},
225
+ {regex: "`" + escape("`") + "*`", onMatch: function(val, state, stack) {
226
+ stack[0].code = val.splice(1, -1);
227
+ return "";
228
+ }, next: "start"},
229
+ {regex: "\\?", onMatch: function(val, state, stack) {
230
+ if (stack[0])
231
+ stack[0].expectIf = true;
232
+ }, next: "start"},
233
+ {regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "start"}
234
+ ],
235
+ formatString: [
236
+ {regex: "/(" + escape("/") + "+)/", token: "regex"},
237
+ {regex: "", onMatch: function(val, state, stack) {
238
+ stack.inFormatString = true;
239
+ }, next: "start"}
240
+ ]
241
+ });
242
+ SnippetManager.prototype.getTokenizer = function() {
243
+ return SnippetManager.$tokenizer;
244
+ }
245
+ return SnippetManager.$tokenizer;
246
+ };
247
+
248
+ this.tokenizeTmSnippet = function(str, startState) {
249
+ return this.getTokenizer().getLineTokens(str, startState).tokens.map(function(x) {
250
+ return x.value || x;
251
+ });
252
+ };
253
+
254
+ this.$getDefaultValue = function(editor, name) {
255
+ if (/^[A-Z]\d+$/.test(name)) {
256
+ var i = name.substr(1);
257
+ return (this.variables[name[0] + "__"] || {})[i];
258
+ }
259
+ if (/^\d+$/.test(name)) {
260
+ return (this.variables.__ || {})[name];
261
+ }
262
+ name = name.replace(/^TM_/, "");
263
+
264
+ if (!editor)
265
+ return;
266
+ var s = editor.session;
267
+ switch(name) {
268
+ case "CURRENT_WORD":
269
+ var r = s.getWordRange();
270
+ case "SELECTION":
271
+ case "SELECTED_TEXT":
272
+ return s.getTextRange(r);
273
+ case "CURRENT_LINE":
274
+ return s.getLine(editor.getCursorPosition().row);
275
+ case "PREV_LINE": // not possible in textmate
276
+ return s.getLine(editor.getCursorPosition().row - 1);
277
+ case "LINE_INDEX":
278
+ return editor.getCursorPosition().column;
279
+ case "LINE_NUMBER":
280
+ return editor.getCursorPosition().row + 1;
281
+ case "SOFT_TABS":
282
+ return s.getUseSoftTabs() ? "YES" : "NO";
283
+ case "TAB_SIZE":
284
+ return s.getTabSize();
285
+ case "FILENAME":
286
+ case "FILEPATH":
287
+ return "ace.ajax.org";
288
+ case "FULLNAME":
289
+ return "Ace";
290
+ }
291
+ };
292
+ this.variables = {};
293
+ this.getVariableValue = function(editor, varName) {
294
+ if (this.variables.hasOwnProperty(varName))
295
+ return this.variables[varName](editor, varName) || "";
296
+ return this.$getDefaultValue(editor, varName) || "";
297
+ };
298
+ this.tmStrFormat = function(str, ch, editor) {
299
+ var flag = ch.flag || "";
300
+ var re = ch.guard;
301
+ re = new RegExp(re, flag.replace(/[^gi]/, ""));
302
+ var fmtTokens = this.tokenizeTmSnippet(ch.fmt, "formatString");
303
+ var _self = this;
304
+ var formatted = str.replace(re, function() {
305
+ _self.variables.__ = arguments;
306
+ var fmtParts = _self.resolveVariables(fmtTokens, editor);
307
+ var gChangeCase = "E";
308
+ for (var i = 0; i < fmtParts.length; i++) {
309
+ var ch = fmtParts[i];
310
+ if (typeof ch == "object") {
311
+ fmtParts[i] = "";
312
+ if (ch.changeCase && ch.local) {
313
+ var next = fmtParts[i + 1];
314
+ if (next && typeof next == "string") {
315
+ if (ch.changeCase == "u")
316
+ fmtParts[i] = next[0].toUpperCase();
317
+ else
318
+ fmtParts[i] = next[0].toLowerCase();
319
+ fmtParts[i + 1] = next.substr(1);
320
+ }
321
+ } else if (ch.changeCase) {
322
+ gChangeCase = ch.changeCase;
323
+ }
324
+ } else if (gChangeCase == "U") {
325
+ fmtParts[i] = ch.toUpperCase();
326
+ } else if (gChangeCase == "L") {
327
+ fmtParts[i] = ch.toLowerCase();
328
+ }
329
+ }
330
+ return fmtParts.join("");
331
+ });
332
+ this.variables.__ = null;
333
+ return formatted;
334
+ };
335
+
336
+ this.resolveVariables = function(snippet, editor) {
337
+ var result = [];
338
+ for (var i = 0; i < snippet.length; i++) {
339
+ var ch = snippet[i];
340
+ if (typeof ch == "string") {
341
+ result.push(ch);
342
+ } else if (typeof ch != "object") {
343
+ continue;
344
+ } else if (ch.skip) {
345
+ gotoNext(ch);
346
+ } else if (ch.processed < i) {
347
+ continue;
348
+ } else if (ch.text) {
349
+ var value = this.getVariableValue(editor, ch.text);
350
+ if (value && ch.fmtString)
351
+ value = this.tmStrFormat(value, ch);
352
+ ch.processed = i;
353
+ if (ch.expectIf == null) {
354
+ if (value) {
355
+ result.push(value);
356
+ gotoNext(ch);
357
+ }
358
+ } else {
359
+ if (value) {
360
+ ch.skip = ch.elseBranch;
361
+ } else
362
+ gotoNext(ch);
363
+ }
364
+ } else if (ch.tabstopId != null) {
365
+ result.push(ch);
366
+ } else if (ch.changeCase != null) {
367
+ result.push(ch);
368
+ }
369
+ }
370
+ function gotoNext(ch) {
371
+ var i1 = snippet.indexOf(ch, i + 1);
372
+ if (i1 != -1)
373
+ i = i1;
374
+ }
375
+ return result;
376
+ };
377
+
378
+ this.insertSnippet = function(editor, snippetText) {
379
+ var cursor = editor.getCursorPosition();
380
+ var line = editor.session.getLine(cursor.row);
381
+ var indentString = line.match(/^\s*/)[0];
382
+ var tabString = editor.session.getTabString();
383
+
384
+ var tokens = this.tokenizeTmSnippet(snippetText);
385
+ tokens = this.resolveVariables(tokens, editor);
386
+ tokens = tokens.map(function(x) {
387
+ if (x == "\n")
388
+ return x + indentString;
389
+ if (typeof x == "string")
390
+ return x.replace(/\t/g, tabString);
391
+ return x;
392
+ });
393
+ var tabstops = [];
394
+ tokens.forEach(function(p, i) {
395
+ if (typeof p != "object")
396
+ return;
397
+ var id = p.tabstopId;
398
+ var ts = tabstops[id];
399
+ if (!ts) {
400
+ ts = tabstops[id] = [];
401
+ ts.index = id;
402
+ ts.value = "";
403
+ }
404
+ if (ts.indexOf(p) !== -1)
405
+ return;
406
+ ts.push(p);
407
+ var i1 = tokens.indexOf(p, i + 1);
408
+ if (i1 === -1)
409
+ return;
410
+
411
+ var value = tokens.slice(i + 1, i1);
412
+ var isNested = value.some(function(t) {return typeof t === "object"});
413
+ if (isNested && !ts.value) {
414
+ ts.value = value;
415
+ } else if (value.length && (!ts.value || typeof ts.value !== "string")) {
416
+ ts.value = value.join("");
417
+ }
418
+ });
419
+ tabstops.forEach(function(ts) {ts.length = 0});
420
+ var expanding = {};
421
+ function copyValue(val) {
422
+ var copy = []
423
+ for (var i = 0; i < val.length; i++) {
424
+ var p = val[i];
425
+ if (typeof p == "object") {
426
+ if (expanding[p.tabstopId])
427
+ continue;
428
+ var j = val.lastIndexOf(p, i - 1);
429
+ p = copy[j] || {tabstopId: p.tabstopId};
430
+ }
431
+ copy[i] = p;
432
+ }
433
+ return copy;
434
+ }
435
+ for (var i = 0; i < tokens.length; i++) {
436
+ var p = tokens[i];
437
+ if (typeof p != "object")
438
+ continue;
439
+ var id = p.tabstopId;
440
+ var i1 = tokens.indexOf(p, i + 1);
441
+ if (expanding[id] == p) {
442
+ expanding[id] = null;
443
+ continue;
444
+ }
445
+
446
+ var ts = tabstops[id];
447
+ var arg = typeof ts.value == "string" ? [ts.value] : copyValue(ts.value);
448
+ arg.unshift(i + 1, Math.max(0, i1 - i));
449
+ arg.push(p);
450
+ expanding[id] = p;
451
+ tokens.splice.apply(tokens, arg);
452
+
453
+ if (ts.indexOf(p) === -1)
454
+ ts.push(p);
455
+ };
456
+ var row = 0, column = 0;
457
+ var text = "";
458
+ tokens.forEach(function(t) {
459
+ if (typeof t === "string") {
460
+ if (t[0] === "\n"){
461
+ column = t.length - 1;
462
+ row ++;
463
+ } else
464
+ column += t.length;
465
+ text += t;
466
+ } else {
467
+ if (!t.start)
468
+ t.start = {row: row, column: column};
469
+ else
470
+ t.end = {row: row, column: column};
471
+ }
472
+ });
473
+ var range = editor.getSelectionRange();
474
+ var end = editor.session.replace(range, text);
475
+
476
+ var tabstopManager = new TabstopManager(editor);
477
+ tabstopManager.addTabstops(tabstops, range.start, end);
478
+ tabstopManager.tabNext();
479
+ };
480
+
481
+ this.$getScope = function(editor) {
482
+ var scope = editor.session.$mode.$id || "";
483
+ scope = scope.split("/").pop();
484
+ if (scope === "html" || scope === "php") {
485
+ if (scope === "php")
486
+ scope = "html";
487
+ var c = editor.getCursorPosition()
488
+ var state = editor.session.getState(c.row);
489
+ if (typeof state === "object") {
490
+ state = state[0];
491
+ }
492
+ if (state.substring) {
493
+ if (state.substring(0, 3) == "js-")
494
+ scope = "javascript";
495
+ else if (state.substring(0, 4) == "css-")
496
+ scope = "css";
497
+ else if (state.substring(0, 4) == "php-")
498
+ scope = "php";
499
+ }
500
+ }
501
+
502
+ return scope;
503
+ };
504
+
505
+ this.getActiveScopes = function(editor) {
506
+ var scope = this.$getScope(editor);
507
+ var scopes = [scope];
508
+ var snippetMap = this.snippetMap;
509
+ if (snippetMap[scope] && snippetMap[scope].includeScopes) {
510
+ scopes.push.apply(scopes, snippetMap[scope].includeScopes);
511
+ }
512
+ scopes.push("_");
513
+ return scopes;
514
+ };
515
+
516
+ this.expandWithTab = function(editor) {
517
+ var cursor = editor.getCursorPosition();
518
+ var line = editor.session.getLine(cursor.row);
519
+ var before = line.substring(0, cursor.column);
520
+ var after = line.substr(cursor.column);
521
+
522
+ var snippetMap = this.snippetMap;
523
+ var snippet;
524
+ this.getActiveScopes(editor).some(function(scope) {
525
+ var snippets = snippetMap[scope];
526
+ if (snippets)
527
+ snippet = this.findMatchingSnippet(snippets, before, after);
528
+ return !!snippet;
529
+ }, this);
530
+ if (!snippet)
531
+ return false;
532
+
533
+ editor.session.doc.removeInLine(cursor.row,
534
+ cursor.column - snippet.replaceBefore.length,
535
+ cursor.column + snippet.replaceAfter.length
536
+ );
537
+
538
+ this.variables.M__ = snippet.matchBefore;
539
+ this.variables.T__ = snippet.matchAfter;
540
+ this.insertSnippet(editor, snippet.content);
541
+
542
+ this.variables.M__ = this.variables.T__ = null;
543
+ return true;
544
+ };
545
+
546
+ this.findMatchingSnippet = function(snippetList, before, after) {
547
+ for (var i = snippetList.length; i--;) {
548
+ var s = snippetList[i];
549
+ if (s.startRe && !s.startRe.test(before))
550
+ continue;
551
+ if (s.endRe && !s.endRe.test(after))
552
+ continue;
553
+ if (!s.startRe && !s.endRe)
554
+ continue;
555
+
556
+ s.matchBefore = s.startRe ? s.startRe.exec(before) : [""];
557
+ s.matchAfter = s.endRe ? s.endRe.exec(after) : [""];
558
+ s.replaceBefore = s.triggerRe ? s.triggerRe.exec(before)[0] : "";
559
+ s.replaceAfter = s.endTriggerRe ? s.endTriggerRe.exec(after)[0] : "";
560
+ return s;
561
+ }
562
+ };
563
+
564
+ this.snippetMap = {};
565
+ this.snippetNameMap = {};
566
+ this.register = function(snippets, scope) {
567
+ var snippetMap = this.snippetMap;
568
+ var snippetNameMap = this.snippetNameMap;
569
+ var self = this;
570
+ function wrapRegexp(src) {
571
+ if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src))
572
+ src = "(?:" + src + ")"
573
+
574
+ return src || "";
575
+ }
576
+ function guardedRegexp(re, guard, opening) {
577
+ re = wrapRegexp(re);
578
+ guard = wrapRegexp(guard);
579
+ if (opening) {
580
+ re = guard + re;
581
+ if (re && re[re.length - 1] != "$")
582
+ re = re + "$";
583
+ } else {
584
+ re = re + guard;
585
+ if (re && re[0] != "^")
586
+ re = "^" + re;
587
+ }
588
+ return new RegExp(re);
589
+ }
590
+
591
+ function addSnippet(s) {
592
+ if (!s.scope)
593
+ s.scope = scope || "_";
594
+ scope = s.scope
595
+ if (!snippetMap[scope]) {
596
+ snippetMap[scope] = [];
597
+ snippetNameMap[scope] = {};
598
+ }
599
+
600
+ var map = snippetNameMap[scope];
601
+ if (s.name) {
602
+ var old = map[s.name];
603
+ if (old)
604
+ self.unregister(old);
605
+ map[s.name] = s;
606
+ }
607
+ snippetMap[scope].push(s);
608
+
609
+ if (s.tabTrigger && !s.trigger) {
610
+ if (!s.guard && /^\w/.test(s.tabTrigger))
611
+ s.guard = "\\b";
612
+ s.trigger = lang.escapeRegExp(s.tabTrigger);
613
+ }
614
+
615
+ s.startRe = guardedRegexp(s.trigger, s.guard, true);
616
+ s.triggerRe = new RegExp(s.trigger, "", true);
617
+
618
+ s.endRe = guardedRegexp(s.endTrigger, s.endGuard, true);
619
+ s.endTriggerRe = new RegExp(s.endTrigger, "", true);
620
+ };
621
+
622
+ if (snippets.content)
623
+ addSnippet(snippets);
624
+ else if (Array.isArray(snippets))
625
+ snippets.forEach(addSnippet);
626
+ };
627
+ this.unregister = function(snippets, scope) {
628
+ var snippetMap = this.snippetMap;
629
+ var snippetNameMap = this.snippetNameMap;
630
+
631
+ function removeSnippet(s) {
632
+ var nameMap = snippetNameMap[s.scope||scope];
633
+ if (nameMap && nameMap[s.name]) {
634
+ delete nameMap[s.name];
635
+ var map = snippetMap[s.scope||scope];
636
+ var i = map && map.indexOf(s);
637
+ if (i >= 0)
638
+ map.splice(i, 1);
639
+ }
640
+ }
641
+ if (snippets.content)
642
+ removeSnippet(snippets);
643
+ else if (Array.isArray(snippets))
644
+ snippets.forEach(removeSnippet);
645
+ };
646
+ this.parseSnippetFile = function(str) {
647
+ str = str.replace(/\r/g, "");
648
+ var list = [], snippet = {};
649
+ var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
650
+ var m;
651
+ while (m = re.exec(str)) {
652
+ if (m[1]) {
653
+ try {
654
+ snippet = JSON.parse(m[1])
655
+ list.push(snippet);
656
+ } catch (e) {}
657
+ } if (m[4]) {
658
+ snippet.content = m[4].replace(/^\t/gm, "");
659
+ list.push(snippet);
660
+ snippet = {};
661
+ } else {
662
+ var key = m[2], val = m[3];
663
+ if (key == "regex") {
664
+ var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g;
665
+ snippet.guard = guardRe.exec(val)[1];
666
+ snippet.trigger = guardRe.exec(val)[1];
667
+ snippet.endTrigger = guardRe.exec(val)[1];
668
+ snippet.endGuard = guardRe.exec(val)[1];
669
+ } else if (key == "snippet") {
670
+ snippet.tabTrigger = val.match(/^\S*/)[0];
671
+ if (!snippet.name)
672
+ snippet.name = val;
673
+ } else {
674
+ snippet[key] = val;
675
+ }
676
+ }
677
+ }
678
+ return list;
679
+ };
680
+ this.getSnippetByName = function(name, editor) {
681
+ var snippetMap = this.snippetNameMap;
682
+ var snippet;
683
+ this.getActiveScopes(editor).some(function(scope) {
684
+ var snippets = snippetMap[scope];
685
+ if (snippets)
686
+ snippet = snippets[name];
687
+ return !!snippet;
688
+ }, this);
689
+ return snippet;
690
+ };
691
+
692
+ }).call(SnippetManager.prototype);
693
+
694
+
695
+ var TabstopManager = function(editor) {
696
+ if (editor.tabstopManager)
697
+ return editor.tabstopManager;
698
+ editor.tabstopManager = this;
699
+ this.$onChange = this.onChange.bind(this);
700
+ this.$onChangeSelection = lang.delayedCall(this.onChangeSelection.bind(this)).schedule;
701
+ this.$onChangeSession = this.onChangeSession.bind(this);
702
+ this.$onAfterExec = this.onAfterExec.bind(this);
703
+ this.attach(editor);
704
+ };
705
+ (function() {
706
+ this.attach = function(editor) {
707
+ this.index = -1;
708
+ this.ranges = [];
709
+ this.tabstops = [];
710
+ this.selectedTabstop = null;
711
+
712
+ this.editor = editor;
713
+ this.editor.on("change", this.$onChange);
714
+ this.editor.on("changeSelection", this.$onChangeSelection);
715
+ this.editor.on("changeSession", this.$onChangeSession);
716
+ this.editor.commands.on("afterExec", this.$onAfterExec);
717
+ this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
718
+ };
719
+ this.detach = function() {
720
+ this.tabstops.forEach(this.removeTabstopMarkers, this);
721
+ this.ranges = null;
722
+ this.tabstops = null;
723
+ this.selectedTabstop = null;
724
+ this.editor.removeListener("change", this.$onChange);
725
+ this.editor.removeListener("changeSelection", this.$onChangeSelection);
726
+ this.editor.removeListener("changeSession", this.$onChangeSession);
727
+ this.editor.commands.removeListener("afterExec", this.$onAfterExec);
728
+ this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
729
+ this.editor.tabstopManager = null;
730
+ this.editor = null;
731
+ };
732
+
733
+ this.onChange = function(e) {
734
+ var changeRange = e.data.range;
735
+ var isRemove = e.data.action[0] == "r";
736
+ var start = changeRange.start;
737
+ var end = changeRange.end;
738
+ var startRow = start.row;
739
+ var endRow = end.row;
740
+ var lineDif = endRow - startRow;
741
+ var colDiff = end.column - start.column;
742
+
743
+ if (isRemove) {
744
+ lineDif = -lineDif;
745
+ colDiff = -colDiff;
746
+ }
747
+ if (!this.$inChange && isRemove) {
748
+ var ts = this.selectedTabstop;
749
+ var changedOutside = !ts.some(function(r) {
750
+ return comparePoints(r.start, start) <= 0 && comparePoints(r.end, end) >= 0;
751
+ });
752
+ if (changedOutside)
753
+ return this.detach();
754
+ }
755
+ var ranges = this.ranges;
756
+ for (var i = 0; i < ranges.length; i++) {
757
+ var r = ranges[i];
758
+ if (r.end.row < start.row)
759
+ continue;
760
+
761
+ if (comparePoints(start, r.start) < 0 && comparePoints(end, r.end) > 0) {
762
+ this.removeRange(r);
763
+ i--;
764
+ continue;
765
+ }
766
+
767
+ if (r.start.row == startRow && r.start.column > start.column)
768
+ r.start.column += colDiff;
769
+ if (r.end.row == startRow && r.end.column >= start.column)
770
+ r.end.column += colDiff;
771
+ if (r.start.row >= startRow)
772
+ r.start.row += lineDif;
773
+ if (r.end.row >= startRow)
774
+ r.end.row += lineDif;
775
+
776
+ if (comparePoints(r.start, r.end) > 0)
777
+ this.removeRange(r);
778
+ }
779
+ if (!ranges.length)
780
+ this.detach();
781
+ };
782
+ this.updateLinkedFields = function() {
783
+ var ts = this.selectedTabstop;
784
+ if (!ts.hasLinkedRanges)
785
+ return;
786
+ this.$inChange = true;
787
+ var session = this.editor.session;
788
+ var text = session.getTextRange(ts.firstNonLinked);
789
+ for (var i = ts.length; i--;) {
790
+ var range = ts[i];
791
+ if (!range.linked)
792
+ continue;
793
+ var fmt = exports.snippetManager.tmStrFormat(text, range.original)
794
+ session.replace(range, fmt);
795
+ }
796
+ this.$inChange = false;
797
+ };
798
+ this.onAfterExec = function(e) {
799
+ if (e.command && !e.command.readOnly)
800
+ this.updateLinkedFields();
801
+ };
802
+ this.onChangeSelection = function() {
803
+ if (!this.editor)
804
+ return
805
+ var lead = this.editor.selection.lead;
806
+ var anchor = this.editor.selection.anchor;
807
+ var isEmpty = this.editor.selection.isEmpty();
808
+ for (var i = this.ranges.length; i--;) {
809
+ if (this.ranges[i].linked)
810
+ continue;
811
+ var containsLead = this.ranges[i].contains(lead.row, lead.column);
812
+ var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column);
813
+ if (containsLead && containsAnchor)
814
+ return;
815
+ }
816
+ this.detach();
817
+ };
818
+ this.onChangeSession = function() {
819
+ this.detach();
820
+ };
821
+ this.tabNext = function(dir) {
822
+ var max = this.tabstops.length - 1;
823
+ var index = this.index + (dir || 1);
824
+ index = Math.min(Math.max(index, 0), max);
825
+ this.selectTabstop(index);
826
+ if (index == max)
827
+ this.detach();
828
+ };
829
+ this.selectTabstop = function(index) {
830
+ var ts = this.tabstops[this.index];
831
+ if (ts)
832
+ this.addTabstopMarkers(ts);
833
+ this.index = index;
834
+ ts = this.tabstops[this.index];
835
+ if (!ts || !ts.length)
836
+ return;
837
+
838
+ this.selectedTabstop = ts;
839
+ if (!this.editor.inVirtualSelectionMode) {
840
+ var sel = this.editor.multiSelect;
841
+ sel.toSingleRange(ts.firstNonLinked.clone());
842
+ for (var i = ts.length; i--;) {
843
+ if (ts.hasLinkedRanges && ts[i].linked)
844
+ continue;
845
+ sel.addRange(ts[i].clone(), true);
846
+ }
847
+ } else {
848
+ this.editor.selection.setRange(ts.firstNonLinked);
849
+ }
850
+
851
+ this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
852
+ };
853
+ this.addTabstops = function(tabstops, start, end) {
854
+ if (!tabstops[0]) {
855
+ var p = Range.fromPoints(end, end);
856
+ moveRelative(p.start, start);
857
+ moveRelative(p.end, start);
858
+ tabstops[0] = [p];
859
+ tabstops[0].index = 0;
860
+ }
861
+
862
+ var i = this.index;
863
+ var arg = [i, 0];
864
+ var ranges = this.ranges;
865
+ var editor = this.editor;
866
+ tabstops.forEach(function(ts) {
867
+ for (var i = ts.length; i--;) {
868
+ var p = ts[i];
869
+ var range = Range.fromPoints(p.start, p.end || p.start);
870
+ movePoint(range.start, start);
871
+ movePoint(range.end, start);
872
+ range.original = p;
873
+ range.tabstop = ts;
874
+ ranges.push(range);
875
+ ts[i] = range;
876
+ if (p.fmtString) {
877
+ range.linked = true;
878
+ ts.hasLinkedRanges = true;
879
+ } else if (!ts.firstNonLinked)
880
+ ts.firstNonLinked = range;
881
+ }
882
+ if (!ts.firstNonLinked)
883
+ ts.hasLinkedRanges = false;
884
+ arg.push(ts);
885
+ this.addTabstopMarkers(ts);
886
+ }, this);
887
+ arg.push(arg.splice(2, 1)[0]);
888
+ this.tabstops.splice.apply(this.tabstops, arg);
889
+ };
890
+
891
+ this.addTabstopMarkers = function(ts) {
892
+ var session = this.editor.session;
893
+ ts.forEach(function(range) {
894
+ if (!range.markerId)
895
+ range.markerId = session.addMarker(range, "ace_snippet-marker", "text");
896
+ });
897
+ };
898
+ this.removeTabstopMarkers = function(ts) {
899
+ var session = this.editor.session;
900
+ ts.forEach(function(range) {
901
+ session.removeMarker(range.markerId);
902
+ range.markerId = null;
903
+ });
904
+ };
905
+ this.removeRange = function(range) {
906
+ var i = range.tabstop.indexOf(range);
907
+ range.tabstop.splice(i, 1);
908
+ i = this.ranges.indexOf(range);
909
+ this.ranges.splice(i, 1);
910
+ this.editor.session.removeMarker(range.markerId);
911
+ };
912
+
913
+ this.keyboardHandler = new HashHandler();
914
+ this.keyboardHandler.bindKeys({
915
+ "Tab": function(ed) {
916
+ if (exports.snippetManager && exports.snippetManager.expandWithTab(ed)) {
917
+ return;
918
+ }
919
+
920
+ ed.tabstopManager.tabNext(1);
921
+ },
922
+ "Shift-Tab": function(ed) {
923
+ ed.tabstopManager.tabNext(-1);
924
+ },
925
+ "Esc": function(ed) {
926
+ ed.tabstopManager.detach();
927
+ },
928
+ "Return": function(ed) {
929
+ return false;
930
+ }
931
+ });
932
+ }).call(TabstopManager.prototype);
933
+
934
+
935
+ var movePoint = function(point, diff) {
936
+ if (point.row == 0)
937
+ point.column += diff.column;
938
+ point.row += diff.row;
939
+ };
940
+
941
+ var moveRelative = function(point, start) {
942
+ if (point.row == start.row)
943
+ point.column -= start.column;
944
+ point.row -= start.row;
945
+ };
946
+
947
+
948
+ require("./lib/dom").importCssString("\
949
+ .ace_snippet-marker {\
950
+ -moz-box-sizing: border-box;\
951
+ box-sizing: border-box;\
952
+ background: rgba(194, 193, 208, 0.09);\
953
+ border: 1px dotted rgba(211, 208, 235, 0.62);\
954
+ position: absolute;\
955
+ }");
956
+
957
+ exports.snippetManager = new SnippetManager();
958
+
959
+
960
+ });
961
+
962
+ define('ace/autocomplete', ['require', 'exports', 'module' , 'ace/keyboard/hash_handler', 'ace/autocomplete/popup', 'ace/autocomplete/util', 'ace/lib/event', 'ace/lib/lang', 'ace/snippets'], function(require, exports, module) {
963
+
964
+
965
+ var HashHandler = require("./keyboard/hash_handler").HashHandler;
966
+ var AcePopup = require("./autocomplete/popup").AcePopup;
967
+ var util = require("./autocomplete/util");
968
+ var event = require("./lib/event");
969
+ var lang = require("./lib/lang");
970
+ var snippetManager = require("./snippets").snippetManager;
971
+
972
+ var Autocomplete = function() {
973
+ this.autoInsert = true;
974
+ this.keyboardHandler = new HashHandler();
975
+ this.keyboardHandler.bindKeys(this.commands);
976
+
977
+ this.blurListener = this.blurListener.bind(this);
978
+ this.changeListener = this.changeListener.bind(this);
979
+ this.mousedownListener = this.mousedownListener.bind(this);
980
+ this.mousewheelListener = this.mousewheelListener.bind(this);
981
+
982
+ this.changeTimer = lang.delayedCall(function() {
983
+ this.updateCompletions(true);
984
+ }.bind(this))
985
+ };
986
+
987
+ (function() {
988
+ this.$init = function() {
989
+ this.popup = new AcePopup(document.body || document.documentElement);
990
+ this.popup.on("click", function(e) {
991
+ this.insertMatch();
992
+ e.stop();
993
+ }.bind(this));
994
+ };
995
+
996
+ this.openPopup = function(editor, prefix, keepPopupPosition) {
997
+ if (!this.popup)
998
+ this.$init();
999
+
1000
+ this.popup.setData(this.completions.filtered);
1001
+
1002
+ var renderer = editor.renderer;
1003
+ if (!keepPopupPosition) {
1004
+ this.popup.setRow(0);
1005
+ this.popup.setFontSize(editor.getFontSize());
1006
+
1007
+ var lineHeight = renderer.layerConfig.lineHeight;
1008
+
1009
+ var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
1010
+ pos.left -= this.popup.getTextLeftOffset();
1011
+
1012
+ var rect = editor.container.getBoundingClientRect();
1013
+ pos.top += rect.top - renderer.layerConfig.offset;
1014
+ pos.left += rect.left - editor.renderer.scrollLeft;
1015
+ pos.left += renderer.$gutterLayer.gutterWidth;
1016
+
1017
+ this.popup.show(pos, lineHeight);
1018
+ }
1019
+ };
1020
+
1021
+ this.detach = function() {
1022
+ this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
1023
+ this.editor.off("changeSelection", this.changeListener);
1024
+ this.editor.off("blur", this.changeListener);
1025
+ this.editor.off("mousedown", this.mousedownListener);
1026
+ this.editor.off("mousewheel", this.mousewheelListener);
1027
+ this.changeTimer.cancel();
1028
+
1029
+ if (this.popup)
1030
+ this.popup.hide();
1031
+
1032
+ this.activated = false;
1033
+ this.completions = this.base = null;
1034
+ };
1035
+
1036
+ this.changeListener = function(e) {
1037
+ var cursor = this.editor.selection.lead;
1038
+ if (cursor.row != this.base.row || cursor.column < this.base.column) {
1039
+ this.detach();
1040
+ }
1041
+ if (this.activated)
1042
+ this.changeTimer.schedule();
1043
+ else
1044
+ this.detach();
1045
+ };
1046
+
1047
+ this.blurListener = function() {
1048
+ if (document.activeElement != this.editor.textInput.getElement())
1049
+ this.detach();
1050
+ };
1051
+
1052
+ this.mousedownListener = function(e) {
1053
+ this.detach();
1054
+ };
1055
+
1056
+ this.mousewheelListener = function(e) {
1057
+ this.detach();
1058
+ };
1059
+
1060
+ this.goTo = function(where) {
1061
+ var row = this.popup.getRow();
1062
+ var max = this.popup.session.getLength() - 1;
1063
+
1064
+ switch(where) {
1065
+ case "up": row = row < 0 ? max : row - 1; break;
1066
+ case "down": row = row >= max ? -1 : row + 1; break;
1067
+ case "start": row = 0; break;
1068
+ case "end": row = max; break;
1069
+ }
1070
+
1071
+ this.popup.setRow(row);
1072
+ };
1073
+
1074
+ this.insertMatch = function(data) {
1075
+ if (!data)
1076
+ data = this.popup.getData(this.popup.getRow());
1077
+ if (!data)
1078
+ return false;
1079
+ if (data.completer && data.completer.insertMatch) {
1080
+ data.completer.insertMatch(this.editor);
1081
+ } else {
1082
+ if (this.completions.filterText) {
1083
+ var ranges = this.editor.selection.getAllRanges();
1084
+ for (var i = 0, range; range = ranges[i]; i++) {
1085
+ range.start.column -= this.completions.filterText.length;
1086
+ this.editor.session.remove(range);
1087
+ }
1088
+ }
1089
+ if (data.snippet)
1090
+ snippetManager.insertSnippet(this.editor, data.snippet);
1091
+ else
1092
+ this.editor.execCommand("insertstring", data.value || data);
1093
+ }
1094
+ this.detach();
1095
+ };
1096
+
1097
+ this.commands = {
1098
+ "Up": function(editor) { editor.completer.goTo("up"); },
1099
+ "Down": function(editor) { editor.completer.goTo("down"); },
1100
+ "Ctrl-Up|Ctrl-Home": function(editor) { editor.completer.goTo("start"); },
1101
+ "Ctrl-Down|Ctrl-End": function(editor) { editor.completer.goTo("end"); },
1102
+
1103
+ "Esc": function(editor) { editor.completer.detach(); },
1104
+ "Space": function(editor) { editor.completer.detach(); editor.insert(" ");},
1105
+ "Return": function(editor) { editor.completer.insertMatch(); },
1106
+ "Shift-Return": function(editor) { editor.completer.insertMatch(true); },
1107
+ "Tab": function(editor) { editor.completer.insertMatch(); },
1108
+
1109
+ "PageUp": function(editor) { editor.completer.popup.gotoPageUp(); },
1110
+ "PageDown": function(editor) { editor.completer.popup.gotoPageDown(); }
1111
+ };
1112
+
1113
+ this.gatherCompletions = function(editor, callback) {
1114
+ var session = editor.getSession();
1115
+ var pos = editor.getCursorPosition();
1116
+
1117
+ var line = session.getLine(pos.row);
1118
+ var prefix = util.retrievePrecedingIdentifier(line, pos.column);
1119
+
1120
+ this.base = editor.getCursorPosition();
1121
+ this.base.column -= prefix.length;
1122
+
1123
+ var matches = [];
1124
+ util.parForEach(editor.completers, function(completer, next) {
1125
+ completer.getCompletions(editor, session, pos, prefix, function(err, results) {
1126
+ if (!err)
1127
+ matches = matches.concat(results);
1128
+ next();
1129
+ });
1130
+ }, function() {
1131
+ callback(null, {
1132
+ prefix: prefix,
1133
+ matches: matches
1134
+ });
1135
+ });
1136
+ return true;
1137
+ };
1138
+
1139
+ this.showPopup = function(editor) {
1140
+ if (this.editor)
1141
+ this.detach();
1142
+
1143
+ this.activated = true;
1144
+
1145
+ this.editor = editor;
1146
+ if (editor.completer != this) {
1147
+ if (editor.completer)
1148
+ editor.completer.detach();
1149
+ editor.completer = this;
1150
+ }
1151
+
1152
+ editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
1153
+ editor.on("changeSelection", this.changeListener);
1154
+ editor.on("blur", this.blurListener);
1155
+ editor.on("mousedown", this.mousedownListener);
1156
+ editor.on("mousewheel", this.mousewheelListener);
1157
+
1158
+ this.updateCompletions();
1159
+ };
1160
+
1161
+ this.updateCompletions = function(keepPopupPosition) {
1162
+ if (keepPopupPosition && this.base && this.completions) {
1163
+ var pos = this.editor.getCursorPosition();
1164
+ var prefix = this.editor.session.getTextRange({start: this.base, end: pos});
1165
+ if (prefix == this.completions.filterText)
1166
+ return;
1167
+ this.completions.setFilter(prefix);
1168
+ if (!this.completions.filtered.length)
1169
+ return this.detach();
1170
+ this.openPopup(this.editor, prefix, keepPopupPosition);
1171
+ return;
1172
+ }
1173
+ this.gatherCompletions(this.editor, function(err, results) {
1174
+ var matches = results && results.matches;
1175
+ if (!matches || !matches.length)
1176
+ return this.detach();
1177
+
1178
+ this.completions = new FilteredList(matches);
1179
+ this.completions.setFilter(results.prefix);
1180
+ var filtered = this.completions.filtered;
1181
+ if (!filtered.length)
1182
+ return this.detach();
1183
+ if (this.autoInsert && filtered.length == 1)
1184
+ return this.insertMatch(filtered[0]);
1185
+ this.openPopup(this.editor, results.prefix, keepPopupPosition);
1186
+ }.bind(this));
1187
+ };
1188
+
1189
+ this.cancelContextMenu = function() {
1190
+ var stop = function(e) {
1191
+ this.editor.off("nativecontextmenu", stop);
1192
+ if (e && e.domEvent)
1193
+ event.stopEvent(e.domEvent);
1194
+ }.bind(this);
1195
+ setTimeout(stop, 10);
1196
+ this.editor.on("nativecontextmenu", stop);
1197
+ };
1198
+
1199
+ }).call(Autocomplete.prototype);
1200
+
1201
+ Autocomplete.startCommand = {
1202
+ name: "startAutocomplete",
1203
+ exec: function(editor) {
1204
+ if (!editor.completer)
1205
+ editor.completer = new Autocomplete();
1206
+ editor.completer.showPopup(editor);
1207
+ editor.completer.cancelContextMenu();
1208
+ },
1209
+ bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
1210
+ };
1211
+
1212
+ var FilteredList = function(array, filterText, mutateData) {
1213
+ this.all = array;
1214
+ this.filtered = array;
1215
+ this.filterText = filterText || "";
1216
+ };
1217
+ (function(){
1218
+ this.setFilter = function(str) {
1219
+ if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0)
1220
+ var matches = this.filtered;
1221
+ else
1222
+ var matches = this.all;
1223
+
1224
+ this.filterText = str;
1225
+ matches = this.filterCompletions(matches, this.filterText);
1226
+ matches = matches.sort(function(a, b) {
1227
+ return b.exactMatch - a.exactMatch || b.score - a.score;
1228
+ });
1229
+ var prev = null;
1230
+ matches = matches.filter(function(item){
1231
+ var caption = item.value || item.caption || item.snippet;
1232
+ if (caption === prev) return false;
1233
+ prev = caption;
1234
+ return true;
1235
+ });
1236
+
1237
+ this.filtered = matches;
1238
+ };
1239
+ this.filterCompletions = function(items, needle) {
1240
+ var results = [];
1241
+ var upper = needle.toUpperCase();
1242
+ var lower = needle.toLowerCase();
1243
+ loop: for (var i = 0, item; item = items[i]; i++) {
1244
+ var caption = item.value || item.caption || item.snippet;
1245
+ if (!caption) continue;
1246
+ var lastIndex = -1;
1247
+ var matchMask = 0;
1248
+ var penalty = 0;
1249
+ var index, distance;
1250
+ for (var j = 0; j < needle.length; j++) {
1251
+ var i1 = caption.indexOf(lower[j], lastIndex + 1);
1252
+ var i2 = caption.indexOf(upper[j], lastIndex + 1);
1253
+ index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
1254
+ if (index < 0)
1255
+ continue loop;
1256
+ distance = index - lastIndex - 1;
1257
+ if (distance > 0) {
1258
+ if (lastIndex === -1)
1259
+ penalty += 10;
1260
+ penalty += distance;
1261
+ }
1262
+ matchMask = matchMask | (1 << index);
1263
+ lastIndex = index;
1264
+ }
1265
+ item.matchMask = matchMask;
1266
+ item.exactMatch = penalty ? 0 : 1;
1267
+ item.score = (item.score || 0) - penalty;
1268
+ results.push(item);
1269
+ }
1270
+ return results;
1271
+ };
1272
+ }).call(FilteredList.prototype);
1273
+
1274
+ exports.Autocomplete = Autocomplete;
1275
+ exports.FilteredList = FilteredList;
1276
+
1277
+ });
1278
+
1279
+ 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) {
1280
+
1281
+
1282
+ var EditSession = require("../edit_session").EditSession;
1283
+ var Renderer = require("../virtual_renderer").VirtualRenderer;
1284
+ var Editor = require("../editor").Editor;
1285
+ var Range = require("../range").Range;
1286
+ var event = require("../lib/event");
1287
+ var lang = require("../lib/lang");
1288
+ var dom = require("../lib/dom");
1289
+
1290
+ var $singleLineEditor = function(el) {
1291
+ var renderer = new Renderer(el);
1292
+
1293
+ renderer.$maxLines = 4;
1294
+
1295
+ var editor = new Editor(renderer);
1296
+
1297
+ editor.setHighlightActiveLine(false);
1298
+ editor.setShowPrintMargin(false);
1299
+ editor.renderer.setShowGutter(false);
1300
+ editor.renderer.setHighlightGutterLine(false);
1301
+
1302
+ editor.$mouseHandler.$focusWaitTimout = 0;
1303
+
1304
+ return editor;
1305
+ };
1306
+
1307
+ var AcePopup = function(parentNode) {
1308
+ var el = dom.createElement("div");
1309
+ var popup = new $singleLineEditor(el);
1310
+
1311
+ if (parentNode)
1312
+ parentNode.appendChild(el);
1313
+ el.style.display = "none";
1314
+ popup.renderer.content.style.cursor = "default";
1315
+ popup.renderer.setStyle("ace_autocomplete");
1316
+
1317
+ popup.setOption("displayIndentGuides", false);
1318
+
1319
+ var noop = function(){};
1320
+
1321
+ popup.focus = noop;
1322
+ popup.$isFocused = true;
1323
+
1324
+ popup.renderer.$cursorLayer.restartTimer = noop;
1325
+ popup.renderer.$cursorLayer.element.style.opacity = 0;
1326
+
1327
+ popup.renderer.$maxLines = 8;
1328
+ popup.renderer.$keepTextAreaAtCursor = false;
1329
+
1330
+ popup.setHighlightActiveLine(false);
1331
+ popup.session.highlight("");
1332
+ popup.session.$searchHighlight.clazz = "ace_highlight-marker";
1333
+
1334
+ popup.on("mousedown", function(e) {
1335
+ var pos = e.getDocumentPosition();
1336
+ popup.moveCursorToPosition(pos);
1337
+ popup.selection.clearSelection();
1338
+ selectionMarker.start.row = selectionMarker.end.row = pos.row;
1339
+ e.stop();
1340
+ });
1341
+
1342
+ var lastMouseEvent;
1343
+ var hoverMarker = new Range(-1,0,-1,Infinity);
1344
+ var selectionMarker = new Range(-1,0,-1,Infinity);
1345
+ selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine");
1346
+ popup.setSelectOnHover = function(val) {
1347
+ if (!val) {
1348
+ hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
1349
+ } else if (hoverMarker.id) {
1350
+ popup.session.removeMarker(hoverMarker.id);
1351
+ hoverMarker.id = null;
1352
+ }
1353
+ }
1354
+ popup.setSelectOnHover(false);
1355
+ popup.on("mousemove", function(e) {
1356
+ if (!lastMouseEvent) {
1357
+ lastMouseEvent = e;
1358
+ return;
1359
+ }
1360
+ if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) {
1361
+ return;
1362
+ }
1363
+ lastMouseEvent = e;
1364
+ lastMouseEvent.scrollTop = popup.renderer.scrollTop;
1365
+ var row = lastMouseEvent.getDocumentPosition().row;
1366
+ if (hoverMarker.start.row != row) {
1367
+ if (!hoverMarker.id)
1368
+ popup.setRow(row);
1369
+ setHoverMarker(row);
1370
+ }
1371
+ });
1372
+ popup.renderer.on("beforeRender", function() {
1373
+ if (lastMouseEvent && hoverMarker.start.row != -1) {
1374
+ lastMouseEvent.$pos = null;
1375
+ var row = lastMouseEvent.getDocumentPosition().row;
1376
+ if (!hoverMarker.id)
1377
+ popup.setRow(row);
1378
+ setHoverMarker(row, true);
1379
+ }
1380
+ });
1381
+ popup.renderer.on("afterRender", function() {
1382
+ var row = popup.getRow();
1383
+ var t = popup.renderer.$textLayer;
1384
+ var selected = t.element.childNodes[row - t.config.firstRow];
1385
+ if (selected == t.selectedNode)
1386
+ return;
1387
+ if (t.selectedNode)
1388
+ dom.removeCssClass(t.selectedNode, "ace_selected");
1389
+ t.selectedNode = selected;
1390
+ if (selected)
1391
+ dom.addCssClass(selected, "ace_selected");
1392
+ });
1393
+ var hideHoverMarker = function() { setHoverMarker(-1) };
1394
+ var setHoverMarker = function(row, suppressRedraw) {
1395
+ if (row !== hoverMarker.start.row) {
1396
+ hoverMarker.start.row = hoverMarker.end.row = row;
1397
+ if (!suppressRedraw)
1398
+ popup.session._emit("changeBackMarker");
1399
+ popup._emit("changeHoverMarker");
1400
+ }
1401
+ };
1402
+ popup.getHoveredRow = function() {
1403
+ return hoverMarker.start.row;
1404
+ };
1405
+
1406
+ event.addListener(popup.container, "mouseout", hideHoverMarker);
1407
+ popup.on("hide", hideHoverMarker);
1408
+ popup.on("changeSelection", hideHoverMarker);
1409
+
1410
+ popup.session.doc.getLength = function() {
1411
+ return popup.data.length;
1412
+ };
1413
+ popup.session.doc.getLine = function(i) {
1414
+ var data = popup.data[i];
1415
+ if (typeof data == "string")
1416
+ return data;
1417
+ return (data && data.value) || "";
1418
+ };
1419
+
1420
+ var bgTokenizer = popup.session.bgTokenizer;
1421
+ bgTokenizer.$tokenizeRow = function(i) {
1422
+ var data = popup.data[i];
1423
+ var tokens = [];
1424
+ if (!data)
1425
+ return tokens;
1426
+ if (typeof data == "string")
1427
+ data = {value: data};
1428
+ if (!data.caption)
1429
+ data.caption = data.value;
1430
+
1431
+ var last = -1;
1432
+ var flag, c;
1433
+ for (var i = 0; i < data.caption.length; i++) {
1434
+ c = data.caption[i];
1435
+ flag = data.matchMask & (1 << i) ? 1 : 0;
1436
+ if (last !== flag) {
1437
+ tokens.push({type: data.className || "" + ( flag ? "completion-highlight" : ""), value: c});
1438
+ last = flag;
1439
+ } else {
1440
+ tokens[tokens.length - 1].value += c;
1441
+ }
1442
+ }
1443
+
1444
+ if (data.meta) {
1445
+ var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth;
1446
+ if (data.meta.length + data.caption.length < maxW - 2)
1447
+ tokens.push({type: "rightAlignedText", value: data.meta});
1448
+ }
1449
+ return tokens;
1450
+ };
1451
+ bgTokenizer.$updateOnChange = noop;
1452
+ bgTokenizer.start = noop;
1453
+
1454
+ popup.session.$computeWidth = function() {
1455
+ return this.screenWidth = 0;
1456
+ }
1457
+ popup.isOpen = false;
1458
+ popup.isTopdown = false;
1459
+
1460
+ popup.data = [];
1461
+ popup.setData = function(list) {
1462
+ popup.data = list || [];
1463
+ popup.setValue(lang.stringRepeat("\n", list.length), -1);
1464
+ popup.setRow(0);
1465
+ };
1466
+ popup.getData = function(row) {
1467
+ return popup.data[row];
1468
+ };
1469
+
1470
+ popup.getRow = function() {
1471
+ return selectionMarker.start.row;
1472
+ };
1473
+ popup.setRow = function(line) {
1474
+ line = Math.max(-1, Math.min(this.data.length, line));
1475
+ if (selectionMarker.start.row != line) {
1476
+ popup.selection.clearSelection();
1477
+ selectionMarker.start.row = selectionMarker.end.row = line || 0;
1478
+ popup.session._emit("changeBackMarker");
1479
+ popup.moveCursorTo(line || 0, 0);
1480
+ if (popup.isOpen)
1481
+ popup._signal("select");
1482
+ }
1483
+ };
1484
+
1485
+ popup.on("changeSelection", function() {
1486
+ if (popup.isOpen)
1487
+ popup.setRow(popup.selection.lead.row);
1488
+ });
1489
+
1490
+ popup.hide = function() {
1491
+ this.container.style.display = "none";
1492
+ this._signal("hide");
1493
+ popup.isOpen = false;
1494
+ };
1495
+ popup.show = function(pos, lineHeight, topdownOnly) {
1496
+ var el = this.container;
1497
+ var screenHeight = window.innerHeight;
1498
+ var screenWidth = window.innerWidth;
1499
+ var renderer = this.renderer;
1500
+ var maxH = renderer.$maxLines * lineHeight * 1.4;
1501
+ var top = pos.top + this.$borderSize;
1502
+ if (top + maxH > screenHeight - lineHeight && !topdownOnly) {
1503
+ el.style.top = "";
1504
+ el.style.bottom = screenHeight - top + "px";
1505
+ popup.isTopdown = false;
1506
+ } else {
1507
+ top += lineHeight;
1508
+ el.style.top = top + "px";
1509
+ el.style.bottom = "";
1510
+ popup.isTopdown = true;
1511
+ }
1512
+
1513
+ el.style.display = "";
1514
+ this.renderer.$textLayer.checkForSizeChanges();
1515
+
1516
+ var left = pos.left;
1517
+ if (left + el.offsetWidth > screenWidth)
1518
+ left = screenWidth - el.offsetWidth;
1519
+
1520
+ el.style.left = left + "px";
1521
+
1522
+ this._signal("show");
1523
+ lastMouseEvent = null;
1524
+ popup.isOpen = true;
1525
+ };
1526
+
1527
+ popup.getTextLeftOffset = function() {
1528
+ return this.$borderSize + this.renderer.$padding + this.$imageSize;
1529
+ };
1530
+
1531
+ popup.$imageSize = 0;
1532
+ popup.$borderSize = 1;
1533
+
1534
+ return popup;
1535
+ };
1536
+
1537
+ dom.importCssString("\
1538
+ .ace_autocomplete.ace-tm .ace_marker-layer .ace_active-line {\
1539
+ background-color: #CAD6FA;\
1540
+ z-index: 1;\
1541
+ }\
1542
+ .ace_autocomplete.ace-tm .ace_line-hover {\
1543
+ border: 1px solid #abbffe;\
1544
+ margin-top: -1px;\
1545
+ background: rgba(233,233,253,0.4);\
1546
+ }\
1547
+ .ace_autocomplete .ace_line-hover {\
1548
+ position: absolute;\
1549
+ z-index: 2;\
1550
+ }\
1551
+ .ace_rightAlignedText {\
1552
+ color: gray;\
1553
+ display: inline-block;\
1554
+ position: absolute;\
1555
+ right: 4px;\
1556
+ text-align: right;\
1557
+ z-index: -1;\
1558
+ }\
1559
+ .ace_autocomplete .ace_completion-highlight{\
1560
+ color: #000;\
1561
+ text-shadow: 0 0 0.01em;\
1562
+ }\
1563
+ .ace_autocomplete {\
1564
+ width: 280px;\
1565
+ z-index: 200000;\
1566
+ background: #fbfbfb;\
1567
+ color: #444;\
1568
+ border: 1px lightgray solid;\
1569
+ position: fixed;\
1570
+ box-shadow: 2px 3px 5px rgba(0,0,0,.2);\
1571
+ line-height: 1.4;\
1572
+ }");
1573
+
1574
+ exports.AcePopup = AcePopup;
1575
+
1576
+ });
1577
+
1578
+ define('ace/autocomplete/util', ['require', 'exports', 'module' ], function(require, exports, module) {
1579
+
1580
+
1581
+ exports.parForEach = function(array, fn, callback) {
1582
+ var completed = 0;
1583
+ var arLength = array.length;
1584
+ if (arLength === 0)
1585
+ callback();
1586
+ for (var i = 0; i < arLength; i++) {
1587
+ fn(array[i], function(result, err) {
1588
+ completed++;
1589
+ if (completed === arLength)
1590
+ callback(result, err);
1591
+ });
1592
+ }
1593
+ }
1594
+
1595
+ var ID_REGEX = /[a-zA-Z_0-9\$-]/;
1596
+
1597
+ exports.retrievePrecedingIdentifier = function(text, pos, regex) {
1598
+ regex = regex || ID_REGEX;
1599
+ var buf = [];
1600
+ for (var i = pos-1; i >= 0; i--) {
1601
+ if (regex.test(text[i]))
1602
+ buf.push(text[i]);
1603
+ else
1604
+ break;
1605
+ }
1606
+ return buf.reverse().join("");
1607
+ }
1608
+
1609
+ exports.retrieveFollowingIdentifier = function(text, pos, regex) {
1610
+ regex = regex || ID_REGEX;
1611
+ var buf = [];
1612
+ for (var i = pos; i < text.length; i++) {
1613
+ if (regex.test(text[i]))
1614
+ buf.push(text[i]);
1615
+ else
1616
+ break;
1617
+ }
1618
+ return buf;
1619
+ }
1620
+
1621
+ });
1622
+
1623
+ define('ace/autocomplete/text_completer', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
1624
+ var Range = require("ace/range").Range;
1625
+
1626
+ var splitRegex = /[^a-zA-Z_0-9\$\-]+/;
1627
+
1628
+ function getWordIndex(doc, pos) {
1629
+ var textBefore = doc.getTextRange(Range.fromPoints({row: 0, column:0}, pos));
1630
+ return textBefore.split(splitRegex).length - 1;
1631
+ }
1632
+ function wordDistance(doc, pos) {
1633
+ var prefixPos = getWordIndex(doc, pos);
1634
+ var words = doc.getValue().split(splitRegex);
1635
+ var wordScores = Object.create(null);
1636
+
1637
+ var currentWord = words[prefixPos];
1638
+
1639
+ words.forEach(function(word, idx) {
1640
+ if (!word || word === currentWord) return;
1641
+
1642
+ var distance = Math.abs(prefixPos - idx);
1643
+ var score = words.length - distance;
1644
+ if (wordScores[word]) {
1645
+ wordScores[word] = Math.max(score, wordScores[word]);
1646
+ } else {
1647
+ wordScores[word] = score;
1648
+ }
1649
+ });
1650
+ return wordScores;
1651
+ }
1652
+
1653
+ exports.getCompletions = function(editor, session, pos, prefix, callback) {
1654
+ var wordScore = wordDistance(session, pos, prefix);
1655
+ var wordList = Object.keys(wordScore);
1656
+ callback(null, wordList.map(function(word) {
1657
+ return {
1658
+ name: word,
1659
+ value: word,
1660
+ score: wordScore[word],
1661
+ meta: "local"
1662
+ };
1663
+ }));
1664
+ };
1665
+ });