ace-rails-ap 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ace/rails/version.rb +1 -1
- data/vendor/assets/javascripts/ace/ace.js +210 -161
- data/vendor/assets/javascripts/ace/ext-beautify.js +0 -1
- data/vendor/assets/javascripts/ace/ext-chromevox.js +0 -1
- data/vendor/assets/javascripts/ace/ext-elastic_tabstops_lite.js +0 -1
- data/vendor/assets/javascripts/ace/ext-emmet.js +66 -48
- data/vendor/assets/javascripts/ace/ext-keybinding_menu.js +9 -19
- data/vendor/assets/javascripts/ace/ext-language_tools.js +108 -10
- data/vendor/assets/javascripts/ace/ext-linking.js +0 -1
- data/vendor/assets/javascripts/ace/ext-modelist.js +4 -1
- data/vendor/assets/javascripts/ace/ext-old_ie.js +23 -2
- data/vendor/assets/javascripts/ace/ext-searchbox.js +23 -2
- data/vendor/assets/javascripts/ace/ext-settings_menu.js +10 -1
- data/vendor/assets/javascripts/ace/ext-spellcheck.js +0 -1
- data/vendor/assets/javascripts/ace/ext-split.js +0 -1
- data/vendor/assets/javascripts/ace/ext-static_highlight.js +0 -1
- data/vendor/assets/javascripts/ace/ext-statusbar.js +2 -4
- data/vendor/assets/javascripts/ace/ext-textarea.js +0 -1
- data/vendor/assets/javascripts/ace/ext-themelist.js +0 -1
- data/vendor/assets/javascripts/ace/ext-whitespace.js +0 -1
- data/vendor/assets/javascripts/ace/keybinding-emacs.js +159 -50
- data/vendor/assets/javascripts/ace/mode-autohotkey.js +1 -1
- data/vendor/assets/javascripts/ace/mode-c_cpp.js +32 -14
- data/vendor/assets/javascripts/ace/mode-coffee.js +1 -1
- data/vendor/assets/javascripts/ace/mode-coldfusion.js +62 -24
- data/vendor/assets/javascripts/ace/mode-csharp.js +14 -8
- data/vendor/assets/javascripts/ace/mode-css.js +2 -2
- data/vendor/assets/javascripts/ace/mode-curly.js +62 -24
- data/vendor/assets/javascripts/ace/mode-d.js +13 -7
- data/vendor/assets/javascripts/ace/mode-dart.js +32 -14
- data/vendor/assets/javascripts/ace/mode-django.js +62 -24
- data/vendor/assets/javascripts/ace/mode-dockerfile.js +3 -3
- data/vendor/assets/javascripts/ace/mode-dot.js +12 -6
- data/vendor/assets/javascripts/ace/mode-ejs.js +126 -27
- data/vendor/assets/javascripts/ace/mode-elixir.js +493 -0
- data/vendor/assets/javascripts/ace/mode-elm.js +248 -0
- data/vendor/assets/javascripts/ace/mode-forth.js +1 -1
- data/vendor/assets/javascripts/ace/mode-ftl.js +20 -10
- data/vendor/assets/javascripts/ace/mode-gitignore.js +1 -0
- data/vendor/assets/javascripts/ace/mode-glsl.js +32 -14
- data/vendor/assets/javascripts/ace/mode-golang.js +14 -8
- data/vendor/assets/javascripts/ace/mode-groovy.js +22 -12
- data/vendor/assets/javascripts/ace/mode-haml.js +64 -3
- data/vendor/assets/javascripts/ace/mode-handlebars.js +72 -34
- data/vendor/assets/javascripts/ace/mode-haxe.js +14 -8
- data/vendor/assets/javascripts/ace/mode-html.js +62 -24
- data/vendor/assets/javascripts/ace/mode-html_ruby.js +126 -27
- data/vendor/assets/javascripts/ace/mode-jack.js +2 -2
- data/vendor/assets/javascripts/ace/mode-jade.js +21 -11
- data/vendor/assets/javascripts/ace/mode-java.js +22 -12
- data/vendor/assets/javascripts/ace/mode-javascript.js +22 -12
- data/vendor/assets/javascripts/ace/mode-json.js +2 -2
- data/vendor/assets/javascripts/ace/mode-jsoniq.js +47 -1835
- data/vendor/assets/javascripts/ace/mode-jsp.js +22 -12
- data/vendor/assets/javascripts/ace/mode-jsx.js +14 -8
- data/vendor/assets/javascripts/ace/mode-less.js +2 -2
- data/vendor/assets/javascripts/ace/mode-liquid.js +20 -10
- data/vendor/assets/javascripts/ace/mode-logiql.js +2 -2
- data/vendor/assets/javascripts/ace/mode-lsl.js +2 -2
- data/vendor/assets/javascripts/ace/mode-luapage.js +62 -24
- data/vendor/assets/javascripts/ace/mode-markdown.js +62 -24
- data/vendor/assets/javascripts/ace/mode-mel.js +2 -2
- data/vendor/assets/javascripts/ace/mode-mysql.js +12 -6
- data/vendor/assets/javascripts/ace/mode-nix.js +32 -14
- data/vendor/assets/javascripts/ace/mode-objectivec.js +30 -12
- data/vendor/assets/javascripts/ace/mode-pgsql.js +20 -10
- data/vendor/assets/javascripts/ace/mode-php.js +1126 -40
- data/vendor/assets/javascripts/ace/mode-powershell.js +2 -2
- data/vendor/assets/javascripts/ace/mode-protobuf.js +32 -14
- data/vendor/assets/javascripts/ace/mode-rhtml.js +62 -24
- data/vendor/assets/javascripts/ace/mode-ruby.js +66 -5
- data/vendor/assets/javascripts/ace/mode-rust.js +36 -3
- data/vendor/assets/javascripts/ace/mode-scad.js +14 -8
- data/vendor/assets/javascripts/ace/mode-scala.js +22 -12
- data/vendor/assets/javascripts/ace/mode-scss.js +2 -2
- data/vendor/assets/javascripts/ace/mode-sh.js +2 -2
- data/vendor/assets/javascripts/ace/mode-sjs.js +22 -12
- data/vendor/assets/javascripts/ace/mode-smarty.js +62 -24
- data/vendor/assets/javascripts/ace/mode-soy_template.js +63 -25
- data/vendor/assets/javascripts/ace/mode-stylus.js +4 -1
- data/vendor/assets/javascripts/ace/mode-svg.js +62 -24
- data/vendor/assets/javascripts/ace/mode-textile.js +1 -0
- data/vendor/assets/javascripts/ace/mode-twig.js +62 -24
- data/vendor/assets/javascripts/ace/mode-typescript.js +22 -12
- data/vendor/assets/javascripts/ace/mode-vala.js +2 -2
- data/vendor/assets/javascripts/ace/mode-velocity.js +62 -24
- data/vendor/assets/javascripts/ace/mode-xml.js +40 -12
- data/vendor/assets/javascripts/ace/mode-xquery.js +47 -1835
- data/vendor/assets/javascripts/ace/theme-cobalt.js +1 -1
- data/vendor/assets/javascripts/ace/theme-idle_fingers.js +1 -1
- data/vendor/assets/javascripts/ace/theme-tomorrow_night_bright.js +2 -2
- data/vendor/assets/javascripts/ace/worker-coffee.js +15 -5
- data/vendor/assets/javascripts/ace/worker-css.js +15 -5
- data/vendor/assets/javascripts/ace/worker-html.js +15 -5
- data/vendor/assets/javascripts/ace/worker-javascript.js +15 -5
- data/vendor/assets/javascripts/ace/worker-json.js +17 -6
- data/vendor/assets/javascripts/ace/worker-lua.js +15 -5
- data/vendor/assets/javascripts/ace/worker-php.js +15 -5
- data/vendor/assets/javascripts/ace/worker-xquery.js +15 -5
- metadata +4 -2
@@ -208,12 +208,13 @@ oop.inherits(XmlHighlightRules, TextHighlightRules);
|
|
208
208
|
exports.XmlHighlightRules = XmlHighlightRules;
|
209
209
|
});
|
210
210
|
|
211
|
-
define("ace/mode/behaviour/xml",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator"], function(require, exports, module) {
|
211
|
+
define("ace/mode/behaviour/xml",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
|
212
212
|
"use strict";
|
213
213
|
|
214
214
|
var oop = require("../../lib/oop");
|
215
215
|
var Behaviour = require("../behaviour").Behaviour;
|
216
216
|
var TokenIterator = require("../../token_iterator").TokenIterator;
|
217
|
+
var lang = require("../../lib/lang");
|
217
218
|
|
218
219
|
function is(token, type) {
|
219
220
|
return token.type.lastIndexOf(type + ".xml") > -1;
|
@@ -311,29 +312,56 @@ var XmlBehaviour = function () {
|
|
311
312
|
return;
|
312
313
|
|
313
314
|
return {
|
314
|
-
text:
|
315
|
+
text: ">" + "</" + element + ">",
|
315
316
|
selection: [1, 1]
|
316
317
|
};
|
317
318
|
}
|
318
319
|
});
|
319
320
|
|
320
|
-
this.add(
|
321
|
+
this.add("autoindent", "insertion", function (state, action, editor, session, text) {
|
321
322
|
if (text == "\n") {
|
322
323
|
var cursor = editor.getCursorPosition();
|
323
324
|
var line = session.getLine(cursor.row);
|
324
|
-
var
|
325
|
-
|
326
|
-
var next_indent = this.$getIndent(line);
|
327
|
-
var indent = next_indent + session.getTabString();
|
325
|
+
var iterator = new TokenIterator(session, cursor.row, cursor.column);
|
326
|
+
var token = iterator.getCurrentToken();
|
328
327
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
}
|
328
|
+
if (token && token.type.indexOf("tag-close") !== -1) {
|
329
|
+
while (token && token.type.indexOf("tag-name") === -1) {
|
330
|
+
token = iterator.stepBackward();
|
331
|
+
}
|
332
|
+
|
333
|
+
if (!token) {
|
334
|
+
return;
|
335
|
+
}
|
336
|
+
|
337
|
+
var tag = token.value;
|
338
|
+
var row = iterator.getCurrentTokenRow();
|
339
|
+
token = iterator.stepBackward();
|
340
|
+
if (!token || token.type.indexOf("end-tag") !== -1) {
|
341
|
+
return;
|
342
|
+
}
|
343
|
+
|
344
|
+
if (this.voidElements && !this.voidElements[tag]) {
|
345
|
+
var nextToken = session.getTokenAt(cursor.row, cursor.column+1);
|
346
|
+
var line = session.getLine(row);
|
347
|
+
var nextIndent = this.$getIndent(line);
|
348
|
+
var indent = nextIndent + session.getTabString();
|
349
|
+
|
350
|
+
if (nextToken && nextToken.value === "</") {
|
351
|
+
return {
|
352
|
+
text: "\n" + indent + "\n" + nextIndent,
|
353
|
+
selection: [1, indent.length, 1, indent.length]
|
354
|
+
};
|
355
|
+
} else {
|
356
|
+
return {
|
357
|
+
text: "\n" + indent
|
358
|
+
};
|
359
|
+
}
|
360
|
+
}
|
333
361
|
}
|
334
362
|
}
|
335
363
|
});
|
336
|
-
|
364
|
+
|
337
365
|
};
|
338
366
|
|
339
367
|
oop.inherits(XmlBehaviour, Behaviour);
|
@@ -2082,11 +2082,11 @@ var SAFE_INSERT_BEFORE_TOKENS =
|
|
2082
2082
|
["text", "paren.rparen", "punctuation.operator", "comment"];
|
2083
2083
|
|
2084
2084
|
var context;
|
2085
|
-
var contextCache = {}
|
2085
|
+
var contextCache = {};
|
2086
2086
|
var initContext = function(editor) {
|
2087
2087
|
var id = -1;
|
2088
2088
|
if (editor.multiSelect) {
|
2089
|
-
id = editor.selection.
|
2089
|
+
id = editor.selection.index;
|
2090
2090
|
if (contextCache.rangeCount != editor.multiSelect.rangeCount)
|
2091
2091
|
contextCache = {rangeCount: editor.multiSelect.rangeCount};
|
2092
2092
|
}
|
@@ -2426,12 +2426,13 @@ oop.inherits(CstyleBehaviour, Behaviour);
|
|
2426
2426
|
exports.CstyleBehaviour = CstyleBehaviour;
|
2427
2427
|
});
|
2428
2428
|
|
2429
|
-
define("ace/mode/behaviour/xml",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator"], function(require, exports, module) {
|
2429
|
+
define("ace/mode/behaviour/xml",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
|
2430
2430
|
"use strict";
|
2431
2431
|
|
2432
2432
|
var oop = require("../../lib/oop");
|
2433
2433
|
var Behaviour = require("../behaviour").Behaviour;
|
2434
2434
|
var TokenIterator = require("../../token_iterator").TokenIterator;
|
2435
|
+
var lang = require("../../lib/lang");
|
2435
2436
|
|
2436
2437
|
function is(token, type) {
|
2437
2438
|
return token.type.lastIndexOf(type + ".xml") > -1;
|
@@ -2529,29 +2530,56 @@ var XmlBehaviour = function () {
|
|
2529
2530
|
return;
|
2530
2531
|
|
2531
2532
|
return {
|
2532
|
-
text:
|
2533
|
+
text: ">" + "</" + element + ">",
|
2533
2534
|
selection: [1, 1]
|
2534
2535
|
};
|
2535
2536
|
}
|
2536
2537
|
});
|
2537
2538
|
|
2538
|
-
this.add(
|
2539
|
+
this.add("autoindent", "insertion", function (state, action, editor, session, text) {
|
2539
2540
|
if (text == "\n") {
|
2540
2541
|
var cursor = editor.getCursorPosition();
|
2541
2542
|
var line = session.getLine(cursor.row);
|
2542
|
-
var
|
2543
|
-
|
2544
|
-
var next_indent = this.$getIndent(line);
|
2545
|
-
var indent = next_indent + session.getTabString();
|
2543
|
+
var iterator = new TokenIterator(session, cursor.row, cursor.column);
|
2544
|
+
var token = iterator.getCurrentToken();
|
2546
2545
|
|
2547
|
-
|
2548
|
-
|
2549
|
-
|
2550
|
-
}
|
2546
|
+
if (token && token.type.indexOf("tag-close") !== -1) {
|
2547
|
+
while (token && token.type.indexOf("tag-name") === -1) {
|
2548
|
+
token = iterator.stepBackward();
|
2549
|
+
}
|
2550
|
+
|
2551
|
+
if (!token) {
|
2552
|
+
return;
|
2553
|
+
}
|
2554
|
+
|
2555
|
+
var tag = token.value;
|
2556
|
+
var row = iterator.getCurrentTokenRow();
|
2557
|
+
token = iterator.stepBackward();
|
2558
|
+
if (!token || token.type.indexOf("end-tag") !== -1) {
|
2559
|
+
return;
|
2560
|
+
}
|
2561
|
+
|
2562
|
+
if (this.voidElements && !this.voidElements[tag]) {
|
2563
|
+
var nextToken = session.getTokenAt(cursor.row, cursor.column+1);
|
2564
|
+
var line = session.getLine(row);
|
2565
|
+
var nextIndent = this.$getIndent(line);
|
2566
|
+
var indent = nextIndent + session.getTabString();
|
2567
|
+
|
2568
|
+
if (nextToken && nextToken.value === "</") {
|
2569
|
+
return {
|
2570
|
+
text: "\n" + indent + "\n" + nextIndent,
|
2571
|
+
selection: [1, indent.length, 1, indent.length]
|
2572
|
+
};
|
2573
|
+
} else {
|
2574
|
+
return {
|
2575
|
+
text: "\n" + indent
|
2576
|
+
};
|
2577
|
+
}
|
2578
|
+
}
|
2551
2579
|
}
|
2552
2580
|
}
|
2553
2581
|
});
|
2554
|
-
|
2582
|
+
|
2555
2583
|
};
|
2556
2584
|
|
2557
2585
|
oop.inherits(XmlBehaviour, Behaviour);
|
@@ -2718,1824 +2746,7 @@ oop.inherits(FoldMode, BaseFoldMode);
|
|
2718
2746
|
|
2719
2747
|
});
|
2720
2748
|
|
2721
|
-
define("ace/
|
2722
|
-
"use strict";
|
2723
|
-
var oop = require("./lib/oop");
|
2724
|
-
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
2725
|
-
var lang = require("./lib/lang");
|
2726
|
-
var Range = require("./range").Range;
|
2727
|
-
var Anchor = require("./anchor").Anchor;
|
2728
|
-
var HashHandler = require("./keyboard/hash_handler").HashHandler;
|
2729
|
-
var Tokenizer = require("./tokenizer").Tokenizer;
|
2730
|
-
var comparePoints = Range.comparePoints;
|
2731
|
-
|
2732
|
-
var SnippetManager = function() {
|
2733
|
-
this.snippetMap = {};
|
2734
|
-
this.snippetNameMap = {};
|
2735
|
-
};
|
2736
|
-
|
2737
|
-
(function() {
|
2738
|
-
oop.implement(this, EventEmitter);
|
2739
|
-
|
2740
|
-
this.getTokenizer = function() {
|
2741
|
-
function TabstopToken(str, _, stack) {
|
2742
|
-
str = str.substr(1);
|
2743
|
-
if (/^\d+$/.test(str) && !stack.inFormatString)
|
2744
|
-
return [{tabstopId: parseInt(str, 10)}];
|
2745
|
-
return [{text: str}];
|
2746
|
-
}
|
2747
|
-
function escape(ch) {
|
2748
|
-
return "(?:[^\\\\" + ch + "]|\\\\.)";
|
2749
|
-
}
|
2750
|
-
SnippetManager.$tokenizer = new Tokenizer({
|
2751
|
-
start: [
|
2752
|
-
{regex: /:/, onMatch: function(val, state, stack) {
|
2753
|
-
if (stack.length && stack[0].expectIf) {
|
2754
|
-
stack[0].expectIf = false;
|
2755
|
-
stack[0].elseBranch = stack[0];
|
2756
|
-
return [stack[0]];
|
2757
|
-
}
|
2758
|
-
return ":";
|
2759
|
-
}},
|
2760
|
-
{regex: /\\./, onMatch: function(val, state, stack) {
|
2761
|
-
var ch = val[1];
|
2762
|
-
if (ch == "}" && stack.length) {
|
2763
|
-
val = ch;
|
2764
|
-
}else if ("`$\\".indexOf(ch) != -1) {
|
2765
|
-
val = ch;
|
2766
|
-
} else if (stack.inFormatString) {
|
2767
|
-
if (ch == "n")
|
2768
|
-
val = "\n";
|
2769
|
-
else if (ch == "t")
|
2770
|
-
val = "\n";
|
2771
|
-
else if ("ulULE".indexOf(ch) != -1) {
|
2772
|
-
val = {changeCase: ch, local: ch > "a"};
|
2773
|
-
}
|
2774
|
-
}
|
2775
|
-
|
2776
|
-
return [val];
|
2777
|
-
}},
|
2778
|
-
{regex: /}/, onMatch: function(val, state, stack) {
|
2779
|
-
return [stack.length ? stack.shift() : val];
|
2780
|
-
}},
|
2781
|
-
{regex: /\$(?:\d+|\w+)/, onMatch: TabstopToken},
|
2782
|
-
{regex: /\$\{[\dA-Z_a-z]+/, onMatch: function(str, state, stack) {
|
2783
|
-
var t = TabstopToken(str.substr(1), state, stack);
|
2784
|
-
stack.unshift(t[0]);
|
2785
|
-
return t;
|
2786
|
-
}, next: "snippetVar"},
|
2787
|
-
{regex: /\n/, token: "newline", merge: false}
|
2788
|
-
],
|
2789
|
-
snippetVar: [
|
2790
|
-
{regex: "\\|" + escape("\\|") + "*\\|", onMatch: function(val, state, stack) {
|
2791
|
-
stack[0].choices = val.slice(1, -1).split(",");
|
2792
|
-
}, next: "start"},
|
2793
|
-
{regex: "/(" + escape("/") + "+)/(?:(" + escape("/") + "*)/)(\\w*):?",
|
2794
|
-
onMatch: function(val, state, stack) {
|
2795
|
-
var ts = stack[0];
|
2796
|
-
ts.fmtString = val;
|
2797
|
-
|
2798
|
-
val = this.splitRegex.exec(val);
|
2799
|
-
ts.guard = val[1];
|
2800
|
-
ts.fmt = val[2];
|
2801
|
-
ts.flag = val[3];
|
2802
|
-
return "";
|
2803
|
-
}, next: "start"},
|
2804
|
-
{regex: "`" + escape("`") + "*`", onMatch: function(val, state, stack) {
|
2805
|
-
stack[0].code = val.splice(1, -1);
|
2806
|
-
return "";
|
2807
|
-
}, next: "start"},
|
2808
|
-
{regex: "\\?", onMatch: function(val, state, stack) {
|
2809
|
-
if (stack[0])
|
2810
|
-
stack[0].expectIf = true;
|
2811
|
-
}, next: "start"},
|
2812
|
-
{regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "start"}
|
2813
|
-
],
|
2814
|
-
formatString: [
|
2815
|
-
{regex: "/(" + escape("/") + "+)/", token: "regex"},
|
2816
|
-
{regex: "", onMatch: function(val, state, stack) {
|
2817
|
-
stack.inFormatString = true;
|
2818
|
-
}, next: "start"}
|
2819
|
-
]
|
2820
|
-
});
|
2821
|
-
SnippetManager.prototype.getTokenizer = function() {
|
2822
|
-
return SnippetManager.$tokenizer;
|
2823
|
-
};
|
2824
|
-
return SnippetManager.$tokenizer;
|
2825
|
-
};
|
2826
|
-
|
2827
|
-
this.tokenizeTmSnippet = function(str, startState) {
|
2828
|
-
return this.getTokenizer().getLineTokens(str, startState).tokens.map(function(x) {
|
2829
|
-
return x.value || x;
|
2830
|
-
});
|
2831
|
-
};
|
2832
|
-
|
2833
|
-
this.$getDefaultValue = function(editor, name) {
|
2834
|
-
if (/^[A-Z]\d+$/.test(name)) {
|
2835
|
-
var i = name.substr(1);
|
2836
|
-
return (this.variables[name[0] + "__"] || {})[i];
|
2837
|
-
}
|
2838
|
-
if (/^\d+$/.test(name)) {
|
2839
|
-
return (this.variables.__ || {})[name];
|
2840
|
-
}
|
2841
|
-
name = name.replace(/^TM_/, "");
|
2842
|
-
|
2843
|
-
if (!editor)
|
2844
|
-
return;
|
2845
|
-
var s = editor.session;
|
2846
|
-
switch(name) {
|
2847
|
-
case "CURRENT_WORD":
|
2848
|
-
var r = s.getWordRange();
|
2849
|
-
case "SELECTION":
|
2850
|
-
case "SELECTED_TEXT":
|
2851
|
-
return s.getTextRange(r);
|
2852
|
-
case "CURRENT_LINE":
|
2853
|
-
return s.getLine(editor.getCursorPosition().row);
|
2854
|
-
case "PREV_LINE": // not possible in textmate
|
2855
|
-
return s.getLine(editor.getCursorPosition().row - 1);
|
2856
|
-
case "LINE_INDEX":
|
2857
|
-
return editor.getCursorPosition().column;
|
2858
|
-
case "LINE_NUMBER":
|
2859
|
-
return editor.getCursorPosition().row + 1;
|
2860
|
-
case "SOFT_TABS":
|
2861
|
-
return s.getUseSoftTabs() ? "YES" : "NO";
|
2862
|
-
case "TAB_SIZE":
|
2863
|
-
return s.getTabSize();
|
2864
|
-
case "FILENAME":
|
2865
|
-
case "FILEPATH":
|
2866
|
-
return "";
|
2867
|
-
case "FULLNAME":
|
2868
|
-
return "Ace";
|
2869
|
-
}
|
2870
|
-
};
|
2871
|
-
this.variables = {};
|
2872
|
-
this.getVariableValue = function(editor, varName) {
|
2873
|
-
if (this.variables.hasOwnProperty(varName))
|
2874
|
-
return this.variables[varName](editor, varName) || "";
|
2875
|
-
return this.$getDefaultValue(editor, varName) || "";
|
2876
|
-
};
|
2877
|
-
this.tmStrFormat = function(str, ch, editor) {
|
2878
|
-
var flag = ch.flag || "";
|
2879
|
-
var re = ch.guard;
|
2880
|
-
re = new RegExp(re, flag.replace(/[^gi]/, ""));
|
2881
|
-
var fmtTokens = this.tokenizeTmSnippet(ch.fmt, "formatString");
|
2882
|
-
var _self = this;
|
2883
|
-
var formatted = str.replace(re, function() {
|
2884
|
-
_self.variables.__ = arguments;
|
2885
|
-
var fmtParts = _self.resolveVariables(fmtTokens, editor);
|
2886
|
-
var gChangeCase = "E";
|
2887
|
-
for (var i = 0; i < fmtParts.length; i++) {
|
2888
|
-
var ch = fmtParts[i];
|
2889
|
-
if (typeof ch == "object") {
|
2890
|
-
fmtParts[i] = "";
|
2891
|
-
if (ch.changeCase && ch.local) {
|
2892
|
-
var next = fmtParts[i + 1];
|
2893
|
-
if (next && typeof next == "string") {
|
2894
|
-
if (ch.changeCase == "u")
|
2895
|
-
fmtParts[i] = next[0].toUpperCase();
|
2896
|
-
else
|
2897
|
-
fmtParts[i] = next[0].toLowerCase();
|
2898
|
-
fmtParts[i + 1] = next.substr(1);
|
2899
|
-
}
|
2900
|
-
} else if (ch.changeCase) {
|
2901
|
-
gChangeCase = ch.changeCase;
|
2902
|
-
}
|
2903
|
-
} else if (gChangeCase == "U") {
|
2904
|
-
fmtParts[i] = ch.toUpperCase();
|
2905
|
-
} else if (gChangeCase == "L") {
|
2906
|
-
fmtParts[i] = ch.toLowerCase();
|
2907
|
-
}
|
2908
|
-
}
|
2909
|
-
return fmtParts.join("");
|
2910
|
-
});
|
2911
|
-
this.variables.__ = null;
|
2912
|
-
return formatted;
|
2913
|
-
};
|
2914
|
-
|
2915
|
-
this.resolveVariables = function(snippet, editor) {
|
2916
|
-
var result = [];
|
2917
|
-
for (var i = 0; i < snippet.length; i++) {
|
2918
|
-
var ch = snippet[i];
|
2919
|
-
if (typeof ch == "string") {
|
2920
|
-
result.push(ch);
|
2921
|
-
} else if (typeof ch != "object") {
|
2922
|
-
continue;
|
2923
|
-
} else if (ch.skip) {
|
2924
|
-
gotoNext(ch);
|
2925
|
-
} else if (ch.processed < i) {
|
2926
|
-
continue;
|
2927
|
-
} else if (ch.text) {
|
2928
|
-
var value = this.getVariableValue(editor, ch.text);
|
2929
|
-
if (value && ch.fmtString)
|
2930
|
-
value = this.tmStrFormat(value, ch);
|
2931
|
-
ch.processed = i;
|
2932
|
-
if (ch.expectIf == null) {
|
2933
|
-
if (value) {
|
2934
|
-
result.push(value);
|
2935
|
-
gotoNext(ch);
|
2936
|
-
}
|
2937
|
-
} else {
|
2938
|
-
if (value) {
|
2939
|
-
ch.skip = ch.elseBranch;
|
2940
|
-
} else
|
2941
|
-
gotoNext(ch);
|
2942
|
-
}
|
2943
|
-
} else if (ch.tabstopId != null) {
|
2944
|
-
result.push(ch);
|
2945
|
-
} else if (ch.changeCase != null) {
|
2946
|
-
result.push(ch);
|
2947
|
-
}
|
2948
|
-
}
|
2949
|
-
function gotoNext(ch) {
|
2950
|
-
var i1 = snippet.indexOf(ch, i + 1);
|
2951
|
-
if (i1 != -1)
|
2952
|
-
i = i1;
|
2953
|
-
}
|
2954
|
-
return result;
|
2955
|
-
};
|
2956
|
-
|
2957
|
-
this.insertSnippetForSelection = function(editor, snippetText) {
|
2958
|
-
var cursor = editor.getCursorPosition();
|
2959
|
-
var line = editor.session.getLine(cursor.row);
|
2960
|
-
var tabString = editor.session.getTabString();
|
2961
|
-
var indentString = line.match(/^\s*/)[0];
|
2962
|
-
|
2963
|
-
if (cursor.column < indentString.length)
|
2964
|
-
indentString = indentString.slice(0, cursor.column);
|
2965
|
-
|
2966
|
-
var tokens = this.tokenizeTmSnippet(snippetText);
|
2967
|
-
tokens = this.resolveVariables(tokens, editor);
|
2968
|
-
tokens = tokens.map(function(x) {
|
2969
|
-
if (x == "\n")
|
2970
|
-
return x + indentString;
|
2971
|
-
if (typeof x == "string")
|
2972
|
-
return x.replace(/\t/g, tabString);
|
2973
|
-
return x;
|
2974
|
-
});
|
2975
|
-
var tabstops = [];
|
2976
|
-
tokens.forEach(function(p, i) {
|
2977
|
-
if (typeof p != "object")
|
2978
|
-
return;
|
2979
|
-
var id = p.tabstopId;
|
2980
|
-
var ts = tabstops[id];
|
2981
|
-
if (!ts) {
|
2982
|
-
ts = tabstops[id] = [];
|
2983
|
-
ts.index = id;
|
2984
|
-
ts.value = "";
|
2985
|
-
}
|
2986
|
-
if (ts.indexOf(p) !== -1)
|
2987
|
-
return;
|
2988
|
-
ts.push(p);
|
2989
|
-
var i1 = tokens.indexOf(p, i + 1);
|
2990
|
-
if (i1 === -1)
|
2991
|
-
return;
|
2992
|
-
|
2993
|
-
var value = tokens.slice(i + 1, i1);
|
2994
|
-
var isNested = value.some(function(t) {return typeof t === "object"});
|
2995
|
-
if (isNested && !ts.value) {
|
2996
|
-
ts.value = value;
|
2997
|
-
} else if (value.length && (!ts.value || typeof ts.value !== "string")) {
|
2998
|
-
ts.value = value.join("");
|
2999
|
-
}
|
3000
|
-
});
|
3001
|
-
tabstops.forEach(function(ts) {ts.length = 0});
|
3002
|
-
var expanding = {};
|
3003
|
-
function copyValue(val) {
|
3004
|
-
var copy = [];
|
3005
|
-
for (var i = 0; i < val.length; i++) {
|
3006
|
-
var p = val[i];
|
3007
|
-
if (typeof p == "object") {
|
3008
|
-
if (expanding[p.tabstopId])
|
3009
|
-
continue;
|
3010
|
-
var j = val.lastIndexOf(p, i - 1);
|
3011
|
-
p = copy[j] || {tabstopId: p.tabstopId};
|
3012
|
-
}
|
3013
|
-
copy[i] = p;
|
3014
|
-
}
|
3015
|
-
return copy;
|
3016
|
-
}
|
3017
|
-
for (var i = 0; i < tokens.length; i++) {
|
3018
|
-
var p = tokens[i];
|
3019
|
-
if (typeof p != "object")
|
3020
|
-
continue;
|
3021
|
-
var id = p.tabstopId;
|
3022
|
-
var i1 = tokens.indexOf(p, i + 1);
|
3023
|
-
if (expanding[id]) {
|
3024
|
-
if (expanding[id] === p)
|
3025
|
-
expanding[id] = null;
|
3026
|
-
continue;
|
3027
|
-
}
|
3028
|
-
|
3029
|
-
var ts = tabstops[id];
|
3030
|
-
var arg = typeof ts.value == "string" ? [ts.value] : copyValue(ts.value);
|
3031
|
-
arg.unshift(i + 1, Math.max(0, i1 - i));
|
3032
|
-
arg.push(p);
|
3033
|
-
expanding[id] = p;
|
3034
|
-
tokens.splice.apply(tokens, arg);
|
3035
|
-
|
3036
|
-
if (ts.indexOf(p) === -1)
|
3037
|
-
ts.push(p);
|
3038
|
-
}
|
3039
|
-
var row = 0, column = 0;
|
3040
|
-
var text = "";
|
3041
|
-
tokens.forEach(function(t) {
|
3042
|
-
if (typeof t === "string") {
|
3043
|
-
if (t[0] === "\n"){
|
3044
|
-
column = t.length - 1;
|
3045
|
-
row ++;
|
3046
|
-
} else
|
3047
|
-
column += t.length;
|
3048
|
-
text += t;
|
3049
|
-
} else {
|
3050
|
-
if (!t.start)
|
3051
|
-
t.start = {row: row, column: column};
|
3052
|
-
else
|
3053
|
-
t.end = {row: row, column: column};
|
3054
|
-
}
|
3055
|
-
});
|
3056
|
-
var range = editor.getSelectionRange();
|
3057
|
-
var end = editor.session.replace(range, text);
|
3058
|
-
|
3059
|
-
var tabstopManager = new TabstopManager(editor);
|
3060
|
-
var selectionId = editor.inVirtualSelectionMode && editor.selection.index;
|
3061
|
-
tabstopManager.addTabstops(tabstops, range.start, end, selectionId);
|
3062
|
-
};
|
3063
|
-
|
3064
|
-
this.insertSnippet = function(editor, snippetText) {
|
3065
|
-
var self = this;
|
3066
|
-
if (editor.inVirtualSelectionMode)
|
3067
|
-
return self.insertSnippetForSelection(editor, snippetText);
|
3068
|
-
|
3069
|
-
editor.forEachSelection(function() {
|
3070
|
-
self.insertSnippetForSelection(editor, snippetText);
|
3071
|
-
}, null, {keepOrder: true});
|
3072
|
-
|
3073
|
-
if (editor.tabstopManager)
|
3074
|
-
editor.tabstopManager.tabNext();
|
3075
|
-
};
|
3076
|
-
|
3077
|
-
this.$getScope = function(editor) {
|
3078
|
-
var scope = editor.session.$mode.$id || "";
|
3079
|
-
scope = scope.split("/").pop();
|
3080
|
-
if (scope === "html" || scope === "php") {
|
3081
|
-
if (scope === "php" && !editor.session.$mode.inlinePhp)
|
3082
|
-
scope = "html";
|
3083
|
-
var c = editor.getCursorPosition();
|
3084
|
-
var state = editor.session.getState(c.row);
|
3085
|
-
if (typeof state === "object") {
|
3086
|
-
state = state[0];
|
3087
|
-
}
|
3088
|
-
if (state.substring) {
|
3089
|
-
if (state.substring(0, 3) == "js-")
|
3090
|
-
scope = "javascript";
|
3091
|
-
else if (state.substring(0, 4) == "css-")
|
3092
|
-
scope = "css";
|
3093
|
-
else if (state.substring(0, 4) == "php-")
|
3094
|
-
scope = "php";
|
3095
|
-
}
|
3096
|
-
}
|
3097
|
-
|
3098
|
-
return scope;
|
3099
|
-
};
|
3100
|
-
|
3101
|
-
this.getActiveScopes = function(editor) {
|
3102
|
-
var scope = this.$getScope(editor);
|
3103
|
-
var scopes = [scope];
|
3104
|
-
var snippetMap = this.snippetMap;
|
3105
|
-
if (snippetMap[scope] && snippetMap[scope].includeScopes) {
|
3106
|
-
scopes.push.apply(scopes, snippetMap[scope].includeScopes);
|
3107
|
-
}
|
3108
|
-
scopes.push("_");
|
3109
|
-
return scopes;
|
3110
|
-
};
|
3111
|
-
|
3112
|
-
this.expandWithTab = function(editor, options) {
|
3113
|
-
var self = this;
|
3114
|
-
var result = editor.forEachSelection(function() {
|
3115
|
-
return self.expandSnippetForSelection(editor, options);
|
3116
|
-
}, null, {keepOrder: true});
|
3117
|
-
if (result && editor.tabstopManager)
|
3118
|
-
editor.tabstopManager.tabNext();
|
3119
|
-
return result;
|
3120
|
-
};
|
3121
|
-
|
3122
|
-
this.expandSnippetForSelection = function(editor, options) {
|
3123
|
-
var cursor = editor.getCursorPosition();
|
3124
|
-
var line = editor.session.getLine(cursor.row);
|
3125
|
-
var before = line.substring(0, cursor.column);
|
3126
|
-
var after = line.substr(cursor.column);
|
3127
|
-
|
3128
|
-
var snippetMap = this.snippetMap;
|
3129
|
-
var snippet;
|
3130
|
-
this.getActiveScopes(editor).some(function(scope) {
|
3131
|
-
var snippets = snippetMap[scope];
|
3132
|
-
if (snippets)
|
3133
|
-
snippet = this.findMatchingSnippet(snippets, before, after);
|
3134
|
-
return !!snippet;
|
3135
|
-
}, this);
|
3136
|
-
if (!snippet)
|
3137
|
-
return false;
|
3138
|
-
if (options && options.dryRun)
|
3139
|
-
return true;
|
3140
|
-
editor.session.doc.removeInLine(cursor.row,
|
3141
|
-
cursor.column - snippet.replaceBefore.length,
|
3142
|
-
cursor.column + snippet.replaceAfter.length
|
3143
|
-
);
|
3144
|
-
|
3145
|
-
this.variables.M__ = snippet.matchBefore;
|
3146
|
-
this.variables.T__ = snippet.matchAfter;
|
3147
|
-
this.insertSnippetForSelection(editor, snippet.content);
|
3148
|
-
|
3149
|
-
this.variables.M__ = this.variables.T__ = null;
|
3150
|
-
return true;
|
3151
|
-
};
|
3152
|
-
|
3153
|
-
this.findMatchingSnippet = function(snippetList, before, after) {
|
3154
|
-
for (var i = snippetList.length; i--;) {
|
3155
|
-
var s = snippetList[i];
|
3156
|
-
if (s.startRe && !s.startRe.test(before))
|
3157
|
-
continue;
|
3158
|
-
if (s.endRe && !s.endRe.test(after))
|
3159
|
-
continue;
|
3160
|
-
if (!s.startRe && !s.endRe)
|
3161
|
-
continue;
|
3162
|
-
|
3163
|
-
s.matchBefore = s.startRe ? s.startRe.exec(before) : [""];
|
3164
|
-
s.matchAfter = s.endRe ? s.endRe.exec(after) : [""];
|
3165
|
-
s.replaceBefore = s.triggerRe ? s.triggerRe.exec(before)[0] : "";
|
3166
|
-
s.replaceAfter = s.endTriggerRe ? s.endTriggerRe.exec(after)[0] : "";
|
3167
|
-
return s;
|
3168
|
-
}
|
3169
|
-
};
|
3170
|
-
|
3171
|
-
this.snippetMap = {};
|
3172
|
-
this.snippetNameMap = {};
|
3173
|
-
this.register = function(snippets, scope) {
|
3174
|
-
var snippetMap = this.snippetMap;
|
3175
|
-
var snippetNameMap = this.snippetNameMap;
|
3176
|
-
var self = this;
|
3177
|
-
|
3178
|
-
if (!snippets)
|
3179
|
-
snippets = [];
|
3180
|
-
|
3181
|
-
function wrapRegexp(src) {
|
3182
|
-
if (src && !/^\^?\(.*\)\$?$|^\\b$/.test(src))
|
3183
|
-
src = "(?:" + src + ")";
|
3184
|
-
|
3185
|
-
return src || "";
|
3186
|
-
}
|
3187
|
-
function guardedRegexp(re, guard, opening) {
|
3188
|
-
re = wrapRegexp(re);
|
3189
|
-
guard = wrapRegexp(guard);
|
3190
|
-
if (opening) {
|
3191
|
-
re = guard + re;
|
3192
|
-
if (re && re[re.length - 1] != "$")
|
3193
|
-
re = re + "$";
|
3194
|
-
} else {
|
3195
|
-
re = re + guard;
|
3196
|
-
if (re && re[0] != "^")
|
3197
|
-
re = "^" + re;
|
3198
|
-
}
|
3199
|
-
return new RegExp(re);
|
3200
|
-
}
|
3201
|
-
|
3202
|
-
function addSnippet(s) {
|
3203
|
-
if (!s.scope)
|
3204
|
-
s.scope = scope || "_";
|
3205
|
-
scope = s.scope;
|
3206
|
-
if (!snippetMap[scope]) {
|
3207
|
-
snippetMap[scope] = [];
|
3208
|
-
snippetNameMap[scope] = {};
|
3209
|
-
}
|
3210
|
-
|
3211
|
-
var map = snippetNameMap[scope];
|
3212
|
-
if (s.name) {
|
3213
|
-
var old = map[s.name];
|
3214
|
-
if (old)
|
3215
|
-
self.unregister(old);
|
3216
|
-
map[s.name] = s;
|
3217
|
-
}
|
3218
|
-
snippetMap[scope].push(s);
|
3219
|
-
|
3220
|
-
if (s.tabTrigger && !s.trigger) {
|
3221
|
-
if (!s.guard && /^\w/.test(s.tabTrigger))
|
3222
|
-
s.guard = "\\b";
|
3223
|
-
s.trigger = lang.escapeRegExp(s.tabTrigger);
|
3224
|
-
}
|
3225
|
-
|
3226
|
-
s.startRe = guardedRegexp(s.trigger, s.guard, true);
|
3227
|
-
s.triggerRe = new RegExp(s.trigger, "", true);
|
3228
|
-
|
3229
|
-
s.endRe = guardedRegexp(s.endTrigger, s.endGuard, true);
|
3230
|
-
s.endTriggerRe = new RegExp(s.endTrigger, "", true);
|
3231
|
-
}
|
3232
|
-
|
3233
|
-
if (snippets && snippets.content)
|
3234
|
-
addSnippet(snippets);
|
3235
|
-
else if (Array.isArray(snippets))
|
3236
|
-
snippets.forEach(addSnippet);
|
3237
|
-
|
3238
|
-
this._signal("registerSnippets", {scope: scope});
|
3239
|
-
};
|
3240
|
-
this.unregister = function(snippets, scope) {
|
3241
|
-
var snippetMap = this.snippetMap;
|
3242
|
-
var snippetNameMap = this.snippetNameMap;
|
3243
|
-
|
3244
|
-
function removeSnippet(s) {
|
3245
|
-
var nameMap = snippetNameMap[s.scope||scope];
|
3246
|
-
if (nameMap && nameMap[s.name]) {
|
3247
|
-
delete nameMap[s.name];
|
3248
|
-
var map = snippetMap[s.scope||scope];
|
3249
|
-
var i = map && map.indexOf(s);
|
3250
|
-
if (i >= 0)
|
3251
|
-
map.splice(i, 1);
|
3252
|
-
}
|
3253
|
-
}
|
3254
|
-
if (snippets.content)
|
3255
|
-
removeSnippet(snippets);
|
3256
|
-
else if (Array.isArray(snippets))
|
3257
|
-
snippets.forEach(removeSnippet);
|
3258
|
-
};
|
3259
|
-
this.parseSnippetFile = function(str) {
|
3260
|
-
str = str.replace(/\r/g, "");
|
3261
|
-
var list = [], snippet = {};
|
3262
|
-
var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm;
|
3263
|
-
var m;
|
3264
|
-
while (m = re.exec(str)) {
|
3265
|
-
if (m[1]) {
|
3266
|
-
try {
|
3267
|
-
snippet = JSON.parse(m[1]);
|
3268
|
-
list.push(snippet);
|
3269
|
-
} catch (e) {}
|
3270
|
-
} if (m[4]) {
|
3271
|
-
snippet.content = m[4].replace(/^\t/gm, "");
|
3272
|
-
list.push(snippet);
|
3273
|
-
snippet = {};
|
3274
|
-
} else {
|
3275
|
-
var key = m[2], val = m[3];
|
3276
|
-
if (key == "regex") {
|
3277
|
-
var guardRe = /\/((?:[^\/\\]|\\.)*)|$/g;
|
3278
|
-
snippet.guard = guardRe.exec(val)[1];
|
3279
|
-
snippet.trigger = guardRe.exec(val)[1];
|
3280
|
-
snippet.endTrigger = guardRe.exec(val)[1];
|
3281
|
-
snippet.endGuard = guardRe.exec(val)[1];
|
3282
|
-
} else if (key == "snippet") {
|
3283
|
-
snippet.tabTrigger = val.match(/^\S*/)[0];
|
3284
|
-
if (!snippet.name)
|
3285
|
-
snippet.name = val;
|
3286
|
-
} else {
|
3287
|
-
snippet[key] = val;
|
3288
|
-
}
|
3289
|
-
}
|
3290
|
-
}
|
3291
|
-
return list;
|
3292
|
-
};
|
3293
|
-
this.getSnippetByName = function(name, editor) {
|
3294
|
-
var snippetMap = this.snippetNameMap;
|
3295
|
-
var snippet;
|
3296
|
-
this.getActiveScopes(editor).some(function(scope) {
|
3297
|
-
var snippets = snippetMap[scope];
|
3298
|
-
if (snippets)
|
3299
|
-
snippet = snippets[name];
|
3300
|
-
return !!snippet;
|
3301
|
-
}, this);
|
3302
|
-
return snippet;
|
3303
|
-
};
|
3304
|
-
|
3305
|
-
}).call(SnippetManager.prototype);
|
3306
|
-
|
3307
|
-
|
3308
|
-
var TabstopManager = function(editor) {
|
3309
|
-
if (editor.tabstopManager)
|
3310
|
-
return editor.tabstopManager;
|
3311
|
-
editor.tabstopManager = this;
|
3312
|
-
this.$onChange = this.onChange.bind(this);
|
3313
|
-
this.$onChangeSelection = lang.delayedCall(this.onChangeSelection.bind(this)).schedule;
|
3314
|
-
this.$onChangeSession = this.onChangeSession.bind(this);
|
3315
|
-
this.$onAfterExec = this.onAfterExec.bind(this);
|
3316
|
-
this.attach(editor);
|
3317
|
-
};
|
3318
|
-
(function() {
|
3319
|
-
this.attach = function(editor) {
|
3320
|
-
this.index = 0;
|
3321
|
-
this.ranges = [];
|
3322
|
-
this.tabstops = [];
|
3323
|
-
this.$openTabstops = null;
|
3324
|
-
this.selectedTabstop = null;
|
3325
|
-
|
3326
|
-
this.editor = editor;
|
3327
|
-
this.editor.on("change", this.$onChange);
|
3328
|
-
this.editor.on("changeSelection", this.$onChangeSelection);
|
3329
|
-
this.editor.on("changeSession", this.$onChangeSession);
|
3330
|
-
this.editor.commands.on("afterExec", this.$onAfterExec);
|
3331
|
-
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
3332
|
-
};
|
3333
|
-
this.detach = function() {
|
3334
|
-
this.tabstops.forEach(this.removeTabstopMarkers, this);
|
3335
|
-
this.ranges = null;
|
3336
|
-
this.tabstops = null;
|
3337
|
-
this.selectedTabstop = null;
|
3338
|
-
this.editor.removeListener("change", this.$onChange);
|
3339
|
-
this.editor.removeListener("changeSelection", this.$onChangeSelection);
|
3340
|
-
this.editor.removeListener("changeSession", this.$onChangeSession);
|
3341
|
-
this.editor.commands.removeListener("afterExec", this.$onAfterExec);
|
3342
|
-
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
|
3343
|
-
this.editor.tabstopManager = null;
|
3344
|
-
this.editor = null;
|
3345
|
-
};
|
3346
|
-
|
3347
|
-
this.onChange = function(e) {
|
3348
|
-
var changeRange = e.data.range;
|
3349
|
-
var isRemove = e.data.action[0] == "r";
|
3350
|
-
var start = changeRange.start;
|
3351
|
-
var end = changeRange.end;
|
3352
|
-
var startRow = start.row;
|
3353
|
-
var endRow = end.row;
|
3354
|
-
var lineDif = endRow - startRow;
|
3355
|
-
var colDiff = end.column - start.column;
|
3356
|
-
|
3357
|
-
if (isRemove) {
|
3358
|
-
lineDif = -lineDif;
|
3359
|
-
colDiff = -colDiff;
|
3360
|
-
}
|
3361
|
-
if (!this.$inChange && isRemove) {
|
3362
|
-
var ts = this.selectedTabstop;
|
3363
|
-
var changedOutside = ts && !ts.some(function(r) {
|
3364
|
-
return comparePoints(r.start, start) <= 0 && comparePoints(r.end, end) >= 0;
|
3365
|
-
});
|
3366
|
-
if (changedOutside)
|
3367
|
-
return this.detach();
|
3368
|
-
}
|
3369
|
-
var ranges = this.ranges;
|
3370
|
-
for (var i = 0; i < ranges.length; i++) {
|
3371
|
-
var r = ranges[i];
|
3372
|
-
if (r.end.row < start.row)
|
3373
|
-
continue;
|
3374
|
-
|
3375
|
-
if (isRemove && comparePoints(start, r.start) < 0 && comparePoints(end, r.end) > 0) {
|
3376
|
-
this.removeRange(r);
|
3377
|
-
i--;
|
3378
|
-
continue;
|
3379
|
-
}
|
3380
|
-
|
3381
|
-
if (r.start.row == startRow && r.start.column > start.column)
|
3382
|
-
r.start.column += colDiff;
|
3383
|
-
if (r.end.row == startRow && r.end.column >= start.column)
|
3384
|
-
r.end.column += colDiff;
|
3385
|
-
if (r.start.row >= startRow)
|
3386
|
-
r.start.row += lineDif;
|
3387
|
-
if (r.end.row >= startRow)
|
3388
|
-
r.end.row += lineDif;
|
3389
|
-
|
3390
|
-
if (comparePoints(r.start, r.end) > 0)
|
3391
|
-
this.removeRange(r);
|
3392
|
-
}
|
3393
|
-
if (!ranges.length)
|
3394
|
-
this.detach();
|
3395
|
-
};
|
3396
|
-
this.updateLinkedFields = function() {
|
3397
|
-
var ts = this.selectedTabstop;
|
3398
|
-
if (!ts || !ts.hasLinkedRanges)
|
3399
|
-
return;
|
3400
|
-
this.$inChange = true;
|
3401
|
-
var session = this.editor.session;
|
3402
|
-
var text = session.getTextRange(ts.firstNonLinked);
|
3403
|
-
for (var i = ts.length; i--;) {
|
3404
|
-
var range = ts[i];
|
3405
|
-
if (!range.linked)
|
3406
|
-
continue;
|
3407
|
-
var fmt = exports.snippetManager.tmStrFormat(text, range.original);
|
3408
|
-
session.replace(range, fmt);
|
3409
|
-
}
|
3410
|
-
this.$inChange = false;
|
3411
|
-
};
|
3412
|
-
this.onAfterExec = function(e) {
|
3413
|
-
if (e.command && !e.command.readOnly)
|
3414
|
-
this.updateLinkedFields();
|
3415
|
-
};
|
3416
|
-
this.onChangeSelection = function() {
|
3417
|
-
if (!this.editor)
|
3418
|
-
return;
|
3419
|
-
var lead = this.editor.selection.lead;
|
3420
|
-
var anchor = this.editor.selection.anchor;
|
3421
|
-
var isEmpty = this.editor.selection.isEmpty();
|
3422
|
-
for (var i = this.ranges.length; i--;) {
|
3423
|
-
if (this.ranges[i].linked)
|
3424
|
-
continue;
|
3425
|
-
var containsLead = this.ranges[i].contains(lead.row, lead.column);
|
3426
|
-
var containsAnchor = isEmpty || this.ranges[i].contains(anchor.row, anchor.column);
|
3427
|
-
if (containsLead && containsAnchor)
|
3428
|
-
return;
|
3429
|
-
}
|
3430
|
-
this.detach();
|
3431
|
-
};
|
3432
|
-
this.onChangeSession = function() {
|
3433
|
-
this.detach();
|
3434
|
-
};
|
3435
|
-
this.tabNext = function(dir) {
|
3436
|
-
var max = this.tabstops.length;
|
3437
|
-
var index = this.index + (dir || 1);
|
3438
|
-
index = Math.min(Math.max(index, 1), max);
|
3439
|
-
if (index == max)
|
3440
|
-
index = 0;
|
3441
|
-
this.selectTabstop(index);
|
3442
|
-
if (index === 0)
|
3443
|
-
this.detach();
|
3444
|
-
};
|
3445
|
-
this.selectTabstop = function(index) {
|
3446
|
-
this.$openTabstops = null;
|
3447
|
-
var ts = this.tabstops[this.index];
|
3448
|
-
if (ts)
|
3449
|
-
this.addTabstopMarkers(ts);
|
3450
|
-
this.index = index;
|
3451
|
-
ts = this.tabstops[this.index];
|
3452
|
-
if (!ts || !ts.length)
|
3453
|
-
return;
|
3454
|
-
|
3455
|
-
this.selectedTabstop = ts;
|
3456
|
-
if (!this.editor.inVirtualSelectionMode) {
|
3457
|
-
var sel = this.editor.multiSelect;
|
3458
|
-
sel.toSingleRange(ts.firstNonLinked.clone());
|
3459
|
-
for (var i = ts.length; i--;) {
|
3460
|
-
if (ts.hasLinkedRanges && ts[i].linked)
|
3461
|
-
continue;
|
3462
|
-
sel.addRange(ts[i].clone(), true);
|
3463
|
-
}
|
3464
|
-
if (sel.ranges[0])
|
3465
|
-
sel.addRange(sel.ranges[0].clone());
|
3466
|
-
} else {
|
3467
|
-
this.editor.selection.setRange(ts.firstNonLinked);
|
3468
|
-
}
|
3469
|
-
|
3470
|
-
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
3471
|
-
};
|
3472
|
-
this.addTabstops = function(tabstops, start, end) {
|
3473
|
-
if (!this.$openTabstops)
|
3474
|
-
this.$openTabstops = [];
|
3475
|
-
if (!tabstops[0]) {
|
3476
|
-
var p = Range.fromPoints(end, end);
|
3477
|
-
moveRelative(p.start, start);
|
3478
|
-
moveRelative(p.end, start);
|
3479
|
-
tabstops[0] = [p];
|
3480
|
-
tabstops[0].index = 0;
|
3481
|
-
}
|
3482
|
-
|
3483
|
-
var i = this.index;
|
3484
|
-
var arg = [i + 1, 0];
|
3485
|
-
var ranges = this.ranges;
|
3486
|
-
tabstops.forEach(function(ts, index) {
|
3487
|
-
var dest = this.$openTabstops[index] || ts;
|
3488
|
-
|
3489
|
-
for (var i = ts.length; i--;) {
|
3490
|
-
var p = ts[i];
|
3491
|
-
var range = Range.fromPoints(p.start, p.end || p.start);
|
3492
|
-
movePoint(range.start, start);
|
3493
|
-
movePoint(range.end, start);
|
3494
|
-
range.original = p;
|
3495
|
-
range.tabstop = dest;
|
3496
|
-
ranges.push(range);
|
3497
|
-
if (dest != ts)
|
3498
|
-
dest.unshift(range);
|
3499
|
-
else
|
3500
|
-
dest[i] = range;
|
3501
|
-
if (p.fmtString) {
|
3502
|
-
range.linked = true;
|
3503
|
-
dest.hasLinkedRanges = true;
|
3504
|
-
} else if (!dest.firstNonLinked)
|
3505
|
-
dest.firstNonLinked = range;
|
3506
|
-
}
|
3507
|
-
if (!dest.firstNonLinked)
|
3508
|
-
dest.hasLinkedRanges = false;
|
3509
|
-
if (dest === ts) {
|
3510
|
-
arg.push(dest);
|
3511
|
-
this.$openTabstops[index] = dest;
|
3512
|
-
}
|
3513
|
-
this.addTabstopMarkers(dest);
|
3514
|
-
}, this);
|
3515
|
-
|
3516
|
-
if (arg.length > 2) {
|
3517
|
-
if (this.tabstops.length)
|
3518
|
-
arg.push(arg.splice(2, 1)[0]);
|
3519
|
-
this.tabstops.splice.apply(this.tabstops, arg);
|
3520
|
-
}
|
3521
|
-
};
|
3522
|
-
|
3523
|
-
this.addTabstopMarkers = function(ts) {
|
3524
|
-
var session = this.editor.session;
|
3525
|
-
ts.forEach(function(range) {
|
3526
|
-
if (!range.markerId)
|
3527
|
-
range.markerId = session.addMarker(range, "ace_snippet-marker", "text");
|
3528
|
-
});
|
3529
|
-
};
|
3530
|
-
this.removeTabstopMarkers = function(ts) {
|
3531
|
-
var session = this.editor.session;
|
3532
|
-
ts.forEach(function(range) {
|
3533
|
-
session.removeMarker(range.markerId);
|
3534
|
-
range.markerId = null;
|
3535
|
-
});
|
3536
|
-
};
|
3537
|
-
this.removeRange = function(range) {
|
3538
|
-
var i = range.tabstop.indexOf(range);
|
3539
|
-
range.tabstop.splice(i, 1);
|
3540
|
-
i = this.ranges.indexOf(range);
|
3541
|
-
this.ranges.splice(i, 1);
|
3542
|
-
this.editor.session.removeMarker(range.markerId);
|
3543
|
-
if (!range.tabstop.length) {
|
3544
|
-
i = this.tabstops.indexOf(range.tabstop);
|
3545
|
-
if (i != -1)
|
3546
|
-
this.tabstops.splice(i, 1);
|
3547
|
-
if (!this.tabstops.length)
|
3548
|
-
this.detach();
|
3549
|
-
}
|
3550
|
-
};
|
3551
|
-
|
3552
|
-
this.keyboardHandler = new HashHandler();
|
3553
|
-
this.keyboardHandler.bindKeys({
|
3554
|
-
"Tab": function(ed) {
|
3555
|
-
if (exports.snippetManager && exports.snippetManager.expandWithTab(ed)) {
|
3556
|
-
return;
|
3557
|
-
}
|
3558
|
-
|
3559
|
-
ed.tabstopManager.tabNext(1);
|
3560
|
-
},
|
3561
|
-
"Shift-Tab": function(ed) {
|
3562
|
-
ed.tabstopManager.tabNext(-1);
|
3563
|
-
},
|
3564
|
-
"Esc": function(ed) {
|
3565
|
-
ed.tabstopManager.detach();
|
3566
|
-
},
|
3567
|
-
"Return": function(ed) {
|
3568
|
-
return false;
|
3569
|
-
}
|
3570
|
-
});
|
3571
|
-
}).call(TabstopManager.prototype);
|
3572
|
-
|
3573
|
-
|
3574
|
-
|
3575
|
-
var changeTracker = {};
|
3576
|
-
changeTracker.onChange = Anchor.prototype.onChange;
|
3577
|
-
changeTracker.setPosition = function(row, column) {
|
3578
|
-
this.pos.row = row;
|
3579
|
-
this.pos.column = column;
|
3580
|
-
};
|
3581
|
-
changeTracker.update = function(pos, delta, $insertRight) {
|
3582
|
-
this.$insertRight = $insertRight;
|
3583
|
-
this.pos = pos;
|
3584
|
-
this.onChange(delta);
|
3585
|
-
};
|
3586
|
-
|
3587
|
-
var movePoint = function(point, diff) {
|
3588
|
-
if (point.row == 0)
|
3589
|
-
point.column += diff.column;
|
3590
|
-
point.row += diff.row;
|
3591
|
-
};
|
3592
|
-
|
3593
|
-
var moveRelative = function(point, start) {
|
3594
|
-
if (point.row == start.row)
|
3595
|
-
point.column -= start.column;
|
3596
|
-
point.row -= start.row;
|
3597
|
-
};
|
3598
|
-
|
3599
|
-
|
3600
|
-
require("./lib/dom").importCssString("\
|
3601
|
-
.ace_snippet-marker {\
|
3602
|
-
-moz-box-sizing: border-box;\
|
3603
|
-
box-sizing: border-box;\
|
3604
|
-
background: rgba(194, 193, 208, 0.09);\
|
3605
|
-
border: 1px dotted rgba(211, 208, 235, 0.62);\
|
3606
|
-
position: absolute;\
|
3607
|
-
}");
|
3608
|
-
|
3609
|
-
exports.snippetManager = new SnippetManager();
|
3610
|
-
|
3611
|
-
|
3612
|
-
var Editor = require("./editor").Editor;
|
3613
|
-
(function() {
|
3614
|
-
this.insertSnippet = function(content, options) {
|
3615
|
-
return exports.snippetManager.insertSnippet(this, content, options);
|
3616
|
-
};
|
3617
|
-
this.expandSnippet = function(options) {
|
3618
|
-
return exports.snippetManager.expandWithTab(this, options);
|
3619
|
-
};
|
3620
|
-
}).call(Editor.prototype);
|
3621
|
-
|
3622
|
-
});
|
3623
|
-
|
3624
|
-
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) {
|
3625
|
-
"use strict";
|
3626
|
-
|
3627
|
-
var EditSession = require("../edit_session").EditSession;
|
3628
|
-
var Renderer = require("../virtual_renderer").VirtualRenderer;
|
3629
|
-
var Editor = require("../editor").Editor;
|
3630
|
-
var Range = require("../range").Range;
|
3631
|
-
var event = require("../lib/event");
|
3632
|
-
var lang = require("../lib/lang");
|
3633
|
-
var dom = require("../lib/dom");
|
3634
|
-
|
3635
|
-
var $singleLineEditor = function(el) {
|
3636
|
-
var renderer = new Renderer(el);
|
3637
|
-
|
3638
|
-
renderer.$maxLines = 4;
|
3639
|
-
|
3640
|
-
var editor = new Editor(renderer);
|
3641
|
-
|
3642
|
-
editor.setHighlightActiveLine(false);
|
3643
|
-
editor.setShowPrintMargin(false);
|
3644
|
-
editor.renderer.setShowGutter(false);
|
3645
|
-
editor.renderer.setHighlightGutterLine(false);
|
3646
|
-
|
3647
|
-
editor.$mouseHandler.$focusWaitTimout = 0;
|
3648
|
-
editor.$highlightTagPending = true;
|
3649
|
-
|
3650
|
-
return editor;
|
3651
|
-
};
|
3652
|
-
|
3653
|
-
var AcePopup = function(parentNode) {
|
3654
|
-
var el = dom.createElement("div");
|
3655
|
-
var popup = new $singleLineEditor(el);
|
3656
|
-
|
3657
|
-
if (parentNode)
|
3658
|
-
parentNode.appendChild(el);
|
3659
|
-
el.style.display = "none";
|
3660
|
-
popup.renderer.content.style.cursor = "default";
|
3661
|
-
popup.renderer.setStyle("ace_autocomplete");
|
3662
|
-
|
3663
|
-
popup.setOption("displayIndentGuides", false);
|
3664
|
-
popup.setOption("dragDelay", 150);
|
3665
|
-
|
3666
|
-
var noop = function(){};
|
3667
|
-
|
3668
|
-
popup.focus = noop;
|
3669
|
-
popup.$isFocused = true;
|
3670
|
-
|
3671
|
-
popup.renderer.$cursorLayer.restartTimer = noop;
|
3672
|
-
popup.renderer.$cursorLayer.element.style.opacity = 0;
|
3673
|
-
|
3674
|
-
popup.renderer.$maxLines = 8;
|
3675
|
-
popup.renderer.$keepTextAreaAtCursor = false;
|
3676
|
-
|
3677
|
-
popup.setHighlightActiveLine(false);
|
3678
|
-
popup.session.highlight("");
|
3679
|
-
popup.session.$searchHighlight.clazz = "ace_highlight-marker";
|
3680
|
-
|
3681
|
-
popup.on("mousedown", function(e) {
|
3682
|
-
var pos = e.getDocumentPosition();
|
3683
|
-
popup.selection.moveToPosition(pos);
|
3684
|
-
selectionMarker.start.row = selectionMarker.end.row = pos.row;
|
3685
|
-
e.stop();
|
3686
|
-
});
|
3687
|
-
|
3688
|
-
var lastMouseEvent;
|
3689
|
-
var hoverMarker = new Range(-1,0,-1,Infinity);
|
3690
|
-
var selectionMarker = new Range(-1,0,-1,Infinity);
|
3691
|
-
selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine");
|
3692
|
-
popup.setSelectOnHover = function(val) {
|
3693
|
-
if (!val) {
|
3694
|
-
hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
|
3695
|
-
} else if (hoverMarker.id) {
|
3696
|
-
popup.session.removeMarker(hoverMarker.id);
|
3697
|
-
hoverMarker.id = null;
|
3698
|
-
}
|
3699
|
-
};
|
3700
|
-
popup.setSelectOnHover(false);
|
3701
|
-
popup.on("mousemove", function(e) {
|
3702
|
-
if (!lastMouseEvent) {
|
3703
|
-
lastMouseEvent = e;
|
3704
|
-
return;
|
3705
|
-
}
|
3706
|
-
if (lastMouseEvent.x == e.x && lastMouseEvent.y == e.y) {
|
3707
|
-
return;
|
3708
|
-
}
|
3709
|
-
lastMouseEvent = e;
|
3710
|
-
lastMouseEvent.scrollTop = popup.renderer.scrollTop;
|
3711
|
-
var row = lastMouseEvent.getDocumentPosition().row;
|
3712
|
-
if (hoverMarker.start.row != row) {
|
3713
|
-
if (!hoverMarker.id)
|
3714
|
-
popup.setRow(row);
|
3715
|
-
setHoverMarker(row);
|
3716
|
-
}
|
3717
|
-
});
|
3718
|
-
popup.renderer.on("beforeRender", function() {
|
3719
|
-
if (lastMouseEvent && hoverMarker.start.row != -1) {
|
3720
|
-
lastMouseEvent.$pos = null;
|
3721
|
-
var row = lastMouseEvent.getDocumentPosition().row;
|
3722
|
-
if (!hoverMarker.id)
|
3723
|
-
popup.setRow(row);
|
3724
|
-
setHoverMarker(row, true);
|
3725
|
-
}
|
3726
|
-
});
|
3727
|
-
popup.renderer.on("afterRender", function() {
|
3728
|
-
var row = popup.getRow();
|
3729
|
-
var t = popup.renderer.$textLayer;
|
3730
|
-
var selected = t.element.childNodes[row - t.config.firstRow];
|
3731
|
-
if (selected == t.selectedNode)
|
3732
|
-
return;
|
3733
|
-
if (t.selectedNode)
|
3734
|
-
dom.removeCssClass(t.selectedNode, "ace_selected");
|
3735
|
-
t.selectedNode = selected;
|
3736
|
-
if (selected)
|
3737
|
-
dom.addCssClass(selected, "ace_selected");
|
3738
|
-
});
|
3739
|
-
var hideHoverMarker = function() { setHoverMarker(-1) };
|
3740
|
-
var setHoverMarker = function(row, suppressRedraw) {
|
3741
|
-
if (row !== hoverMarker.start.row) {
|
3742
|
-
hoverMarker.start.row = hoverMarker.end.row = row;
|
3743
|
-
if (!suppressRedraw)
|
3744
|
-
popup.session._emit("changeBackMarker");
|
3745
|
-
popup._emit("changeHoverMarker");
|
3746
|
-
}
|
3747
|
-
};
|
3748
|
-
popup.getHoveredRow = function() {
|
3749
|
-
return hoverMarker.start.row;
|
3750
|
-
};
|
3751
|
-
|
3752
|
-
event.addListener(popup.container, "mouseout", hideHoverMarker);
|
3753
|
-
popup.on("hide", hideHoverMarker);
|
3754
|
-
popup.on("changeSelection", hideHoverMarker);
|
3755
|
-
|
3756
|
-
popup.session.doc.getLength = function() {
|
3757
|
-
return popup.data.length;
|
3758
|
-
};
|
3759
|
-
popup.session.doc.getLine = function(i) {
|
3760
|
-
var data = popup.data[i];
|
3761
|
-
if (typeof data == "string")
|
3762
|
-
return data;
|
3763
|
-
return (data && data.value) || "";
|
3764
|
-
};
|
3765
|
-
|
3766
|
-
var bgTokenizer = popup.session.bgTokenizer;
|
3767
|
-
bgTokenizer.$tokenizeRow = function(row) {
|
3768
|
-
var data = popup.data[row];
|
3769
|
-
var tokens = [];
|
3770
|
-
if (!data)
|
3771
|
-
return tokens;
|
3772
|
-
if (typeof data == "string")
|
3773
|
-
data = {value: data};
|
3774
|
-
if (!data.caption)
|
3775
|
-
data.caption = data.value || data.name;
|
3776
|
-
|
3777
|
-
var last = -1;
|
3778
|
-
var flag, c;
|
3779
|
-
for (var i = 0; i < data.caption.length; i++) {
|
3780
|
-
c = data.caption[i];
|
3781
|
-
flag = data.matchMask & (1 << i) ? 1 : 0;
|
3782
|
-
if (last !== flag) {
|
3783
|
-
tokens.push({type: data.className || "" + ( flag ? "completion-highlight" : ""), value: c});
|
3784
|
-
last = flag;
|
3785
|
-
} else {
|
3786
|
-
tokens[tokens.length - 1].value += c;
|
3787
|
-
}
|
3788
|
-
}
|
3789
|
-
|
3790
|
-
if (data.meta) {
|
3791
|
-
var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth;
|
3792
|
-
if (data.meta.length + data.caption.length < maxW - 2)
|
3793
|
-
tokens.push({type: "rightAlignedText", value: data.meta});
|
3794
|
-
}
|
3795
|
-
return tokens;
|
3796
|
-
};
|
3797
|
-
bgTokenizer.$updateOnChange = noop;
|
3798
|
-
bgTokenizer.start = noop;
|
3799
|
-
|
3800
|
-
popup.session.$computeWidth = function() {
|
3801
|
-
return this.screenWidth = 0;
|
3802
|
-
};
|
3803
|
-
popup.isOpen = false;
|
3804
|
-
popup.isTopdown = false;
|
3805
|
-
|
3806
|
-
popup.data = [];
|
3807
|
-
popup.setData = function(list) {
|
3808
|
-
popup.data = list || [];
|
3809
|
-
popup.setValue(lang.stringRepeat("\n", list.length), -1);
|
3810
|
-
popup.setRow(0);
|
3811
|
-
};
|
3812
|
-
popup.getData = function(row) {
|
3813
|
-
return popup.data[row];
|
3814
|
-
};
|
3815
|
-
|
3816
|
-
popup.getRow = function() {
|
3817
|
-
return selectionMarker.start.row;
|
3818
|
-
};
|
3819
|
-
popup.setRow = function(line) {
|
3820
|
-
line = Math.max(-1, Math.min(this.data.length, line));
|
3821
|
-
if (selectionMarker.start.row != line) {
|
3822
|
-
popup.selection.clearSelection();
|
3823
|
-
selectionMarker.start.row = selectionMarker.end.row = line || 0;
|
3824
|
-
popup.session._emit("changeBackMarker");
|
3825
|
-
popup.moveCursorTo(line || 0, 0);
|
3826
|
-
if (popup.isOpen)
|
3827
|
-
popup._signal("select");
|
3828
|
-
}
|
3829
|
-
};
|
3830
|
-
|
3831
|
-
popup.on("changeSelection", function() {
|
3832
|
-
if (popup.isOpen)
|
3833
|
-
popup.setRow(popup.selection.lead.row);
|
3834
|
-
});
|
3835
|
-
|
3836
|
-
popup.hide = function() {
|
3837
|
-
this.container.style.display = "none";
|
3838
|
-
this._signal("hide");
|
3839
|
-
popup.isOpen = false;
|
3840
|
-
};
|
3841
|
-
popup.show = function(pos, lineHeight, topdownOnly) {
|
3842
|
-
var el = this.container;
|
3843
|
-
var screenHeight = window.innerHeight;
|
3844
|
-
var screenWidth = window.innerWidth;
|
3845
|
-
var renderer = this.renderer;
|
3846
|
-
var maxH = renderer.$maxLines * lineHeight * 1.4;
|
3847
|
-
var top = pos.top + this.$borderSize;
|
3848
|
-
if (top + maxH > screenHeight - lineHeight && !topdownOnly) {
|
3849
|
-
el.style.top = "";
|
3850
|
-
el.style.bottom = screenHeight - top + "px";
|
3851
|
-
popup.isTopdown = false;
|
3852
|
-
} else {
|
3853
|
-
top += lineHeight;
|
3854
|
-
el.style.top = top + "px";
|
3855
|
-
el.style.bottom = "";
|
3856
|
-
popup.isTopdown = true;
|
3857
|
-
}
|
3858
|
-
|
3859
|
-
el.style.display = "";
|
3860
|
-
this.renderer.$textLayer.checkForSizeChanges();
|
3861
|
-
|
3862
|
-
var left = pos.left;
|
3863
|
-
if (left + el.offsetWidth > screenWidth)
|
3864
|
-
left = screenWidth - el.offsetWidth;
|
3865
|
-
|
3866
|
-
el.style.left = left + "px";
|
3867
|
-
|
3868
|
-
this._signal("show");
|
3869
|
-
lastMouseEvent = null;
|
3870
|
-
popup.isOpen = true;
|
3871
|
-
};
|
3872
|
-
|
3873
|
-
popup.getTextLeftOffset = function() {
|
3874
|
-
return this.$borderSize + this.renderer.$padding + this.$imageSize;
|
3875
|
-
};
|
3876
|
-
|
3877
|
-
popup.$imageSize = 0;
|
3878
|
-
popup.$borderSize = 1;
|
3879
|
-
|
3880
|
-
return popup;
|
3881
|
-
};
|
3882
|
-
|
3883
|
-
dom.importCssString("\
|
3884
|
-
.ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line {\
|
3885
|
-
background-color: #CAD6FA;\
|
3886
|
-
z-index: 1;\
|
3887
|
-
}\
|
3888
|
-
.ace_editor.ace_autocomplete .ace_line-hover {\
|
3889
|
-
border: 1px solid #abbffe;\
|
3890
|
-
margin-top: -1px;\
|
3891
|
-
background: rgba(233,233,253,0.4);\
|
3892
|
-
}\
|
3893
|
-
.ace_editor.ace_autocomplete .ace_line-hover {\
|
3894
|
-
position: absolute;\
|
3895
|
-
z-index: 2;\
|
3896
|
-
}\
|
3897
|
-
.ace_editor.ace_autocomplete .ace_scroller {\
|
3898
|
-
background: none;\
|
3899
|
-
border: none;\
|
3900
|
-
box-shadow: none;\
|
3901
|
-
}\
|
3902
|
-
.ace_rightAlignedText {\
|
3903
|
-
color: gray;\
|
3904
|
-
display: inline-block;\
|
3905
|
-
position: absolute;\
|
3906
|
-
right: 4px;\
|
3907
|
-
text-align: right;\
|
3908
|
-
z-index: -1;\
|
3909
|
-
}\
|
3910
|
-
.ace_editor.ace_autocomplete .ace_completion-highlight{\
|
3911
|
-
color: #000;\
|
3912
|
-
text-shadow: 0 0 0.01em;\
|
3913
|
-
}\
|
3914
|
-
.ace_editor.ace_autocomplete {\
|
3915
|
-
width: 280px;\
|
3916
|
-
z-index: 200000;\
|
3917
|
-
background: #fbfbfb;\
|
3918
|
-
color: #444;\
|
3919
|
-
border: 1px lightgray solid;\
|
3920
|
-
position: fixed;\
|
3921
|
-
box-shadow: 2px 3px 5px rgba(0,0,0,.2);\
|
3922
|
-
line-height: 1.4;\
|
3923
|
-
}");
|
3924
|
-
|
3925
|
-
exports.AcePopup = AcePopup;
|
3926
|
-
|
3927
|
-
});
|
3928
|
-
|
3929
|
-
define("ace/autocomplete/util",["require","exports","module"], function(require, exports, module) {
|
3930
|
-
"use strict";
|
3931
|
-
|
3932
|
-
exports.parForEach = function(array, fn, callback) {
|
3933
|
-
var completed = 0;
|
3934
|
-
var arLength = array.length;
|
3935
|
-
if (arLength === 0)
|
3936
|
-
callback();
|
3937
|
-
for (var i = 0; i < arLength; i++) {
|
3938
|
-
fn(array[i], function(result, err) {
|
3939
|
-
completed++;
|
3940
|
-
if (completed === arLength)
|
3941
|
-
callback(result, err);
|
3942
|
-
});
|
3943
|
-
}
|
3944
|
-
};
|
3945
|
-
|
3946
|
-
var ID_REGEX = /[a-zA-Z_0-9\$\-\u00A2-\uFFFF]/;
|
3947
|
-
|
3948
|
-
exports.retrievePrecedingIdentifier = function(text, pos, regex) {
|
3949
|
-
regex = regex || ID_REGEX;
|
3950
|
-
var buf = [];
|
3951
|
-
for (var i = pos-1; i >= 0; i--) {
|
3952
|
-
if (regex.test(text[i]))
|
3953
|
-
buf.push(text[i]);
|
3954
|
-
else
|
3955
|
-
break;
|
3956
|
-
}
|
3957
|
-
return buf.reverse().join("");
|
3958
|
-
};
|
3959
|
-
|
3960
|
-
exports.retrieveFollowingIdentifier = function(text, pos, regex) {
|
3961
|
-
regex = regex || ID_REGEX;
|
3962
|
-
var buf = [];
|
3963
|
-
for (var i = pos; i < text.length; i++) {
|
3964
|
-
if (regex.test(text[i]))
|
3965
|
-
buf.push(text[i]);
|
3966
|
-
else
|
3967
|
-
break;
|
3968
|
-
}
|
3969
|
-
return buf;
|
3970
|
-
};
|
3971
|
-
|
3972
|
-
});
|
3973
|
-
|
3974
|
-
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) {
|
3975
|
-
"use strict";
|
3976
|
-
|
3977
|
-
var HashHandler = require("./keyboard/hash_handler").HashHandler;
|
3978
|
-
var AcePopup = require("./autocomplete/popup").AcePopup;
|
3979
|
-
var util = require("./autocomplete/util");
|
3980
|
-
var event = require("./lib/event");
|
3981
|
-
var lang = require("./lib/lang");
|
3982
|
-
var snippetManager = require("./snippets").snippetManager;
|
3983
|
-
|
3984
|
-
var Autocomplete = function() {
|
3985
|
-
this.autoInsert = true;
|
3986
|
-
this.autoSelect = true;
|
3987
|
-
this.keyboardHandler = new HashHandler();
|
3988
|
-
this.keyboardHandler.bindKeys(this.commands);
|
3989
|
-
|
3990
|
-
this.blurListener = this.blurListener.bind(this);
|
3991
|
-
this.changeListener = this.changeListener.bind(this);
|
3992
|
-
this.mousedownListener = this.mousedownListener.bind(this);
|
3993
|
-
this.mousewheelListener = this.mousewheelListener.bind(this);
|
3994
|
-
|
3995
|
-
this.changeTimer = lang.delayedCall(function() {
|
3996
|
-
this.updateCompletions(true);
|
3997
|
-
}.bind(this));
|
3998
|
-
};
|
3999
|
-
|
4000
|
-
(function() {
|
4001
|
-
this.gatherCompletionsId = 0;
|
4002
|
-
|
4003
|
-
this.$init = function() {
|
4004
|
-
this.popup = new AcePopup(document.body || document.documentElement);
|
4005
|
-
this.popup.on("click", function(e) {
|
4006
|
-
this.insertMatch();
|
4007
|
-
e.stop();
|
4008
|
-
}.bind(this));
|
4009
|
-
this.popup.focus = this.editor.focus.bind(this.editor);
|
4010
|
-
};
|
4011
|
-
|
4012
|
-
this.openPopup = function(editor, prefix, keepPopupPosition) {
|
4013
|
-
if (!this.popup)
|
4014
|
-
this.$init();
|
4015
|
-
|
4016
|
-
this.popup.setData(this.completions.filtered);
|
4017
|
-
|
4018
|
-
var renderer = editor.renderer;
|
4019
|
-
this.popup.setRow(this.autoSelect ? 0 : -1);
|
4020
|
-
if (!keepPopupPosition) {
|
4021
|
-
this.popup.setTheme(editor.getTheme());
|
4022
|
-
this.popup.setFontSize(editor.getFontSize());
|
4023
|
-
|
4024
|
-
var lineHeight = renderer.layerConfig.lineHeight;
|
4025
|
-
|
4026
|
-
var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
|
4027
|
-
pos.left -= this.popup.getTextLeftOffset();
|
4028
|
-
|
4029
|
-
var rect = editor.container.getBoundingClientRect();
|
4030
|
-
pos.top += rect.top - renderer.layerConfig.offset;
|
4031
|
-
pos.left += rect.left - editor.renderer.scrollLeft;
|
4032
|
-
pos.left += renderer.$gutterLayer.gutterWidth;
|
4033
|
-
|
4034
|
-
this.popup.show(pos, lineHeight);
|
4035
|
-
} else if (keepPopupPosition && !prefix) {
|
4036
|
-
this.detach();
|
4037
|
-
}
|
4038
|
-
};
|
4039
|
-
|
4040
|
-
this.detach = function() {
|
4041
|
-
this.editor.keyBinding.removeKeyboardHandler(this.keyboardHandler);
|
4042
|
-
this.editor.off("changeSelection", this.changeListener);
|
4043
|
-
this.editor.off("blur", this.blurListener);
|
4044
|
-
this.editor.off("mousedown", this.mousedownListener);
|
4045
|
-
this.editor.off("mousewheel", this.mousewheelListener);
|
4046
|
-
this.changeTimer.cancel();
|
4047
|
-
|
4048
|
-
if (this.popup && this.popup.isOpen) {
|
4049
|
-
this.gatherCompletionsId += 1;
|
4050
|
-
this.popup.hide();
|
4051
|
-
}
|
4052
|
-
|
4053
|
-
if (this.base)
|
4054
|
-
this.base.detach();
|
4055
|
-
this.activated = false;
|
4056
|
-
this.completions = this.base = null;
|
4057
|
-
};
|
4058
|
-
|
4059
|
-
this.changeListener = function(e) {
|
4060
|
-
var cursor = this.editor.selection.lead;
|
4061
|
-
if (cursor.row != this.base.row || cursor.column < this.base.column) {
|
4062
|
-
this.detach();
|
4063
|
-
}
|
4064
|
-
if (this.activated)
|
4065
|
-
this.changeTimer.schedule();
|
4066
|
-
else
|
4067
|
-
this.detach();
|
4068
|
-
};
|
4069
|
-
|
4070
|
-
this.blurListener = function() {
|
4071
|
-
var el = document.activeElement;
|
4072
|
-
if (el != this.editor.textInput.getElement() && el.parentNode != this.popup.container)
|
4073
|
-
this.detach();
|
4074
|
-
};
|
4075
|
-
|
4076
|
-
this.mousedownListener = function(e) {
|
4077
|
-
this.detach();
|
4078
|
-
};
|
4079
|
-
|
4080
|
-
this.mousewheelListener = function(e) {
|
4081
|
-
this.detach();
|
4082
|
-
};
|
4083
|
-
|
4084
|
-
this.goTo = function(where) {
|
4085
|
-
var row = this.popup.getRow();
|
4086
|
-
var max = this.popup.session.getLength() - 1;
|
4087
|
-
|
4088
|
-
switch(where) {
|
4089
|
-
case "up": row = row <= 0 ? max : row - 1; break;
|
4090
|
-
case "down": row = row >= max ? -1 : row + 1; break;
|
4091
|
-
case "start": row = 0; break;
|
4092
|
-
case "end": row = max; break;
|
4093
|
-
}
|
4094
|
-
|
4095
|
-
this.popup.setRow(row);
|
4096
|
-
};
|
4097
|
-
|
4098
|
-
this.insertMatch = function(data) {
|
4099
|
-
if (!data)
|
4100
|
-
data = this.popup.getData(this.popup.getRow());
|
4101
|
-
if (!data)
|
4102
|
-
return false;
|
4103
|
-
|
4104
|
-
if (data.completer && data.completer.insertMatch) {
|
4105
|
-
data.completer.insertMatch(this.editor);
|
4106
|
-
} else {
|
4107
|
-
if (this.completions.filterText) {
|
4108
|
-
var ranges = this.editor.selection.getAllRanges();
|
4109
|
-
for (var i = 0, range; range = ranges[i]; i++) {
|
4110
|
-
range.start.column -= this.completions.filterText.length;
|
4111
|
-
this.editor.session.remove(range);
|
4112
|
-
}
|
4113
|
-
}
|
4114
|
-
if (data.snippet)
|
4115
|
-
snippetManager.insertSnippet(this.editor, data.snippet);
|
4116
|
-
else
|
4117
|
-
this.editor.execCommand("insertstring", data.value || data);
|
4118
|
-
}
|
4119
|
-
this.detach();
|
4120
|
-
};
|
4121
|
-
|
4122
|
-
this.commands = {
|
4123
|
-
"Up": function(editor) { editor.completer.goTo("up"); },
|
4124
|
-
"Down": function(editor) { editor.completer.goTo("down"); },
|
4125
|
-
"Ctrl-Up|Ctrl-Home": function(editor) { editor.completer.goTo("start"); },
|
4126
|
-
"Ctrl-Down|Ctrl-End": function(editor) { editor.completer.goTo("end"); },
|
4127
|
-
|
4128
|
-
"Esc": function(editor) { editor.completer.detach(); },
|
4129
|
-
"Space": function(editor) { editor.completer.detach(); editor.insert(" ");},
|
4130
|
-
"Return": function(editor) { return editor.completer.insertMatch(); },
|
4131
|
-
"Shift-Return": function(editor) { editor.completer.insertMatch(true); },
|
4132
|
-
"Tab": function(editor) {
|
4133
|
-
var result = editor.completer.insertMatch();
|
4134
|
-
if (!result && !editor.tabstopManager)
|
4135
|
-
editor.completer.goTo("down");
|
4136
|
-
else
|
4137
|
-
return result;
|
4138
|
-
},
|
4139
|
-
|
4140
|
-
"PageUp": function(editor) { editor.completer.popup.gotoPageUp(); },
|
4141
|
-
"PageDown": function(editor) { editor.completer.popup.gotoPageDown(); }
|
4142
|
-
};
|
4143
|
-
|
4144
|
-
this.gatherCompletions = function(editor, callback) {
|
4145
|
-
var session = editor.getSession();
|
4146
|
-
var pos = editor.getCursorPosition();
|
4147
|
-
|
4148
|
-
var line = session.getLine(pos.row);
|
4149
|
-
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
4150
|
-
|
4151
|
-
this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
|
4152
|
-
this.base.$insertRight = true;
|
4153
|
-
|
4154
|
-
var matches = [];
|
4155
|
-
var total = editor.completers.length;
|
4156
|
-
editor.completers.forEach(function(completer, i) {
|
4157
|
-
completer.getCompletions(editor, session, pos, prefix, function(err, results) {
|
4158
|
-
if (!err)
|
4159
|
-
matches = matches.concat(results);
|
4160
|
-
var pos = editor.getCursorPosition();
|
4161
|
-
var line = session.getLine(pos.row);
|
4162
|
-
callback(null, {
|
4163
|
-
prefix: util.retrievePrecedingIdentifier(line, pos.column, results[0] && results[0].identifierRegex),
|
4164
|
-
matches: matches,
|
4165
|
-
finished: (--total === 0)
|
4166
|
-
});
|
4167
|
-
});
|
4168
|
-
});
|
4169
|
-
return true;
|
4170
|
-
};
|
4171
|
-
|
4172
|
-
this.showPopup = function(editor) {
|
4173
|
-
if (this.editor)
|
4174
|
-
this.detach();
|
4175
|
-
|
4176
|
-
this.activated = true;
|
4177
|
-
|
4178
|
-
this.editor = editor;
|
4179
|
-
if (editor.completer != this) {
|
4180
|
-
if (editor.completer)
|
4181
|
-
editor.completer.detach();
|
4182
|
-
editor.completer = this;
|
4183
|
-
}
|
4184
|
-
|
4185
|
-
editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
|
4186
|
-
editor.on("changeSelection", this.changeListener);
|
4187
|
-
editor.on("blur", this.blurListener);
|
4188
|
-
editor.on("mousedown", this.mousedownListener);
|
4189
|
-
editor.on("mousewheel", this.mousewheelListener);
|
4190
|
-
|
4191
|
-
this.updateCompletions();
|
4192
|
-
};
|
4193
|
-
|
4194
|
-
this.updateCompletions = function(keepPopupPosition) {
|
4195
|
-
if (keepPopupPosition && this.base && this.completions) {
|
4196
|
-
var pos = this.editor.getCursorPosition();
|
4197
|
-
var prefix = this.editor.session.getTextRange({start: this.base, end: pos});
|
4198
|
-
if (prefix == this.completions.filterText)
|
4199
|
-
return;
|
4200
|
-
this.completions.setFilter(prefix);
|
4201
|
-
if (!this.completions.filtered.length)
|
4202
|
-
return this.detach();
|
4203
|
-
if (this.completions.filtered.length == 1
|
4204
|
-
&& this.completions.filtered[0].value == prefix
|
4205
|
-
&& !this.completions.filtered[0].snippet)
|
4206
|
-
return this.detach();
|
4207
|
-
this.openPopup(this.editor, prefix, keepPopupPosition);
|
4208
|
-
return;
|
4209
|
-
}
|
4210
|
-
var _id = this.gatherCompletionsId;
|
4211
|
-
this.gatherCompletions(this.editor, function(err, results) {
|
4212
|
-
var detachIfFinished = function() {
|
4213
|
-
if (!results.finished) return;
|
4214
|
-
return this.detach();
|
4215
|
-
}.bind(this);
|
4216
|
-
|
4217
|
-
var prefix = results.prefix;
|
4218
|
-
var matches = results && results.matches;
|
4219
|
-
|
4220
|
-
if (!matches || !matches.length)
|
4221
|
-
return detachIfFinished();
|
4222
|
-
if (prefix.indexOf(results.prefix) !== 0 || _id != this.gatherCompletionsId)
|
4223
|
-
return;
|
4224
|
-
|
4225
|
-
this.completions = new FilteredList(matches);
|
4226
|
-
this.completions.setFilter(prefix);
|
4227
|
-
var filtered = this.completions.filtered;
|
4228
|
-
if (!filtered.length)
|
4229
|
-
return detachIfFinished();
|
4230
|
-
if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet)
|
4231
|
-
return detachIfFinished();
|
4232
|
-
if (this.autoInsert && filtered.length == 1 && results.finished)
|
4233
|
-
return this.insertMatch(filtered[0]);
|
4234
|
-
|
4235
|
-
this.openPopup(this.editor, prefix, keepPopupPosition);
|
4236
|
-
}.bind(this));
|
4237
|
-
};
|
4238
|
-
|
4239
|
-
this.cancelContextMenu = function() {
|
4240
|
-
this.editor.$mouseHandler.cancelContextMenu();
|
4241
|
-
};
|
4242
|
-
|
4243
|
-
}).call(Autocomplete.prototype);
|
4244
|
-
|
4245
|
-
Autocomplete.startCommand = {
|
4246
|
-
name: "startAutocomplete",
|
4247
|
-
exec: function(editor) {
|
4248
|
-
if (!editor.completer)
|
4249
|
-
editor.completer = new Autocomplete();
|
4250
|
-
editor.completer.autoInsert =
|
4251
|
-
editor.completer.autoSelect = true;
|
4252
|
-
editor.completer.showPopup(editor);
|
4253
|
-
editor.completer.cancelContextMenu();
|
4254
|
-
},
|
4255
|
-
bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
|
4256
|
-
};
|
4257
|
-
|
4258
|
-
var FilteredList = function(array, filterText, mutateData) {
|
4259
|
-
this.all = array;
|
4260
|
-
this.filtered = array;
|
4261
|
-
this.filterText = filterText || "";
|
4262
|
-
};
|
4263
|
-
(function(){
|
4264
|
-
this.setFilter = function(str) {
|
4265
|
-
if (str.length > this.filterText && str.lastIndexOf(this.filterText, 0) === 0)
|
4266
|
-
var matches = this.filtered;
|
4267
|
-
else
|
4268
|
-
var matches = this.all;
|
4269
|
-
|
4270
|
-
this.filterText = str;
|
4271
|
-
matches = this.filterCompletions(matches, this.filterText);
|
4272
|
-
matches = matches.sort(function(a, b) {
|
4273
|
-
return b.exactMatch - a.exactMatch || b.score - a.score;
|
4274
|
-
});
|
4275
|
-
var prev = null;
|
4276
|
-
matches = matches.filter(function(item){
|
4277
|
-
var caption = item.snippet || item.caption || item.value;
|
4278
|
-
if (caption === prev) return false;
|
4279
|
-
prev = caption;
|
4280
|
-
return true;
|
4281
|
-
});
|
4282
|
-
|
4283
|
-
this.filtered = matches;
|
4284
|
-
};
|
4285
|
-
this.filterCompletions = function(items, needle) {
|
4286
|
-
var results = [];
|
4287
|
-
var upper = needle.toUpperCase();
|
4288
|
-
var lower = needle.toLowerCase();
|
4289
|
-
loop: for (var i = 0, item; item = items[i]; i++) {
|
4290
|
-
var caption = item.value || item.caption || item.snippet;
|
4291
|
-
if (!caption) continue;
|
4292
|
-
var lastIndex = -1;
|
4293
|
-
var matchMask = 0;
|
4294
|
-
var penalty = 0;
|
4295
|
-
var index, distance;
|
4296
|
-
for (var j = 0; j < needle.length; j++) {
|
4297
|
-
var i1 = caption.indexOf(lower[j], lastIndex + 1);
|
4298
|
-
var i2 = caption.indexOf(upper[j], lastIndex + 1);
|
4299
|
-
index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
|
4300
|
-
if (index < 0)
|
4301
|
-
continue loop;
|
4302
|
-
distance = index - lastIndex - 1;
|
4303
|
-
if (distance > 0) {
|
4304
|
-
if (lastIndex === -1)
|
4305
|
-
penalty += 10;
|
4306
|
-
penalty += distance;
|
4307
|
-
}
|
4308
|
-
matchMask = matchMask | (1 << index);
|
4309
|
-
lastIndex = index;
|
4310
|
-
}
|
4311
|
-
item.matchMask = matchMask;
|
4312
|
-
item.exactMatch = penalty ? 0 : 1;
|
4313
|
-
item.score = (item.score || 0) - penalty;
|
4314
|
-
results.push(item);
|
4315
|
-
}
|
4316
|
-
return results;
|
4317
|
-
};
|
4318
|
-
}).call(FilteredList.prototype);
|
4319
|
-
|
4320
|
-
exports.Autocomplete = Autocomplete;
|
4321
|
-
exports.FilteredList = FilteredList;
|
4322
|
-
|
4323
|
-
});
|
4324
|
-
|
4325
|
-
define("ace/autocomplete/text_completer",["require","exports","module","ace/range"], function(require, exports, module) {
|
4326
|
-
var Range = require("../range").Range;
|
4327
|
-
|
4328
|
-
var splitRegex = /[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/;
|
4329
|
-
|
4330
|
-
function getWordIndex(doc, pos) {
|
4331
|
-
var textBefore = doc.getTextRange(Range.fromPoints({row: 0, column:0}, pos));
|
4332
|
-
return textBefore.split(splitRegex).length - 1;
|
4333
|
-
}
|
4334
|
-
function wordDistance(doc, pos) {
|
4335
|
-
var prefixPos = getWordIndex(doc, pos);
|
4336
|
-
var words = doc.getValue().split(splitRegex);
|
4337
|
-
var wordScores = Object.create(null);
|
4338
|
-
|
4339
|
-
var currentWord = words[prefixPos];
|
4340
|
-
|
4341
|
-
words.forEach(function(word, idx) {
|
4342
|
-
if (!word || word === currentWord) return;
|
4343
|
-
|
4344
|
-
var distance = Math.abs(prefixPos - idx);
|
4345
|
-
var score = words.length - distance;
|
4346
|
-
if (wordScores[word]) {
|
4347
|
-
wordScores[word] = Math.max(score, wordScores[word]);
|
4348
|
-
} else {
|
4349
|
-
wordScores[word] = score;
|
4350
|
-
}
|
4351
|
-
});
|
4352
|
-
return wordScores;
|
4353
|
-
}
|
4354
|
-
|
4355
|
-
exports.getCompletions = function(editor, session, pos, prefix, callback) {
|
4356
|
-
var wordScore = wordDistance(session, pos, prefix);
|
4357
|
-
var wordList = Object.keys(wordScore);
|
4358
|
-
callback(null, wordList.map(function(word) {
|
4359
|
-
return {
|
4360
|
-
caption: word,
|
4361
|
-
value: word,
|
4362
|
-
score: wordScore[word],
|
4363
|
-
meta: "local"
|
4364
|
-
};
|
4365
|
-
}));
|
4366
|
-
};
|
4367
|
-
});
|
4368
|
-
|
4369
|
-
define("ace/ext/language_tools",["require","exports","module","ace/snippets","ace/autocomplete","ace/config","ace/autocomplete/util","ace/autocomplete/text_completer","ace/editor","ace/config"], function(require, exports, module) {
|
4370
|
-
"use strict";
|
4371
|
-
|
4372
|
-
var snippetManager = require("../snippets").snippetManager;
|
4373
|
-
var Autocomplete = require("../autocomplete").Autocomplete;
|
4374
|
-
var config = require("../config");
|
4375
|
-
var util = require("../autocomplete/util");
|
4376
|
-
|
4377
|
-
var textCompleter = require("../autocomplete/text_completer");
|
4378
|
-
var keyWordCompleter = {
|
4379
|
-
getCompletions: function(editor, session, pos, prefix, callback) {
|
4380
|
-
var state = editor.session.getState(pos.row);
|
4381
|
-
var completions = session.$mode.getCompletions(state, session, pos, prefix);
|
4382
|
-
callback(null, completions);
|
4383
|
-
}
|
4384
|
-
};
|
4385
|
-
|
4386
|
-
var snippetCompleter = {
|
4387
|
-
getCompletions: function(editor, session, pos, prefix, callback) {
|
4388
|
-
var snippetMap = snippetManager.snippetMap;
|
4389
|
-
var completions = [];
|
4390
|
-
snippetManager.getActiveScopes(editor).forEach(function(scope) {
|
4391
|
-
var snippets = snippetMap[scope] || [];
|
4392
|
-
for (var i = snippets.length; i--;) {
|
4393
|
-
var s = snippets[i];
|
4394
|
-
var caption = s.name || s.tabTrigger;
|
4395
|
-
if (!caption)
|
4396
|
-
continue;
|
4397
|
-
completions.push({
|
4398
|
-
caption: caption,
|
4399
|
-
snippet: s.content,
|
4400
|
-
meta: s.tabTrigger && !s.name ? s.tabTrigger + "\u21E5 " : "snippet"
|
4401
|
-
});
|
4402
|
-
}
|
4403
|
-
}, this);
|
4404
|
-
callback(null, completions);
|
4405
|
-
}
|
4406
|
-
};
|
4407
|
-
|
4408
|
-
var completers = [snippetCompleter, textCompleter, keyWordCompleter];
|
4409
|
-
exports.addCompleter = function(completer) {
|
4410
|
-
completers.push(completer);
|
4411
|
-
};
|
4412
|
-
exports.textCompleter = textCompleter;
|
4413
|
-
exports.keyWordCompleter = keyWordCompleter;
|
4414
|
-
exports.snippetCompleter = snippetCompleter;
|
4415
|
-
|
4416
|
-
var expandSnippet = {
|
4417
|
-
name: "expandSnippet",
|
4418
|
-
exec: function(editor) {
|
4419
|
-
var success = snippetManager.expandWithTab(editor);
|
4420
|
-
if (!success)
|
4421
|
-
editor.execCommand("indent");
|
4422
|
-
},
|
4423
|
-
bindKey: "Tab"
|
4424
|
-
};
|
4425
|
-
|
4426
|
-
var onChangeMode = function(e, editor) {
|
4427
|
-
loadSnippetsForMode(editor.session.$mode);
|
4428
|
-
};
|
4429
|
-
|
4430
|
-
var loadSnippetsForMode = function(mode) {
|
4431
|
-
var id = mode.$id;
|
4432
|
-
if (!snippetManager.files)
|
4433
|
-
snippetManager.files = {};
|
4434
|
-
loadSnippetFile(id);
|
4435
|
-
if (mode.modes)
|
4436
|
-
mode.modes.forEach(loadSnippetsForMode);
|
4437
|
-
};
|
4438
|
-
|
4439
|
-
var loadSnippetFile = function(id) {
|
4440
|
-
if (!id || snippetManager.files[id])
|
4441
|
-
return;
|
4442
|
-
var snippetFilePath = id.replace("mode", "snippets");
|
4443
|
-
snippetManager.files[id] = {};
|
4444
|
-
config.loadModule(snippetFilePath, function(m) {
|
4445
|
-
if (m) {
|
4446
|
-
snippetManager.files[id] = m;
|
4447
|
-
if (!m.snippets && m.snippetText)
|
4448
|
-
m.snippets = snippetManager.parseSnippetFile(m.snippetText);
|
4449
|
-
snippetManager.register(m.snippets || [], m.scope);
|
4450
|
-
if (m.includeScopes) {
|
4451
|
-
snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
|
4452
|
-
m.includeScopes.forEach(function(x) {
|
4453
|
-
loadSnippetFile("ace/mode/" + x);
|
4454
|
-
});
|
4455
|
-
}
|
4456
|
-
}
|
4457
|
-
});
|
4458
|
-
};
|
4459
|
-
|
4460
|
-
function getCompletionPrefix(editor) {
|
4461
|
-
var pos = editor.getCursorPosition();
|
4462
|
-
var line = editor.session.getLine(pos.row);
|
4463
|
-
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
4464
|
-
editor.completers.forEach(function(completer) {
|
4465
|
-
if (completer.identifierRegexps) {
|
4466
|
-
completer.identifierRegexps.forEach(function(identifierRegex) {
|
4467
|
-
if (!prefix && identifierRegex)
|
4468
|
-
prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
|
4469
|
-
});
|
4470
|
-
}
|
4471
|
-
});
|
4472
|
-
return prefix;
|
4473
|
-
}
|
4474
|
-
|
4475
|
-
var doLiveAutocomplete = function(e) {
|
4476
|
-
var editor = e.editor;
|
4477
|
-
var text = e.args || "";
|
4478
|
-
var hasCompleter = editor.completer && editor.completer.activated;
|
4479
|
-
if (e.command.name === "backspace") {
|
4480
|
-
if (hasCompleter && !getCompletionPrefix(editor))
|
4481
|
-
editor.completer.detach();
|
4482
|
-
}
|
4483
|
-
else if (e.command.name === "insertstring") {
|
4484
|
-
var prefix = getCompletionPrefix(editor);
|
4485
|
-
if (prefix && !hasCompleter) {
|
4486
|
-
if (!editor.completer) {
|
4487
|
-
editor.completer = new Autocomplete();
|
4488
|
-
}
|
4489
|
-
editor.completer.autoSelect = false;
|
4490
|
-
editor.completer.autoInsert = false;
|
4491
|
-
editor.completer.showPopup(editor);
|
4492
|
-
}
|
4493
|
-
}
|
4494
|
-
};
|
4495
|
-
|
4496
|
-
var Editor = require("../editor").Editor;
|
4497
|
-
require("../config").defineOptions(Editor.prototype, "editor", {
|
4498
|
-
enableBasicAutocompletion: {
|
4499
|
-
set: function(val) {
|
4500
|
-
if (val) {
|
4501
|
-
if (!this.completers)
|
4502
|
-
this.completers = Array.isArray(val)? val: completers;
|
4503
|
-
this.commands.addCommand(Autocomplete.startCommand);
|
4504
|
-
} else {
|
4505
|
-
this.commands.removeCommand(Autocomplete.startCommand);
|
4506
|
-
}
|
4507
|
-
},
|
4508
|
-
value: false
|
4509
|
-
},
|
4510
|
-
enableLiveAutocompletion: {
|
4511
|
-
set: function(val) {
|
4512
|
-
if (val) {
|
4513
|
-
if (!this.completers)
|
4514
|
-
this.completers = Array.isArray(val)? val: completers;
|
4515
|
-
this.commands.on('afterExec', doLiveAutocomplete);
|
4516
|
-
} else {
|
4517
|
-
this.commands.removeListener('afterExec', doLiveAutocomplete);
|
4518
|
-
}
|
4519
|
-
},
|
4520
|
-
value: false
|
4521
|
-
},
|
4522
|
-
enableSnippets: {
|
4523
|
-
set: function(val) {
|
4524
|
-
if (val) {
|
4525
|
-
this.commands.addCommand(expandSnippet);
|
4526
|
-
this.on("changeMode", onChangeMode);
|
4527
|
-
onChangeMode(null, this);
|
4528
|
-
} else {
|
4529
|
-
this.commands.removeCommand(expandSnippet);
|
4530
|
-
this.off("changeMode", onChangeMode);
|
4531
|
-
}
|
4532
|
-
},
|
4533
|
-
value: false
|
4534
|
-
}
|
4535
|
-
});
|
4536
|
-
});
|
4537
|
-
|
4538
|
-
define("ace/mode/xquery",["require","exports","module","ace/worker/worker_client","ace/lib/oop","ace/mode/text","ace/mode/text_highlight_rules","ace/mode/xquery/xquery_lexer","ace/range","ace/mode/behaviour/xquery","ace/mode/folding/cstyle","ace/anchor","ace/ext/language_tools"], function(require, exports, module) {
|
2749
|
+
define("ace/mode/xquery",["require","exports","module","ace/worker/worker_client","ace/lib/oop","ace/mode/text","ace/mode/text_highlight_rules","ace/mode/xquery/xquery_lexer","ace/range","ace/mode/behaviour/xquery","ace/mode/folding/cstyle","ace/anchor"], function(require, exports, module) {
|
4539
2750
|
"use strict";
|
4540
2751
|
|
4541
2752
|
var WorkerClient = require("../worker/worker_client").WorkerClient;
|
@@ -4547,7 +2758,6 @@ var Range = require("../range").Range;
|
|
4547
2758
|
var XQueryBehaviour = require("./behaviour/xquery").XQueryBehaviour;
|
4548
2759
|
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
4549
2760
|
var Anchor = require("../anchor").Anchor;
|
4550
|
-
var LanguageTools = require("../ext/language_tools");
|
4551
2761
|
|
4552
2762
|
var Mode = function() {
|
4553
2763
|
this.$tokenizer = new XQueryLexer();
|
@@ -4559,14 +2769,16 @@ oop.inherits(Mode, TextMode);
|
|
4559
2769
|
|
4560
2770
|
(function() {
|
4561
2771
|
|
4562
|
-
|
2772
|
+
this.completer = {
|
4563
2773
|
getCompletions: function(editor, session, pos, prefix, callback) {
|
2774
|
+
if (!session.$worker)
|
2775
|
+
return callback();
|
4564
2776
|
session.$worker.emit("complete", { data: { pos: pos, prefix: prefix } });
|
4565
2777
|
session.$worker.on("complete", function(e){
|
4566
2778
|
callback(null, e.data);
|
4567
2779
|
});
|
4568
2780
|
}
|
4569
|
-
}
|
2781
|
+
};
|
4570
2782
|
|
4571
2783
|
this.getNextLineIndent = function(state, line, tab) {
|
4572
2784
|
var indent = this.$getIndent(line);
|