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
@@ -141,6 +141,19 @@ var initContext = function(editor) {
141
141
  };
142
142
  };
143
143
 
144
+ var getWrapped = function(selection, selected, opening, closing) {
145
+ var rowDiff = selection.end.row - selection.start.row;
146
+ return {
147
+ text: opening + selected + closing,
148
+ selection: [
149
+ 0,
150
+ selection.start.column + 1,
151
+ rowDiff,
152
+ selection.end.column + (rowDiff ? 0 : 1)
153
+ ]
154
+ };
155
+ };
156
+
144
157
  var CstyleBehaviour = function() {
145
158
  this.add("braces", "insertion", function(state, action, editor, session, text) {
146
159
  var cursor = editor.getCursorPosition();
@@ -150,10 +163,7 @@ var CstyleBehaviour = function() {
150
163
  var selection = editor.getSelectionRange();
151
164
  var selected = session.doc.getTextRange(selection);
152
165
  if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
153
- return {
154
- text: '{' + selected + '}',
155
- selection: false
156
- };
166
+ return getWrapped(selection, selected, '{', '}');
157
167
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
158
168
  if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
159
169
  CstyleBehaviour.recordAutoInsert(editor, session, "}");
@@ -233,10 +243,7 @@ var CstyleBehaviour = function() {
233
243
  var selection = editor.getSelectionRange();
234
244
  var selected = session.doc.getTextRange(selection);
235
245
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
236
- return {
237
- text: '(' + selected + ')',
238
- selection: false
239
- };
246
+ return getWrapped(selection, selected, '(', ')');
240
247
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
241
248
  CstyleBehaviour.recordAutoInsert(editor, session, ")");
242
249
  return {
@@ -281,10 +288,7 @@ var CstyleBehaviour = function() {
281
288
  var selection = editor.getSelectionRange();
282
289
  var selected = session.doc.getTextRange(selection);
283
290
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
284
- return {
285
- text: '[' + selected + ']',
286
- selection: false
287
- };
291
+ return getWrapped(selection, selected, '[', ']');
288
292
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
289
293
  CstyleBehaviour.recordAutoInsert(editor, session, "]");
290
294
  return {
@@ -330,49 +334,44 @@ var CstyleBehaviour = function() {
330
334
  var selection = editor.getSelectionRange();
331
335
  var selected = session.doc.getTextRange(selection);
332
336
  if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
333
- return {
334
- text: quote + selected + quote,
335
- selection: false
336
- };
337
- } else {
337
+ return getWrapped(selection, selected, quote, quote);
338
+ } else if (!selected) {
338
339
  var cursor = editor.getCursorPosition();
339
340
  var line = session.doc.getLine(cursor.row);
340
341
  var leftChar = line.substring(cursor.column-1, cursor.column);
341
- if (leftChar == '\\') {
342
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
343
+
344
+ var token = session.getTokenAt(cursor.row, cursor.column);
345
+ var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
346
+ if (leftChar == "\\" && token && /escape/.test(token.type))
342
347
  return null;
348
+
349
+ var stringBefore = token && /string/.test(token.type);
350
+ var stringAfter = !rightToken || /string/.test(rightToken.type);
351
+
352
+ var pair;
353
+ if (rightChar == quote) {
354
+ pair = stringBefore !== stringAfter;
355
+ } else {
356
+ if (stringBefore && !stringAfter)
357
+ return null; // wrap string with different quote
358
+ if (stringBefore && stringAfter)
359
+ return null; // do not pair quotes inside strings
360
+ var wordRe = session.$mode.tokenRe;
361
+ wordRe.lastIndex = 0;
362
+ var isWordBefore = wordRe.test(leftChar);
363
+ wordRe.lastIndex = 0;
364
+ var isWordAfter = wordRe.test(leftChar);
365
+ if (isWordBefore || isWordAfter)
366
+ return null; // before or after alphanumeric
367
+ if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
368
+ return null; // there is rightChar and it isn't closing
369
+ pair = true;
343
370
  }
344
- var tokens = session.getTokens(selection.start.row);
345
- var col = 0, token;
346
- var quotepos = -1; // Track whether we're inside an open quote.
347
-
348
- for (var x = 0; x < tokens.length; x++) {
349
- token = tokens[x];
350
- if (token.type == "string") {
351
- quotepos = -1;
352
- } else if (quotepos < 0) {
353
- quotepos = token.value.indexOf(quote);
354
- }
355
- if ((token.value.length + col) > selection.start.column) {
356
- break;
357
- }
358
- col += tokens[x].value.length;
359
- }
360
- 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)))) {
361
- if (!CstyleBehaviour.isSaneInsertion(editor, session))
362
- return;
363
- return {
364
- text: quote + quote,
365
- selection: [1,1]
366
- };
367
- } else if (token && token.type === "string") {
368
- var rightChar = line.substring(cursor.column, cursor.column + 1);
369
- if (rightChar == quote) {
370
- return {
371
- text: '',
372
- selection: [1, 1]
373
- };
374
- }
375
- }
371
+ return {
372
+ text: pair ? quote + quote : "",
373
+ selection: [1,1]
374
+ };
376
375
  }
377
376
  }
378
377
  });
@@ -484,12 +483,35 @@ var FoldMode = exports.FoldMode = function(commentRegex) {
484
483
  oop.inherits(FoldMode, BaseFoldMode);
485
484
 
486
485
  (function() {
487
-
486
+
488
487
  this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
489
488
  this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
489
+ this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
490
+ this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
491
+ this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
492
+ this._getFoldWidgetBase = this.getFoldWidget;
493
+ this.getFoldWidget = function(session, foldStyle, row) {
494
+ var line = session.getLine(row);
495
+
496
+ if (this.singleLineBlockCommentRe.test(line)) {
497
+ if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
498
+ return "";
499
+ }
500
+
501
+ var fw = this._getFoldWidgetBase(session, foldStyle, row);
502
+
503
+ if (!fw && this.startRegionRe.test(line))
504
+ return "start"; // lineCommentRegionStart
505
+
506
+ return fw;
507
+ };
490
508
 
491
509
  this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
492
510
  var line = session.getLine(row);
511
+
512
+ if (this.startRegionRe.test(line))
513
+ return this.getCommentRegionBlock(session, line, row);
514
+
493
515
  var match = line.match(this.foldingStartMarker);
494
516
  if (match) {
495
517
  var i = match.index;
@@ -554,6 +576,29 @@ oop.inherits(FoldMode, BaseFoldMode);
554
576
 
555
577
  return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
556
578
  };
579
+
580
+ this.getCommentRegionBlock = function(session, line, row) {
581
+ var startColumn = line.search(/\s*$/);
582
+ var maxRow = session.getLength();
583
+ var startRow = row;
584
+
585
+ var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
586
+ var depth = 1;
587
+ while (++row < maxRow) {
588
+ line = session.getLine(row);
589
+ var m = re.exec(line);
590
+ if (!m) continue;
591
+ if (m[1]) depth--;
592
+ else depth++;
593
+
594
+ if (!depth) break;
595
+ }
596
+
597
+ var endRow = row;
598
+ if (endRow > startRow) {
599
+ return new Range(startRow, startColumn, endRow, line.length);
600
+ }
601
+ };
557
602
 
558
603
  }).call(FoldMode.prototype);
559
604
 
@@ -605,11 +650,11 @@ oop.inherits(Mode, TextMode);
605
650
  var worker = new WorkerClient(["ace"], "ace/mode/json_worker", "JsonWorker");
606
651
  worker.attachToDocument(session.getDocument());
607
652
 
608
- worker.on("error", function(e) {
609
- session.setAnnotations([e.data]);
653
+ worker.on("annotate", function(e) {
654
+ session.setAnnotations(e.data);
610
655
  });
611
656
 
612
- worker.on("ok", function() {
657
+ worker.on("terminate", function() {
613
658
  session.clearAnnotations();
614
659
  });
615
660
 
@@ -2104,6 +2104,19 @@ var initContext = function(editor) {
2104
2104
  };
2105
2105
  };
2106
2106
 
2107
+ var getWrapped = function(selection, selected, opening, closing) {
2108
+ var rowDiff = selection.end.row - selection.start.row;
2109
+ return {
2110
+ text: opening + selected + closing,
2111
+ selection: [
2112
+ 0,
2113
+ selection.start.column + 1,
2114
+ rowDiff,
2115
+ selection.end.column + (rowDiff ? 0 : 1)
2116
+ ]
2117
+ };
2118
+ };
2119
+
2107
2120
  var CstyleBehaviour = function() {
2108
2121
  this.add("braces", "insertion", function(state, action, editor, session, text) {
2109
2122
  var cursor = editor.getCursorPosition();
@@ -2113,10 +2126,7 @@ var CstyleBehaviour = function() {
2113
2126
  var selection = editor.getSelectionRange();
2114
2127
  var selected = session.doc.getTextRange(selection);
2115
2128
  if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
2116
- return {
2117
- text: '{' + selected + '}',
2118
- selection: false
2119
- };
2129
+ return getWrapped(selection, selected, '{', '}');
2120
2130
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
2121
2131
  if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
2122
2132
  CstyleBehaviour.recordAutoInsert(editor, session, "}");
@@ -2196,10 +2206,7 @@ var CstyleBehaviour = function() {
2196
2206
  var selection = editor.getSelectionRange();
2197
2207
  var selected = session.doc.getTextRange(selection);
2198
2208
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
2199
- return {
2200
- text: '(' + selected + ')',
2201
- selection: false
2202
- };
2209
+ return getWrapped(selection, selected, '(', ')');
2203
2210
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
2204
2211
  CstyleBehaviour.recordAutoInsert(editor, session, ")");
2205
2212
  return {
@@ -2244,10 +2251,7 @@ var CstyleBehaviour = function() {
2244
2251
  var selection = editor.getSelectionRange();
2245
2252
  var selected = session.doc.getTextRange(selection);
2246
2253
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
2247
- return {
2248
- text: '[' + selected + ']',
2249
- selection: false
2250
- };
2254
+ return getWrapped(selection, selected, '[', ']');
2251
2255
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
2252
2256
  CstyleBehaviour.recordAutoInsert(editor, session, "]");
2253
2257
  return {
@@ -2293,49 +2297,44 @@ var CstyleBehaviour = function() {
2293
2297
  var selection = editor.getSelectionRange();
2294
2298
  var selected = session.doc.getTextRange(selection);
2295
2299
  if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
2296
- return {
2297
- text: quote + selected + quote,
2298
- selection: false
2299
- };
2300
- } else {
2300
+ return getWrapped(selection, selected, quote, quote);
2301
+ } else if (!selected) {
2301
2302
  var cursor = editor.getCursorPosition();
2302
2303
  var line = session.doc.getLine(cursor.row);
2303
2304
  var leftChar = line.substring(cursor.column-1, cursor.column);
2304
- if (leftChar == '\\') {
2305
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
2306
+
2307
+ var token = session.getTokenAt(cursor.row, cursor.column);
2308
+ var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
2309
+ if (leftChar == "\\" && token && /escape/.test(token.type))
2305
2310
  return null;
2311
+
2312
+ var stringBefore = token && /string/.test(token.type);
2313
+ var stringAfter = !rightToken || /string/.test(rightToken.type);
2314
+
2315
+ var pair;
2316
+ if (rightChar == quote) {
2317
+ pair = stringBefore !== stringAfter;
2318
+ } else {
2319
+ if (stringBefore && !stringAfter)
2320
+ return null; // wrap string with different quote
2321
+ if (stringBefore && stringAfter)
2322
+ return null; // do not pair quotes inside strings
2323
+ var wordRe = session.$mode.tokenRe;
2324
+ wordRe.lastIndex = 0;
2325
+ var isWordBefore = wordRe.test(leftChar);
2326
+ wordRe.lastIndex = 0;
2327
+ var isWordAfter = wordRe.test(leftChar);
2328
+ if (isWordBefore || isWordAfter)
2329
+ return null; // before or after alphanumeric
2330
+ if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
2331
+ return null; // there is rightChar and it isn't closing
2332
+ pair = true;
2306
2333
  }
2307
- var tokens = session.getTokens(selection.start.row);
2308
- var col = 0, token;
2309
- var quotepos = -1; // Track whether we're inside an open quote.
2310
-
2311
- for (var x = 0; x < tokens.length; x++) {
2312
- token = tokens[x];
2313
- if (token.type == "string") {
2314
- quotepos = -1;
2315
- } else if (quotepos < 0) {
2316
- quotepos = token.value.indexOf(quote);
2317
- }
2318
- if ((token.value.length + col) > selection.start.column) {
2319
- break;
2320
- }
2321
- col += tokens[x].value.length;
2322
- }
2323
- 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)))) {
2324
- if (!CstyleBehaviour.isSaneInsertion(editor, session))
2325
- return;
2326
- return {
2327
- text: quote + quote,
2328
- selection: [1,1]
2329
- };
2330
- } else if (token && token.type === "string") {
2331
- var rightChar = line.substring(cursor.column, cursor.column + 1);
2332
- if (rightChar == quote) {
2333
- return {
2334
- text: '',
2335
- selection: [1, 1]
2336
- };
2337
- }
2338
- }
2334
+ return {
2335
+ text: pair ? quote + quote : "",
2336
+ selection: [1,1]
2337
+ };
2339
2338
  }
2340
2339
  }
2341
2340
  });
@@ -2545,6 +2544,8 @@ var XmlBehaviour = function () {
2545
2544
  var token = iterator.getCurrentToken();
2546
2545
 
2547
2546
  if (token && token.type.indexOf("tag-close") !== -1) {
2547
+ if (token.value == "/>")
2548
+ return;
2548
2549
  while (token && token.type.indexOf("tag-name") === -1) {
2549
2550
  token = iterator.stepBackward();
2550
2551
  }
@@ -2672,12 +2673,35 @@ var FoldMode = exports.FoldMode = function(commentRegex) {
2672
2673
  oop.inherits(FoldMode, BaseFoldMode);
2673
2674
 
2674
2675
  (function() {
2675
-
2676
+
2676
2677
  this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
2677
2678
  this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
2679
+ this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
2680
+ this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
2681
+ this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
2682
+ this._getFoldWidgetBase = this.getFoldWidget;
2683
+ this.getFoldWidget = function(session, foldStyle, row) {
2684
+ var line = session.getLine(row);
2685
+
2686
+ if (this.singleLineBlockCommentRe.test(line)) {
2687
+ if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
2688
+ return "";
2689
+ }
2690
+
2691
+ var fw = this._getFoldWidgetBase(session, foldStyle, row);
2692
+
2693
+ if (!fw && this.startRegionRe.test(line))
2694
+ return "start"; // lineCommentRegionStart
2695
+
2696
+ return fw;
2697
+ };
2678
2698
 
2679
2699
  this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
2680
2700
  var line = session.getLine(row);
2701
+
2702
+ if (this.startRegionRe.test(line))
2703
+ return this.getCommentRegionBlock(session, line, row);
2704
+
2681
2705
  var match = line.match(this.foldingStartMarker);
2682
2706
  if (match) {
2683
2707
  var i = match.index;
@@ -2742,6 +2766,29 @@ oop.inherits(FoldMode, BaseFoldMode);
2742
2766
 
2743
2767
  return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
2744
2768
  };
2769
+
2770
+ this.getCommentRegionBlock = function(session, line, row) {
2771
+ var startColumn = line.search(/\s*$/);
2772
+ var maxRow = session.getLength();
2773
+ var startRow = row;
2774
+
2775
+ var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
2776
+ var depth = 1;
2777
+ while (++row < maxRow) {
2778
+ line = session.getLine(row);
2779
+ var m = re.exec(line);
2780
+ if (!m) continue;
2781
+ if (m[1]) depth--;
2782
+ else depth++;
2783
+
2784
+ if (!depth) break;
2785
+ }
2786
+
2787
+ var endRow = row;
2788
+ if (endRow > startRow) {
2789
+ return new Range(startRow, startColumn, endRow, line.length);
2790
+ }
2791
+ };
2745
2792
 
2746
2793
  }).call(FoldMode.prototype);
2747
2794
 
@@ -8,7 +8,7 @@ var supportType = exports.supportType = "animation-fill-mode|alignment-adjust|al
8
8
  var supportFunction = exports.supportFunction = "rgb|rgba|url|attr|counter|counters";
9
9
  var supportConstant = exports.supportConstant = "absolute|after-edge|after|all-scroll|all|alphabetic|always|antialiased|armenian|auto|avoid-column|avoid-page|avoid|balance|baseline|before-edge|before|below|bidi-override|block-line-height|block|bold|bolder|border-box|both|bottom|box|break-all|break-word|capitalize|caps-height|caption|center|central|char|circle|cjk-ideographic|clone|close-quote|col-resize|collapse|column|consider-shifts|contain|content-box|cover|crosshair|cubic-bezier|dashed|decimal-leading-zero|decimal|default|disabled|disc|disregard-shifts|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ease-in|ease-in-out|ease-out|ease|ellipsis|end|exclude-ruby|fill|fixed|georgian|glyphs|grid-height|groove|hand|hanging|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|icon|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|ideographic|inactive|include-ruby|inherit|initial|inline-block|inline-box|inline-line-height|inline-table|inline|inset|inside|inter-ideograph|inter-word|invert|italic|justify|katakana-iroha|katakana|keep-all|last|left|lighter|line-edge|line-through|line|linear|list-item|local|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|mathematical|max-height|max-size|medium|menu|message-box|middle|move|n-resize|ne-resize|newspaper|no-change|no-close-quote|no-drop|no-open-quote|no-repeat|none|normal|not-allowed|nowrap|nw-resize|oblique|open-quote|outset|outside|overline|padding-box|page|pointer|pre-line|pre-wrap|pre|preserve-3d|progress|relative|repeat-x|repeat-y|repeat|replaced|reset-size|ridge|right|round|row-resize|rtl|s-resize|scroll|se-resize|separate|slice|small-caps|small-caption|solid|space|square|start|static|status-bar|step-end|step-start|steps|stretch|strict|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|table|tb-rl|text-after-edge|text-before-edge|text-bottom|text-size|text-top|text|thick|thin|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|use-script|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|z-index|zero";
10
10
  var supportConstantColor = exports.supportConstantColor = "aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow";
11
- var supportConstantFonts = exports.supportConstantFonts = "arial|century|comic|courier|garamond|georgia|helvetica|impact|lucida|symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|serif|monospace";
11
+ var supportConstantFonts = exports.supportConstantFonts = "arial|century|comic|courier|cursive|fantasy|garamond|georgia|helvetica|impact|lucida|symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|serif|monospace";
12
12
 
13
13
  var numRe = exports.numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
14
14
  var pseudoElements = exports.pseudoElements = "(\\:+)\\b(after|before|first-letter|first-line|moz-selection|selection)\\b";
@@ -320,7 +320,7 @@ var JavaScriptHighlightRules = function(options) {
320
320
  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(?=\()/
321
321
  }, {
322
322
  token : ["punctuation.operator", "support.function.dom"],
323
- 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(?=\()/
323
+ 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(?=\()/
324
324
  }, {
325
325
  token : ["punctuation.operator", "support.constant"],
326
326
  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/
@@ -551,6 +551,9 @@ var oop = require("../lib/oop");
551
551
  var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
552
552
 
553
553
  var XmlHighlightRules = function(normalize) {
554
+
555
+ var tagRegex = "[a-zA-Z][-_a-zA-Z0-9]*";
556
+
554
557
  this.$rules = {
555
558
  start : [
556
559
  {token : "string.cdata.xml", regex : "<\\!\\[CDATA\\[", next : "cdata"},
@@ -560,7 +563,7 @@ var XmlHighlightRules = function(normalize) {
560
563
  },
561
564
  {
562
565
  token : ["punctuation.instruction.xml", "keyword.instruction.xml"],
563
- regex : "(<\\?)([-_a-zA-Z0-9]+)", next : "processing_instruction",
566
+ regex : "(<\\?)(" + tagRegex + ")", next : "processing_instruction",
564
567
  },
565
568
  {token : "comment.xml", regex : "<\\!--", next : "comment"},
566
569
  {
@@ -576,7 +579,7 @@ var XmlHighlightRules = function(normalize) {
576
579
 
577
580
  xml_decl : [{
578
581
  token : "entity.other.attribute-name.decl-attribute-name.xml",
579
- regex : "(?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+"
582
+ regex : "(?:" + tagRegex + ":)?" + tagRegex + ""
580
583
  }, {
581
584
  token : "keyword.operator.decl-attribute-equals.xml",
582
585
  regex : "="
@@ -612,7 +615,7 @@ var XmlHighlightRules = function(normalize) {
612
615
  next: "pop"
613
616
  }, {
614
617
  token : ["punctuation.markup-decl.xml", "keyword.markup-decl.xml"],
615
- regex : "(<\\!)([-_a-zA-Z0-9]+)",
618
+ regex : "(<\\!)(" + tagRegex + ")",
616
619
  push : [{
617
620
  token : "text",
618
621
  regex : "\\s+"
@@ -648,7 +651,7 @@ var XmlHighlightRules = function(normalize) {
648
651
 
649
652
  tag : [{
650
653
  token : ["meta.tag.punctuation.tag-open.xml", "meta.tag.punctuation.end-tag-open.xml", "meta.tag.tag-name.xml"],
651
- regex : "(?:(<)|(</))((?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+)",
654
+ regex : "(?:(<)|(</))((?:" + tagRegex + ":)?" + tagRegex + ")",
652
655
  next: [
653
656
  {include : "attributes"},
654
657
  {token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next : "start"}
@@ -679,7 +682,7 @@ var XmlHighlightRules = function(normalize) {
679
682
 
680
683
  attributes: [{
681
684
  token : "entity.other.attribute-name.xml",
682
- regex : "(?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+"
685
+ regex : "(?:" + tagRegex + ":)?" + tagRegex + ""
683
686
  }, {
684
687
  token : "keyword.operator.attribute-equals.xml",
685
688
  regex : "="
@@ -1095,6 +1098,19 @@ var initContext = function(editor) {
1095
1098
  };
1096
1099
  };
1097
1100
 
1101
+ var getWrapped = function(selection, selected, opening, closing) {
1102
+ var rowDiff = selection.end.row - selection.start.row;
1103
+ return {
1104
+ text: opening + selected + closing,
1105
+ selection: [
1106
+ 0,
1107
+ selection.start.column + 1,
1108
+ rowDiff,
1109
+ selection.end.column + (rowDiff ? 0 : 1)
1110
+ ]
1111
+ };
1112
+ };
1113
+
1098
1114
  var CstyleBehaviour = function() {
1099
1115
  this.add("braces", "insertion", function(state, action, editor, session, text) {
1100
1116
  var cursor = editor.getCursorPosition();
@@ -1104,10 +1120,7 @@ var CstyleBehaviour = function() {
1104
1120
  var selection = editor.getSelectionRange();
1105
1121
  var selected = session.doc.getTextRange(selection);
1106
1122
  if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
1107
- return {
1108
- text: '{' + selected + '}',
1109
- selection: false
1110
- };
1123
+ return getWrapped(selection, selected, '{', '}');
1111
1124
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
1112
1125
  if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
1113
1126
  CstyleBehaviour.recordAutoInsert(editor, session, "}");
@@ -1187,10 +1200,7 @@ var CstyleBehaviour = function() {
1187
1200
  var selection = editor.getSelectionRange();
1188
1201
  var selected = session.doc.getTextRange(selection);
1189
1202
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
1190
- return {
1191
- text: '(' + selected + ')',
1192
- selection: false
1193
- };
1203
+ return getWrapped(selection, selected, '(', ')');
1194
1204
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
1195
1205
  CstyleBehaviour.recordAutoInsert(editor, session, ")");
1196
1206
  return {
@@ -1235,10 +1245,7 @@ var CstyleBehaviour = function() {
1235
1245
  var selection = editor.getSelectionRange();
1236
1246
  var selected = session.doc.getTextRange(selection);
1237
1247
  if (selected !== "" && editor.getWrapBehavioursEnabled()) {
1238
- return {
1239
- text: '[' + selected + ']',
1240
- selection: false
1241
- };
1248
+ return getWrapped(selection, selected, '[', ']');
1242
1249
  } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
1243
1250
  CstyleBehaviour.recordAutoInsert(editor, session, "]");
1244
1251
  return {
@@ -1284,49 +1291,44 @@ var CstyleBehaviour = function() {
1284
1291
  var selection = editor.getSelectionRange();
1285
1292
  var selected = session.doc.getTextRange(selection);
1286
1293
  if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
1287
- return {
1288
- text: quote + selected + quote,
1289
- selection: false
1290
- };
1291
- } else {
1294
+ return getWrapped(selection, selected, quote, quote);
1295
+ } else if (!selected) {
1292
1296
  var cursor = editor.getCursorPosition();
1293
1297
  var line = session.doc.getLine(cursor.row);
1294
1298
  var leftChar = line.substring(cursor.column-1, cursor.column);
1295
- if (leftChar == '\\') {
1299
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
1300
+
1301
+ var token = session.getTokenAt(cursor.row, cursor.column);
1302
+ var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
1303
+ if (leftChar == "\\" && token && /escape/.test(token.type))
1296
1304
  return null;
1305
+
1306
+ var stringBefore = token && /string/.test(token.type);
1307
+ var stringAfter = !rightToken || /string/.test(rightToken.type);
1308
+
1309
+ var pair;
1310
+ if (rightChar == quote) {
1311
+ pair = stringBefore !== stringAfter;
1312
+ } else {
1313
+ if (stringBefore && !stringAfter)
1314
+ return null; // wrap string with different quote
1315
+ if (stringBefore && stringAfter)
1316
+ return null; // do not pair quotes inside strings
1317
+ var wordRe = session.$mode.tokenRe;
1318
+ wordRe.lastIndex = 0;
1319
+ var isWordBefore = wordRe.test(leftChar);
1320
+ wordRe.lastIndex = 0;
1321
+ var isWordAfter = wordRe.test(leftChar);
1322
+ if (isWordBefore || isWordAfter)
1323
+ return null; // before or after alphanumeric
1324
+ if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
1325
+ return null; // there is rightChar and it isn't closing
1326
+ pair = true;
1297
1327
  }
1298
- var tokens = session.getTokens(selection.start.row);
1299
- var col = 0, token;
1300
- var quotepos = -1; // Track whether we're inside an open quote.
1301
-
1302
- for (var x = 0; x < tokens.length; x++) {
1303
- token = tokens[x];
1304
- if (token.type == "string") {
1305
- quotepos = -1;
1306
- } else if (quotepos < 0) {
1307
- quotepos = token.value.indexOf(quote);
1308
- }
1309
- if ((token.value.length + col) > selection.start.column) {
1310
- break;
1311
- }
1312
- col += tokens[x].value.length;
1313
- }
1314
- 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)))) {
1315
- if (!CstyleBehaviour.isSaneInsertion(editor, session))
1316
- return;
1317
- return {
1318
- text: quote + quote,
1319
- selection: [1,1]
1320
- };
1321
- } else if (token && token.type === "string") {
1322
- var rightChar = line.substring(cursor.column, cursor.column + 1);
1323
- if (rightChar == quote) {
1324
- return {
1325
- text: '',
1326
- selection: [1, 1]
1327
- };
1328
- }
1329
- }
1328
+ return {
1329
+ text: pair ? quote + quote : "",
1330
+ selection: [1,1]
1331
+ };
1330
1332
  }
1331
1333
  }
1332
1334
  });
@@ -1438,12 +1440,35 @@ var FoldMode = exports.FoldMode = function(commentRegex) {
1438
1440
  oop.inherits(FoldMode, BaseFoldMode);
1439
1441
 
1440
1442
  (function() {
1441
-
1443
+
1442
1444
  this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
1443
1445
  this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
1446
+ this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
1447
+ this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
1448
+ this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
1449
+ this._getFoldWidgetBase = this.getFoldWidget;
1450
+ this.getFoldWidget = function(session, foldStyle, row) {
1451
+ var line = session.getLine(row);
1452
+
1453
+ if (this.singleLineBlockCommentRe.test(line)) {
1454
+ if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
1455
+ return "";
1456
+ }
1457
+
1458
+ var fw = this._getFoldWidgetBase(session, foldStyle, row);
1459
+
1460
+ if (!fw && this.startRegionRe.test(line))
1461
+ return "start"; // lineCommentRegionStart
1462
+
1463
+ return fw;
1464
+ };
1444
1465
 
1445
1466
  this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
1446
1467
  var line = session.getLine(row);
1468
+
1469
+ if (this.startRegionRe.test(line))
1470
+ return this.getCommentRegionBlock(session, line, row);
1471
+
1447
1472
  var match = line.match(this.foldingStartMarker);
1448
1473
  if (match) {
1449
1474
  var i = match.index;
@@ -1508,6 +1533,29 @@ oop.inherits(FoldMode, BaseFoldMode);
1508
1533
 
1509
1534
  return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
1510
1535
  };
1536
+
1537
+ this.getCommentRegionBlock = function(session, line, row) {
1538
+ var startColumn = line.search(/\s*$/);
1539
+ var maxRow = session.getLength();
1540
+ var startRow = row;
1541
+
1542
+ var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
1543
+ var depth = 1;
1544
+ while (++row < maxRow) {
1545
+ line = session.getLine(row);
1546
+ var m = re.exec(line);
1547
+ if (!m) continue;
1548
+ if (m[1]) depth--;
1549
+ else depth++;
1550
+
1551
+ if (!depth) break;
1552
+ }
1553
+
1554
+ var endRow = row;
1555
+ if (endRow > startRow) {
1556
+ return new Range(startRow, startColumn, endRow, line.length);
1557
+ }
1558
+ };
1511
1559
 
1512
1560
  }).call(FoldMode.prototype);
1513
1561