ace-rails-ap 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ace/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/ace/ace.js +403 -326
  4. data/vendor/assets/javascripts/ace/ext-language_tools.js +56 -40
  5. data/vendor/assets/javascripts/ace/ext-modelist.js +7 -3
  6. data/vendor/assets/javascripts/ace/ext-settings_menu.js +8 -4
  7. data/vendor/assets/javascripts/ace/ext-static_highlight.js +12 -5
  8. data/vendor/assets/javascripts/ace/keybinding-vim.js +5234 -1558
  9. data/vendor/assets/javascripts/ace/mode-abap.js +1 -1
  10. data/vendor/assets/javascripts/ace/mode-abc.js +261 -0
  11. data/vendor/assets/javascripts/ace/mode-actionscript.js +47 -1
  12. data/vendor/assets/javascripts/ace/mode-apache_conf.js +47 -1
  13. data/vendor/assets/javascripts/ace/mode-applescript.js +47 -1
  14. data/vendor/assets/javascripts/ace/mode-autohotkey.js +47 -1
  15. data/vendor/assets/javascripts/ace/mode-batchfile.js +47 -1
  16. data/vendor/assets/javascripts/ace/mode-c_cpp.js +101 -56
  17. data/vendor/assets/javascripts/ace/mode-coffee.js +3 -3
  18. data/vendor/assets/javascripts/ace/mode-coldfusion.js +114 -63
  19. data/vendor/assets/javascripts/ace/mode-csharp.js +99 -55
  20. data/vendor/assets/javascripts/ace/mode-css.js +98 -53
  21. data/vendor/assets/javascripts/ace/mode-curly.js +114 -63
  22. data/vendor/assets/javascripts/ace/mode-d.js +47 -1
  23. data/vendor/assets/javascripts/ace/mode-dart.js +103 -58
  24. data/vendor/assets/javascripts/ace/mode-diff.js +85 -85
  25. data/vendor/assets/javascripts/ace/mode-django.js +114 -63
  26. data/vendor/assets/javascripts/ace/mode-dockerfile.js +97 -52
  27. data/vendor/assets/javascripts/ace/mode-dot.js +47 -1
  28. data/vendor/assets/javascripts/ace/mode-eiffel.js +30 -37
  29. data/vendor/assets/javascripts/ace/mode-ejs.js +117 -63
  30. data/vendor/assets/javascripts/ace/mode-elm.js +47 -1
  31. data/vendor/assets/javascripts/ace/mode-erlang.js +47 -1
  32. data/vendor/assets/javascripts/ace/mode-forth.js +47 -1
  33. data/vendor/assets/javascripts/ace/mode-ftl.js +10 -7
  34. data/vendor/assets/javascripts/ace/mode-glsl.js +101 -56
  35. data/vendor/assets/javascripts/ace/mode-golang.js +96 -51
  36. data/vendor/assets/javascripts/ace/mode-groovy.js +98 -53
  37. data/vendor/assets/javascripts/ace/mode-haml.js +3 -0
  38. data/vendor/assets/javascripts/ace/mode-handlebars.js +114 -63
  39. data/vendor/assets/javascripts/ace/mode-haskell.js +49 -3
  40. data/vendor/assets/javascripts/ace/mode-haxe.js +96 -51
  41. data/vendor/assets/javascripts/ace/mode-html.js +114 -63
  42. data/vendor/assets/javascripts/ace/mode-html_ruby.js +117 -63
  43. data/vendor/assets/javascripts/ace/mode-io.js +47 -1
  44. data/vendor/assets/javascripts/ace/mode-jack.js +96 -51
  45. data/vendor/assets/javascripts/ace/mode-jade.js +10 -7
  46. data/vendor/assets/javascripts/ace/mode-java.js +98 -53
  47. data/vendor/assets/javascripts/ace/mode-javascript.js +98 -53
  48. data/vendor/assets/javascripts/ace/mode-json.js +99 -54
  49. data/vendor/assets/javascripts/ace/mode-jsoniq.js +98 -51
  50. data/vendor/assets/javascripts/ace/mode-jsp.js +106 -58
  51. data/vendor/assets/javascripts/ace/mode-jsx.js +96 -51
  52. data/vendor/assets/javascripts/ace/mode-julia.js +47 -1
  53. data/vendor/assets/javascripts/ace/mode-latex.js +1 -1
  54. data/vendor/assets/javascripts/ace/mode-lean.js +281 -0
  55. data/vendor/assets/javascripts/ace/mode-less.js +96 -51
  56. data/vendor/assets/javascripts/ace/mode-liquid.js +10 -7
  57. data/vendor/assets/javascripts/ace/mode-live_script.js +481 -0
  58. data/vendor/assets/javascripts/ace/mode-livescript.js +5 -8
  59. data/vendor/assets/javascripts/ace/mode-logiql.js +49 -50
  60. data/vendor/assets/javascripts/ace/mode-lsl.js +96 -51
  61. data/vendor/assets/javascripts/ace/mode-lua.js +3 -3
  62. data/vendor/assets/javascripts/ace/mode-luapage.js +117 -66
  63. data/vendor/assets/javascripts/ace/mode-makefile.js +1 -1
  64. data/vendor/assets/javascripts/ace/mode-markdown.js +134 -67
  65. data/vendor/assets/javascripts/ace/mode-mask.js +1985 -0
  66. data/vendor/assets/javascripts/ace/mode-mel.js +96 -51
  67. data/vendor/assets/javascripts/ace/mode-mips_assembler.js +235 -0
  68. data/vendor/assets/javascripts/ace/mode-mipsassembler.js +196 -0
  69. data/vendor/assets/javascripts/ace/mode-nix.js +101 -56
  70. data/vendor/assets/javascripts/ace/mode-objectivec.js +52 -6
  71. data/vendor/assets/javascripts/ace/mode-perl.js +47 -1
  72. data/vendor/assets/javascripts/ace/mode-pgsql.js +1 -1
  73. data/vendor/assets/javascripts/ace/mode-php.js +139 -85
  74. data/vendor/assets/javascripts/ace/mode-powershell.js +96 -51
  75. data/vendor/assets/javascripts/ace/mode-praat.js +47 -1
  76. data/vendor/assets/javascripts/ace/mode-prolog.js +47 -1
  77. data/vendor/assets/javascripts/ace/mode-protobuf.js +101 -56
  78. data/vendor/assets/javascripts/ace/mode-rdoc.js +1 -1
  79. data/vendor/assets/javascripts/ace/mode-rhtml.js +114 -63
  80. data/vendor/assets/javascripts/ace/mode-ruby.js +52 -50
  81. data/vendor/assets/javascripts/ace/mode-rust.js +57 -18
  82. data/vendor/assets/javascripts/ace/mode-scad.js +96 -51
  83. data/vendor/assets/javascripts/ace/mode-scala.js +98 -53
  84. data/vendor/assets/javascripts/ace/mode-scss.js +96 -51
  85. data/vendor/assets/javascripts/ace/mode-sh.js +97 -52
  86. data/vendor/assets/javascripts/ace/mode-sjs.js +98 -53
  87. data/vendor/assets/javascripts/ace/mode-smarty.js +114 -63
  88. data/vendor/assets/javascripts/ace/mode-soy_template.js +114 -63
  89. data/vendor/assets/javascripts/ace/mode-stylus.js +1 -1
  90. data/vendor/assets/javascripts/ace/mode-svg.js +132 -65
  91. data/vendor/assets/javascripts/ace/mode-tcl.js +47 -1
  92. data/vendor/assets/javascripts/ace/mode-twig.js +114 -63
  93. data/vendor/assets/javascripts/ace/mode-typescript.js +98 -53
  94. data/vendor/assets/javascripts/ace/mode-vala.js +96 -51
  95. data/vendor/assets/javascripts/ace/mode-velocity.js +114 -63
  96. data/vendor/assets/javascripts/ace/mode-vhdl.js +21 -21
  97. data/vendor/assets/javascripts/ace/mode-xml.js +34 -12
  98. data/vendor/assets/javascripts/ace/mode-xquery.js +98 -51
  99. data/vendor/assets/javascripts/ace/snippets/abc.js +38 -0
  100. data/vendor/assets/javascripts/ace/snippets/elixir.js +7 -0
  101. data/vendor/assets/javascripts/ace/snippets/elm.js +7 -0
  102. data/vendor/assets/javascripts/ace/snippets/lean.js +7 -0
  103. data/vendor/assets/javascripts/ace/snippets/live_script.js +7 -0
  104. data/vendor/assets/javascripts/ace/snippets/mask.js +7 -0
  105. data/vendor/assets/javascripts/ace/snippets/mips_assembler.js +7 -0
  106. data/vendor/assets/javascripts/ace/snippets/mipsassembler.js +7 -0
  107. data/vendor/assets/javascripts/ace/snippets/r.js +1 -1
  108. data/vendor/assets/javascripts/ace/theme-clouds_midnight.js +1 -1
  109. data/vendor/assets/javascripts/ace/theme-github.js +7 -1
  110. data/vendor/assets/javascripts/ace/theme-katzenmilch.js +3 -0
  111. data/vendor/assets/javascripts/ace/theme-kuroir.js +3 -0
  112. data/vendor/assets/javascripts/ace/worker-coffee.js +6 -7
  113. data/vendor/assets/javascripts/ace/worker-css.js +5 -5
  114. data/vendor/assets/javascripts/ace/worker-html.js +4354 -4354
  115. data/vendor/assets/javascripts/ace/worker-javascript.js +2435 -1397
  116. data/vendor/assets/javascripts/ace/worker-json.js +6 -7
  117. data/vendor/assets/javascripts/ace/worker-lua.js +11 -11
  118. data/vendor/assets/javascripts/ace/worker-php.js +4 -8
  119. data/vendor/assets/javascripts/ace/worker-xml.js +3809 -0
  120. data/vendor/assets/javascripts/ace/worker-xquery.js +38 -47
  121. metadata +18 -9
  122. data/vendor/assets/javascripts/ace/ext-options.js +0 -252
  123. data/vendor/assets/javascripts/ace/mode-html_completions.js +0 -309
  124. data/vendor/assets/javascripts/ace/mode-luahtml.js +0 -2415
  125. data/vendor/assets/javascripts/ace/mode-mushcode_high_rules.js +0 -569
  126. data/vendor/assets/javascripts/ace/mode-tmsnippet.js +0 -200
  127. data/vendor/assets/javascripts/ace/theme-kr.js +0 -105
@@ -327,6 +327,19 @@ var initContext = function(editor) {
327
327
  };
328
328
  };
329
329
 
330
+ var getWrapped = function(selection, selected, opening, closing) {
331
+ var rowDiff = selection.end.row - selection.start.row;
332
+ return {
333
+ text: opening + selected + closing,
334
+ selection: [
335
+ 0,
336
+ selection.start.column + 1,
337
+ rowDiff,
338
+ selection.end.column + (rowDiff ? 0 : 1)
339
+ ]
340
+ };
341
+ };
342
+
330
343
  var CstyleBehaviour = function() {
331
344
  this.add("braces", "insertion", function(state, action, editor, session, text) {
332
345
  var cursor = editor.getCursorPosition();
@@ -336,10 +349,7 @@ var CstyleBehaviour = function() {
336
349
  var selection = editor.getSelectionRange();
337
350
  var selected = session.doc.getTextRange(selection);
338
351
  if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
339
- return {
340
- text: '{' + selected + '}',
341
- selection: false
342
- };
352
+ return getWrapped(selection, selected, '{', '}');
343
353
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
344
354
  if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
345
355
  CstyleBehaviour.recordAutoInsert(editor, session, "}");
@@ -419,10 +429,7 @@ var CstyleBehaviour = function() {
419
429
  var selection = editor.getSelectionRange();
420
430
  var selected = session.doc.getTextRange(selection);
421
431
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
422
- return {
423
- text: '(' + selected + ')',
424
- selection: false
425
- };
432
+ return getWrapped(selection, selected, '(', ')');
426
433
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
427
434
  CstyleBehaviour.recordAutoInsert(editor, session, ")");
428
435
  return {
@@ -467,10 +474,7 @@ var CstyleBehaviour = function() {
467
474
  var selection = editor.getSelectionRange();
468
475
  var selected = session.doc.getTextRange(selection);
469
476
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
470
- return {
471
- text: '[' + selected + ']',
472
- selection: false
473
- };
477
+ return getWrapped(selection, selected, '[', ']');
474
478
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
475
479
  CstyleBehaviour.recordAutoInsert(editor, session, "]");
476
480
  return {
@@ -516,49 +520,44 @@ var CstyleBehaviour = function() {
516
520
  var selection = editor.getSelectionRange();
517
521
  var selected = session.doc.getTextRange(selection);
518
522
  if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
519
- return {
520
- text: quote + selected + quote,
521
- selection: false
522
- };
523
- } else {
523
+ return getWrapped(selection, selected, quote, quote);
524
+ } else if (!selected) {
524
525
  var cursor = editor.getCursorPosition();
525
526
  var line = session.doc.getLine(cursor.row);
526
527
  var leftChar = line.substring(cursor.column-1, cursor.column);
527
- if (leftChar == '\\') {
528
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
529
+
530
+ var token = session.getTokenAt(cursor.row, cursor.column);
531
+ var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
532
+ if (leftChar == "\\" && token && /escape/.test(token.type))
528
533
  return null;
534
+
535
+ var stringBefore = token && /string/.test(token.type);
536
+ var stringAfter = !rightToken || /string/.test(rightToken.type);
537
+
538
+ var pair;
539
+ if (rightChar == quote) {
540
+ pair = stringBefore !== stringAfter;
541
+ } else {
542
+ if (stringBefore && !stringAfter)
543
+ return null; // wrap string with different quote
544
+ if (stringBefore && stringAfter)
545
+ return null; // do not pair quotes inside strings
546
+ var wordRe = session.$mode.tokenRe;
547
+ wordRe.lastIndex = 0;
548
+ var isWordBefore = wordRe.test(leftChar);
549
+ wordRe.lastIndex = 0;
550
+ var isWordAfter = wordRe.test(leftChar);
551
+ if (isWordBefore || isWordAfter)
552
+ return null; // before or after alphanumeric
553
+ if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
554
+ return null; // there is rightChar and it isn't closing
555
+ pair = true;
529
556
  }
530
- var tokens = session.getTokens(selection.start.row);
531
- var col = 0, token;
532
- var quotepos = -1; // Track whether we're inside an open quote.
533
-
534
- for (var x = 0; x < tokens.length; x++) {
535
- token = tokens[x];
536
- if (token.type == "string") {
537
- quotepos = -1;
538
- } else if (quotepos < 0) {
539
- quotepos = token.value.indexOf(quote);
540
- }
541
- if ((token.value.length + col) > selection.start.column) {
542
- break;
543
- }
544
- col += tokens[x].value.length;
545
- }
546
- if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
547
- if (!CstyleBehaviour.isSaneInsertion(editor, session))
548
- return;
549
- return {
550
- text: quote + quote,
551
- selection: [1,1]
552
- };
553
- } else if (token && token.type === "string") {
554
- var rightChar = line.substring(cursor.column, cursor.column + 1);
555
- if (rightChar == quote) {
556
- return {
557
- text: '',
558
- selection: [1, 1]
559
- };
560
- }
561
- }
557
+ return {
558
+ text: pair ? quote + quote : "",
559
+ selection: [1,1]
560
+ };
562
561
  }
563
562
  }
564
563
  });
@@ -749,12 +748,35 @@ var FoldMode = exports.FoldMode = function(commentRegex) {
749
748
  oop.inherits(FoldMode, BaseFoldMode);
750
749
 
751
750
  (function() {
752
-
751
+
753
752
  this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
754
753
  this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
754
+ this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
755
+ this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
756
+ this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
757
+ this._getFoldWidgetBase = this.getFoldWidget;
758
+ this.getFoldWidget = function(session, foldStyle, row) {
759
+ var line = session.getLine(row);
760
+
761
+ if (this.singleLineBlockCommentRe.test(line)) {
762
+ if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
763
+ return "";
764
+ }
765
+
766
+ var fw = this._getFoldWidgetBase(session, foldStyle, row);
767
+
768
+ if (!fw && this.startRegionRe.test(line))
769
+ return "start"; // lineCommentRegionStart
770
+
771
+ return fw;
772
+ };
755
773
 
756
774
  this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
757
775
  var line = session.getLine(row);
776
+
777
+ if (this.startRegionRe.test(line))
778
+ return this.getCommentRegionBlock(session, line, row);
779
+
758
780
  var match = line.match(this.foldingStartMarker);
759
781
  if (match) {
760
782
  var i = match.index;
@@ -819,6 +841,29 @@ oop.inherits(FoldMode, BaseFoldMode);
819
841
 
820
842
  return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
821
843
  };
844
+
845
+ this.getCommentRegionBlock = function(session, line, row) {
846
+ var startColumn = line.search(/\s*$/);
847
+ var maxRow = session.getLength();
848
+ var startRow = row;
849
+
850
+ var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
851
+ var depth = 1;
852
+ while (++row < maxRow) {
853
+ line = session.getLine(row);
854
+ var m = re.exec(line);
855
+ if (!m) continue;
856
+ if (m[1]) depth--;
857
+ else depth++;
858
+
859
+ if (!depth) break;
860
+ }
861
+
862
+ var endRow = row;
863
+ if (endRow > startRow) {
864
+ return new Range(startRow, startColumn, endRow, line.length);
865
+ }
866
+ };
822
867
 
823
868
  }).call(FoldMode.prototype);
824
869
 
@@ -73,7 +73,7 @@ var ShHighlightRules = function() {
73
73
  token : "keyword.operator"
74
74
  }, {
75
75
  stateName: "heredoc",
76
- regex : "(<<)(\\s*)(['\"`]?)([\\w\\-]+)(['\"`]?)",
76
+ regex : "(<<-?)(\\s*)(['\"`]?)([\\w\\-]+)(['\"`]?)",
77
77
  onMatch : function(value, currentState, stack) {
78
78
  var next = value[2] == '-' ? "indentedHeredoc" : "heredoc";
79
79
  var tokens = value.split(this.splitRegex);
@@ -191,12 +191,35 @@ var FoldMode = exports.FoldMode = function(commentRegex) {
191
191
  oop.inherits(FoldMode, BaseFoldMode);
192
192
 
193
193
  (function() {
194
-
194
+
195
195
  this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
196
196
  this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
197
+ this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
198
+ this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
199
+ this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
200
+ this._getFoldWidgetBase = this.getFoldWidget;
201
+ this.getFoldWidget = function(session, foldStyle, row) {
202
+ var line = session.getLine(row);
203
+
204
+ if (this.singleLineBlockCommentRe.test(line)) {
205
+ if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
206
+ return "";
207
+ }
208
+
209
+ var fw = this._getFoldWidgetBase(session, foldStyle, row);
210
+
211
+ if (!fw && this.startRegionRe.test(line))
212
+ return "start"; // lineCommentRegionStart
213
+
214
+ return fw;
215
+ };
197
216
 
198
217
  this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
199
218
  var line = session.getLine(row);
219
+
220
+ if (this.startRegionRe.test(line))
221
+ return this.getCommentRegionBlock(session, line, row);
222
+
200
223
  var match = line.match(this.foldingStartMarker);
201
224
  if (match) {
202
225
  var i = match.index;
@@ -261,6 +284,29 @@ oop.inherits(FoldMode, BaseFoldMode);
261
284
 
262
285
  return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
263
286
  };
287
+
288
+ this.getCommentRegionBlock = function(session, line, row) {
289
+ var startColumn = line.search(/\s*$/);
290
+ var maxRow = session.getLength();
291
+ var startRow = row;
292
+
293
+ var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
294
+ var depth = 1;
295
+ while (++row < maxRow) {
296
+ line = session.getLine(row);
297
+ var m = re.exec(line);
298
+ if (!m) continue;
299
+ if (m[1]) depth--;
300
+ else depth++;
301
+
302
+ if (!depth) break;
303
+ }
304
+
305
+ var endRow = row;
306
+ if (endRow > startRow) {
307
+ return new Range(startRow, startColumn, endRow, line.length);
308
+ }
309
+ };
264
310
 
265
311
  }).call(FoldMode.prototype);
266
312
 
@@ -301,6 +347,19 @@ var initContext = function(editor) {
301
347
  };
302
348
  };
303
349
 
350
+ var getWrapped = function(selection, selected, opening, closing) {
351
+ var rowDiff = selection.end.row - selection.start.row;
352
+ return {
353
+ text: opening + selected + closing,
354
+ selection: [
355
+ 0,
356
+ selection.start.column + 1,
357
+ rowDiff,
358
+ selection.end.column + (rowDiff ? 0 : 1)
359
+ ]
360
+ };
361
+ };
362
+
304
363
  var CstyleBehaviour = function() {
305
364
  this.add("braces", "insertion", function(state, action, editor, session, text) {
306
365
  var cursor = editor.getCursorPosition();
@@ -310,10 +369,7 @@ var CstyleBehaviour = function() {
310
369
  var selection = editor.getSelectionRange();
311
370
  var selected = session.doc.getTextRange(selection);
312
371
  if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
313
- return {
314
- text: '{' + selected + '}',
315
- selection: false
316
- };
372
+ return getWrapped(selection, selected, '{', '}');
317
373
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
318
374
  if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
319
375
  CstyleBehaviour.recordAutoInsert(editor, session, "}");
@@ -393,10 +449,7 @@ var CstyleBehaviour = function() {
393
449
  var selection = editor.getSelectionRange();
394
450
  var selected = session.doc.getTextRange(selection);
395
451
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
396
- return {
397
- text: '(' + selected + ')',
398
- selection: false
399
- };
452
+ return getWrapped(selection, selected, '(', ')');
400
453
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
401
454
  CstyleBehaviour.recordAutoInsert(editor, session, ")");
402
455
  return {
@@ -441,10 +494,7 @@ var CstyleBehaviour = function() {
441
494
  var selection = editor.getSelectionRange();
442
495
  var selected = session.doc.getTextRange(selection);
443
496
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
444
- return {
445
- text: '[' + selected + ']',
446
- selection: false
447
- };
497
+ return getWrapped(selection, selected, '[', ']');
448
498
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
449
499
  CstyleBehaviour.recordAutoInsert(editor, session, "]");
450
500
  return {
@@ -490,49 +540,44 @@ var CstyleBehaviour = function() {
490
540
  var selection = editor.getSelectionRange();
491
541
  var selected = session.doc.getTextRange(selection);
492
542
  if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
493
- return {
494
- text: quote + selected + quote,
495
- selection: false
496
- };
497
- } else {
543
+ return getWrapped(selection, selected, quote, quote);
544
+ } else if (!selected) {
498
545
  var cursor = editor.getCursorPosition();
499
546
  var line = session.doc.getLine(cursor.row);
500
547
  var leftChar = line.substring(cursor.column-1, cursor.column);
501
- if (leftChar == '\\') {
548
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
549
+
550
+ var token = session.getTokenAt(cursor.row, cursor.column);
551
+ var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
552
+ if (leftChar == "\\" && token && /escape/.test(token.type))
502
553
  return null;
554
+
555
+ var stringBefore = token && /string/.test(token.type);
556
+ var stringAfter = !rightToken || /string/.test(rightToken.type);
557
+
558
+ var pair;
559
+ if (rightChar == quote) {
560
+ pair = stringBefore !== stringAfter;
561
+ } else {
562
+ if (stringBefore && !stringAfter)
563
+ return null; // wrap string with different quote
564
+ if (stringBefore && stringAfter)
565
+ return null; // do not pair quotes inside strings
566
+ var wordRe = session.$mode.tokenRe;
567
+ wordRe.lastIndex = 0;
568
+ var isWordBefore = wordRe.test(leftChar);
569
+ wordRe.lastIndex = 0;
570
+ var isWordAfter = wordRe.test(leftChar);
571
+ if (isWordBefore || isWordAfter)
572
+ return null; // before or after alphanumeric
573
+ if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
574
+ return null; // there is rightChar and it isn't closing
575
+ pair = true;
503
576
  }
504
- var tokens = session.getTokens(selection.start.row);
505
- var col = 0, token;
506
- var quotepos = -1; // Track whether we're inside an open quote.
507
-
508
- for (var x = 0; x < tokens.length; x++) {
509
- token = tokens[x];
510
- if (token.type == "string") {
511
- quotepos = -1;
512
- } else if (quotepos < 0) {
513
- quotepos = token.value.indexOf(quote);
514
- }
515
- if ((token.value.length + col) > selection.start.column) {
516
- break;
517
- }
518
- col += tokens[x].value.length;
519
- }
520
- if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
521
- if (!CstyleBehaviour.isSaneInsertion(editor, session))
522
- return;
523
- return {
524
- text: quote + quote,
525
- selection: [1,1]
526
- };
527
- } else if (token && token.type === "string") {
528
- var rightChar = line.substring(cursor.column, cursor.column + 1);
529
- if (rightChar == quote) {
530
- return {
531
- text: '',
532
- selection: [1, 1]
533
- };
534
- }
535
- }
577
+ return {
578
+ text: pair ? quote + quote : "",
579
+ selection: [1,1]
580
+ };
536
581
  }
537
582
  }
538
583
  });
@@ -176,7 +176,7 @@ var JavaScriptHighlightRules = function(options) {
176
176
  regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/
177
177
  }, {
178
178
  token : ["punctuation.operator", "support.function.dom"],
179
- regex : /(\.)(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/
179
+ regex : /(\.)(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName|ClassName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/
180
180
  }, {
181
181
  token : ["punctuation.operator", "support.constant"],
182
182
  regex : /(\.)(s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/
@@ -475,6 +475,19 @@ var initContext = function(editor) {
475
475
  };
476
476
  };
477
477
 
478
+ var getWrapped = function(selection, selected, opening, closing) {
479
+ var rowDiff = selection.end.row - selection.start.row;
480
+ return {
481
+ text: opening + selected + closing,
482
+ selection: [
483
+ 0,
484
+ selection.start.column + 1,
485
+ rowDiff,
486
+ selection.end.column + (rowDiff ? 0 : 1)
487
+ ]
488
+ };
489
+ };
490
+
478
491
  var CstyleBehaviour = function() {
479
492
  this.add("braces", "insertion", function(state, action, editor, session, text) {
480
493
  var cursor = editor.getCursorPosition();
@@ -484,10 +497,7 @@ var CstyleBehaviour = function() {
484
497
  var selection = editor.getSelectionRange();
485
498
  var selected = session.doc.getTextRange(selection);
486
499
  if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
487
- return {
488
- text: '{' + selected + '}',
489
- selection: false
490
- };
500
+ return getWrapped(selection, selected, '{', '}');
491
501
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
492
502
  if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
493
503
  CstyleBehaviour.recordAutoInsert(editor, session, "}");
@@ -567,10 +577,7 @@ var CstyleBehaviour = function() {
567
577
  var selection = editor.getSelectionRange();
568
578
  var selected = session.doc.getTextRange(selection);
569
579
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
570
- return {
571
- text: '(' + selected + ')',
572
- selection: false
573
- };
580
+ return getWrapped(selection, selected, '(', ')');
574
581
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
575
582
  CstyleBehaviour.recordAutoInsert(editor, session, ")");
576
583
  return {
@@ -615,10 +622,7 @@ var CstyleBehaviour = function() {
615
622
  var selection = editor.getSelectionRange();
616
623
  var selected = session.doc.getTextRange(selection);
617
624
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
618
- return {
619
- text: '[' + selected + ']',
620
- selection: false
621
- };
625
+ return getWrapped(selection, selected, '[', ']');
622
626
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
623
627
  CstyleBehaviour.recordAutoInsert(editor, session, "]");
624
628
  return {
@@ -664,49 +668,44 @@ var CstyleBehaviour = function() {
664
668
  var selection = editor.getSelectionRange();
665
669
  var selected = session.doc.getTextRange(selection);
666
670
  if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
667
- return {
668
- text: quote + selected + quote,
669
- selection: false
670
- };
671
- } else {
671
+ return getWrapped(selection, selected, quote, quote);
672
+ } else if (!selected) {
672
673
  var cursor = editor.getCursorPosition();
673
674
  var line = session.doc.getLine(cursor.row);
674
675
  var leftChar = line.substring(cursor.column-1, cursor.column);
675
- if (leftChar == '\\') {
676
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
677
+
678
+ var token = session.getTokenAt(cursor.row, cursor.column);
679
+ var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
680
+ if (leftChar == "\\" && token && /escape/.test(token.type))
676
681
  return null;
682
+
683
+ var stringBefore = token && /string/.test(token.type);
684
+ var stringAfter = !rightToken || /string/.test(rightToken.type);
685
+
686
+ var pair;
687
+ if (rightChar == quote) {
688
+ pair = stringBefore !== stringAfter;
689
+ } else {
690
+ if (stringBefore && !stringAfter)
691
+ return null; // wrap string with different quote
692
+ if (stringBefore && stringAfter)
693
+ return null; // do not pair quotes inside strings
694
+ var wordRe = session.$mode.tokenRe;
695
+ wordRe.lastIndex = 0;
696
+ var isWordBefore = wordRe.test(leftChar);
697
+ wordRe.lastIndex = 0;
698
+ var isWordAfter = wordRe.test(leftChar);
699
+ if (isWordBefore || isWordAfter)
700
+ return null; // before or after alphanumeric
701
+ if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
702
+ return null; // there is rightChar and it isn't closing
703
+ pair = true;
677
704
  }
678
- var tokens = session.getTokens(selection.start.row);
679
- var col = 0, token;
680
- var quotepos = -1; // Track whether we're inside an open quote.
681
-
682
- for (var x = 0; x < tokens.length; x++) {
683
- token = tokens[x];
684
- if (token.type == "string") {
685
- quotepos = -1;
686
- } else if (quotepos < 0) {
687
- quotepos = token.value.indexOf(quote);
688
- }
689
- if ((token.value.length + col) > selection.start.column) {
690
- break;
691
- }
692
- col += tokens[x].value.length;
693
- }
694
- if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
695
- if (!CstyleBehaviour.isSaneInsertion(editor, session))
696
- return;
697
- return {
698
- text: quote + quote,
699
- selection: [1,1]
700
- };
701
- } else if (token && token.type === "string") {
702
- var rightChar = line.substring(cursor.column, cursor.column + 1);
703
- if (rightChar == quote) {
704
- return {
705
- text: '',
706
- selection: [1, 1]
707
- };
708
- }
709
- }
705
+ return {
706
+ text: pair ? quote + quote : "",
707
+ selection: [1,1]
708
+ };
710
709
  }
711
710
  }
712
711
  });
@@ -818,12 +817,35 @@ var FoldMode = exports.FoldMode = function(commentRegex) {
818
817
  oop.inherits(FoldMode, BaseFoldMode);
819
818
 
820
819
  (function() {
821
-
820
+
822
821
  this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
823
822
  this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
823
+ this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
824
+ this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
825
+ this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
826
+ this._getFoldWidgetBase = this.getFoldWidget;
827
+ this.getFoldWidget = function(session, foldStyle, row) {
828
+ var line = session.getLine(row);
829
+
830
+ if (this.singleLineBlockCommentRe.test(line)) {
831
+ if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
832
+ return "";
833
+ }
834
+
835
+ var fw = this._getFoldWidgetBase(session, foldStyle, row);
836
+
837
+ if (!fw && this.startRegionRe.test(line))
838
+ return "start"; // lineCommentRegionStart
839
+
840
+ return fw;
841
+ };
824
842
 
825
843
  this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
826
844
  var line = session.getLine(row);
845
+
846
+ if (this.startRegionRe.test(line))
847
+ return this.getCommentRegionBlock(session, line, row);
848
+
827
849
  var match = line.match(this.foldingStartMarker);
828
850
  if (match) {
829
851
  var i = match.index;
@@ -888,6 +910,29 @@ oop.inherits(FoldMode, BaseFoldMode);
888
910
 
889
911
  return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
890
912
  };
913
+
914
+ this.getCommentRegionBlock = function(session, line, row) {
915
+ var startColumn = line.search(/\s*$/);
916
+ var maxRow = session.getLength();
917
+ var startRow = row;
918
+
919
+ var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
920
+ var depth = 1;
921
+ while (++row < maxRow) {
922
+ line = session.getLine(row);
923
+ var m = re.exec(line);
924
+ if (!m) continue;
925
+ if (m[1]) depth--;
926
+ else depth++;
927
+
928
+ if (!depth) break;
929
+ }
930
+
931
+ var endRow = row;
932
+ if (endRow > startRow) {
933
+ return new Range(startRow, startColumn, endRow, line.length);
934
+ }
935
+ };
891
936
 
892
937
  }).call(FoldMode.prototype);
893
938
 
@@ -963,7 +1008,7 @@ oop.inherits(Mode, TextMode);
963
1008
  var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
964
1009
  worker.attachToDocument(session.getDocument());
965
1010
 
966
- worker.on("jslint", function(results) {
1011
+ worker.on("annotate", function(results) {
967
1012
  session.setAnnotations(results.data);
968
1013
  });
969
1014