1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2010, Ajax.org B.V.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* * Neither the name of Ajax.org B.V. nor the
15
* names of its contributors may be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
* ***** END LICENSE BLOCK ***** */
31
define('ace/mode/css', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/css_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/worker/worker_client', 'ace/mode/behaviour/css', 'ace/mode/folding/cstyle'], function(require, exports, module) {
34
var oop = require("../lib/oop");
35
var TextMode = require("./text").Mode;
36
var Tokenizer = require("../tokenizer").Tokenizer;
37
var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules;
38
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
39
var WorkerClient = require("../worker/worker_client").WorkerClient;
40
var CssBehaviour = require("./behaviour/css").CssBehaviour;
41
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
43
var Mode = function() {
44
this.$tokenizer = new Tokenizer(new CssHighlightRules().getRules());
45
this.$outdent = new MatchingBraceOutdent();
46
this.$behaviour = new CssBehaviour();
47
this.foldingRules = new CStyleFoldMode();
49
oop.inherits(Mode, TextMode);
53
this.foldingRules = "cStyle";
54
this.blockComment = {start: "/*", end: "*/"};
56
this.getNextLineIndent = function(state, line, tab) {
57
var indent = this.$getIndent(line);
58
var tokens = this.$tokenizer.getLineTokens(line, state).tokens;
59
if (tokens.length && tokens[tokens.length-1].type == "comment") {
63
var match = line.match(/^.*\{\s*$/);
71
this.checkOutdent = function(state, line, input) {
72
return this.$outdent.checkOutdent(line, input);
75
this.autoOutdent = function(state, doc, row) {
76
this.$outdent.autoOutdent(doc, row);
79
this.createWorker = function(session) {
80
var worker = new WorkerClient(["ace"], "ace/mode/css_worker", "Worker");
81
worker.attachToDocument(session.getDocument());
83
worker.on("csslint", function(e) {
84
session.setAnnotations(e.data);
87
worker.on("terminate", function() {
88
session.clearAnnotations();
94
}).call(Mode.prototype);
100
define('ace/mode/css_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
103
var oop = require("../lib/oop");
104
var lang = require("../lib/lang");
105
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
106
var supportType = exports.supportType = "animation-fill-mode|alignment-adjust|alignment-baseline|animation-delay|animation-direction|animation-duration|animation-iteration-count|animation-name|animation-play-state|animation-timing-function|animation|appearance|azimuth|backface-visibility|background-attachment|background-break|background-clip|background-color|background-image|background-origin|background-position|background-repeat|background-size|background|baseline-shift|binding|bleed|bookmark-label|bookmark-level|bookmark-state|bookmark-target|border-bottom|border-bottom-color|border-bottom-left-radius|border-bottom-right-radius|border-bottom-style|border-bottom-width|border-collapse|border-color|border-image|border-image-outset|border-image-repeat|border-image-slice|border-image-source|border-image-width|border-left|border-left-color|border-left-style|border-left-width|border-radius|border-right|border-right-color|border-right-style|border-right-width|border-spacing|border-style|border-top|border-top-color|border-top-left-radius|border-top-right-radius|border-top-style|border-top-width|border-width|border|bottom|box-align|box-decoration-break|box-direction|box-flex-group|box-flex|box-lines|box-ordinal-group|box-orient|box-pack|box-shadow|box-sizing|break-after|break-before|break-inside|caption-side|clear|clip|color-profile|color|column-count|column-fill|column-gap|column-rule|column-rule-color|column-rule-style|column-rule-width|column-span|column-width|columns|content|counter-increment|counter-reset|crop|cue-after|cue-before|cue|cursor|direction|display|dominant-baseline|drop-initial-after-adjust|drop-initial-after-align|drop-initial-before-adjust|drop-initial-before-align|drop-initial-size|drop-initial-value|elevation|empty-cells|fit|fit-position|float-offset|float|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|font|grid-columns|grid-rows|hanging-punctuation|height|hyphenate-after|hyphenate-before|hyphenate-character|hyphenate-lines|hyphenate-resource|hyphens|icon|image-orientation|image-rendering|image-resolution|inline-box-align|left|letter-spacing|line-height|line-stacking-ruby|line-stacking-shift|line-stacking-strategy|line-stacking|list-style-image|list-style-position|list-style-type|list-style|margin-bottom|margin-left|margin-right|margin-top|margin|mark-after|mark-before|mark|marks|marquee-direction|marquee-play-count|marquee-speed|marquee-style|max-height|max-width|min-height|min-width|move-to|nav-down|nav-index|nav-left|nav-right|nav-up|opacity|orphans|outline-color|outline-offset|outline-style|outline-width|outline|overflow-style|overflow-x|overflow-y|overflow|padding-bottom|padding-left|padding-right|padding-top|padding|page-break-after|page-break-before|page-break-inside|page-policy|page|pause-after|pause-before|pause|perspective-origin|perspective|phonemes|pitch-range|pitch|play-during|position|presentation-level|punctuation-trim|quotes|rendering-intent|resize|rest-after|rest-before|rest|richness|right|rotation-point|rotation|ruby-align|ruby-overhang|ruby-position|ruby-span|size|speak-header|speak-numeral|speak-punctuation|speak|speech-rate|stress|string-set|table-layout|target-name|target-new|target-position|target|text-align-last|text-align|text-decoration|text-emphasis|text-height|text-indent|text-justify|text-outline|text-shadow|text-transform|text-wrap|top|transform-origin|transform-style|transform|transition-delay|transition-duration|transition-property|transition-timing-function|transition|unicode-bidi|vertical-align|visibility|voice-balance|voice-duration|voice-family|voice-pitch-range|voice-pitch|voice-rate|voice-stress|voice-volume|volume|white-space-collapse|white-space|widows|width|word-break|word-spacing|word-wrap|z-index";
107
var supportFunction = exports.supportFunction = "rgb|rgba|url|attr|counter|counters";
108
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";
109
var supportConstantColor = exports.supportConstantColor = "aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow";
110
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";
112
var numRe = exports.numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
113
var pseudoElements = exports.pseudoElements = "(\\:+)\\b(after|before|first-letter|first-line|moz-selection|selection)\\b";
114
var pseudoClasses = exports.pseudoClasses = "(:)\\b(active|checked|disabled|empty|enabled|first-child|first-of-type|focus|hover|indeterminate|invalid|last-child|last-of-type|link|not|nth-child|nth-last-child|nth-last-of-type|nth-of-type|only-child|only-of-type|required|root|target|valid|visited)\\b";
116
var CssHighlightRules = function() {
118
var keywordMapper = this.createKeywordMapper({
119
"support.function": supportFunction,
120
"support.constant": supportConstant,
121
"support.type": supportType,
122
"support.constant.color": supportConstantColor,
123
"support.constant.fonts": supportConstantFonts
128
token : "comment", // multi line comment
130
next : "ruleset_comment"
132
token : "string", // single line
133
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
135
token : "string", // single line
136
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
138
token : ["constant.numeric", "keyword"],
139
regex : "(" + numRe + ")(ch|cm|deg|em|ex|fr|gd|grad|Hz|in|kHz|mm|ms|pc|pt|px|rad|rem|s|turn|vh|vm|vw|%)"
141
token : "constant.numeric",
144
token : "constant.numeric", // hex6 color
145
regex : "#[a-f0-9]{6}"
147
token : "constant.numeric", // hex3 color
148
regex : "#[a-f0-9]{3}"
150
token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"],
151
regex : pseudoElements
153
token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"],
154
regex : pseudoClasses
156
token : ["support.function", "string", "support.function"],
157
regex : "(url\\()(.*)(\\))"
159
token : keywordMapper,
160
regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
162
caseInsensitive: true
166
var ruleset = lang.copyArray(base_ruleset);
168
token : "paren.rparen",
173
var media_ruleset = lang.copyArray( base_ruleset );
174
media_ruleset.unshift({
175
token : "paren.rparen",
180
var base_comment = [{
181
token : "comment", // comment spanning whole line
185
var comment = lang.copyArray(base_comment);
187
token : "comment", // closing comment
192
var media_comment = lang.copyArray(base_comment);
193
media_comment.unshift({
194
token : "comment", // closing comment
199
var ruleset_comment = lang.copyArray(base_comment);
200
ruleset_comment.unshift({
201
token : "comment", // closing comment
208
token : "comment", // multi line comment
212
token: "paren.lparen",
221
regex: "#[a-z0-9-_]+"
224
regex: "\\.[a-z0-9-_]+"
227
regex: ":[a-z0-9-_]+"
232
caseInsensitive: true
236
token : "comment", // multi line comment
238
next : "media_comment"
240
token: "paren.lparen",
242
next: "media_ruleset"
249
regex: "#[a-z0-9-_]+"
252
regex: "\\.[a-z0-9-_]+"
255
regex: ":[a-z0-9-_]+"
260
caseInsensitive: true
266
"ruleset_comment" : ruleset_comment,
268
"media_ruleset" : media_ruleset,
269
"media_comment" : media_comment
273
oop.inherits(CssHighlightRules, TextHighlightRules);
275
exports.CssHighlightRules = CssHighlightRules;
279
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
282
var Range = require("../range").Range;
284
var MatchingBraceOutdent = function() {};
288
this.checkOutdent = function(line, input) {
289
if (! /^\s+$/.test(line))
292
return /^\s*\}/.test(input);
295
this.autoOutdent = function(doc, row) {
296
var line = doc.getLine(row);
297
var match = line.match(/^(\s*\})/);
299
if (!match) return 0;
301
var column = match[1].length;
302
var openBracePos = doc.findMatchingBracket({row: row, column: column});
304
if (!openBracePos || openBracePos.row == row) return 0;
306
var indent = this.$getIndent(doc.getLine(openBracePos.row));
307
doc.replace(new Range(row, 0, row, column-1), indent);
310
this.$getIndent = function(line) {
311
return line.match(/^\s*/)[0];
314
}).call(MatchingBraceOutdent.prototype);
316
exports.MatchingBraceOutdent = MatchingBraceOutdent;
319
define('ace/mode/behaviour/css', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/mode/behaviour/cstyle', 'ace/token_iterator'], function(require, exports, module) {
322
var oop = require("../../lib/oop");
323
var Behaviour = require("../behaviour").Behaviour;
324
var CstyleBehaviour = require("./cstyle").CstyleBehaviour;
325
var TokenIterator = require("../../token_iterator").TokenIterator;
327
var CssBehaviour = function () {
329
this.inherit(CstyleBehaviour);
331
this.add("colon", "insertion", function (state, action, editor, session, text) {
333
var cursor = editor.getCursorPosition();
334
var iterator = new TokenIterator(session, cursor.row, cursor.column);
335
var token = iterator.getCurrentToken();
336
if (token && token.value.match(/\s+/)) {
337
token = iterator.stepBackward();
339
if (token && token.type === 'support.type') {
340
var line = session.doc.getLine(cursor.row);
341
var rightChar = line.substring(cursor.column, cursor.column + 1);
342
if (rightChar === ':') {
348
if (!line.substring(cursor.column).match(/^\s*;/)) {
358
this.add("colon", "deletion", function (state, action, editor, session, range) {
359
var selected = session.doc.getTextRange(range);
360
if (!range.isMultiLine() && selected === ':') {
361
var cursor = editor.getCursorPosition();
362
var iterator = new TokenIterator(session, cursor.row, cursor.column);
363
var token = iterator.getCurrentToken();
364
if (token && token.value.match(/\s+/)) {
365
token = iterator.stepBackward();
367
if (token && token.type === 'support.type') {
368
var line = session.doc.getLine(range.start.row);
369
var rightChar = line.substring(range.end.column, range.end.column + 1);
370
if (rightChar === ';') {
378
this.add("semicolon", "insertion", function (state, action, editor, session, text) {
380
var cursor = editor.getCursorPosition();
381
var line = session.doc.getLine(cursor.row);
382
var rightChar = line.substring(cursor.column, cursor.column + 1);
383
if (rightChar === ';') {
393
oop.inherits(CssBehaviour, CstyleBehaviour);
395
exports.CssBehaviour = CssBehaviour;
398
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
401
var oop = require("../../lib/oop");
402
var Behaviour = require("../behaviour").Behaviour;
403
var TokenIterator = require("../../token_iterator").TokenIterator;
404
var lang = require("../../lib/lang");
406
var SAFE_INSERT_IN_TOKENS =
407
["text", "paren.rparen", "punctuation.operator"];
408
var SAFE_INSERT_BEFORE_TOKENS =
409
["text", "paren.rparen", "punctuation.operator", "comment"];
412
var autoInsertedBrackets = 0;
413
var autoInsertedRow = -1;
414
var autoInsertedLineEnd = "";
415
var maybeInsertedBrackets = 0;
416
var maybeInsertedRow = -1;
417
var maybeInsertedLineStart = "";
418
var maybeInsertedLineEnd = "";
420
var CstyleBehaviour = function () {
422
CstyleBehaviour.isSaneInsertion = function(editor, session) {
423
var cursor = editor.getCursorPosition();
424
var iterator = new TokenIterator(session, cursor.row, cursor.column);
425
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
426
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
427
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
430
iterator.stepForward();
431
return iterator.getCurrentTokenRow() !== cursor.row ||
432
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
435
CstyleBehaviour.$matchTokenType = function(token, types) {
436
return types.indexOf(token.type || token) > -1;
439
CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
440
var cursor = editor.getCursorPosition();
441
var line = session.doc.getLine(cursor.row);
442
if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
443
autoInsertedBrackets = 0;
444
autoInsertedRow = cursor.row;
445
autoInsertedLineEnd = bracket + line.substr(cursor.column);
446
autoInsertedBrackets++;
449
CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
450
var cursor = editor.getCursorPosition();
451
var line = session.doc.getLine(cursor.row);
452
if (!this.isMaybeInsertedClosing(cursor, line))
453
maybeInsertedBrackets = 0;
454
maybeInsertedRow = cursor.row;
455
maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
456
maybeInsertedLineEnd = line.substr(cursor.column);
457
maybeInsertedBrackets++;
460
CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
461
return autoInsertedBrackets > 0 &&
462
cursor.row === autoInsertedRow &&
463
bracket === autoInsertedLineEnd[0] &&
464
line.substr(cursor.column) === autoInsertedLineEnd;
467
CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
468
return maybeInsertedBrackets > 0 &&
469
cursor.row === maybeInsertedRow &&
470
line.substr(cursor.column) === maybeInsertedLineEnd &&
471
line.substr(0, cursor.column) == maybeInsertedLineStart;
474
CstyleBehaviour.popAutoInsertedClosing = function() {
475
autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
476
autoInsertedBrackets--;
479
CstyleBehaviour.clearMaybeInsertedClosing = function() {
480
maybeInsertedBrackets = 0;
481
maybeInsertedRow = -1;
484
this.add("braces", "insertion", function (state, action, editor, session, text) {
485
var cursor = editor.getCursorPosition();
486
var line = session.doc.getLine(cursor.row);
488
var selection = editor.getSelectionRange();
489
var selected = session.doc.getTextRange(selection);
490
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
492
text: '{' + selected + '}',
495
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
496
if (/[\]\}\)]/.test(line[cursor.column])) {
497
CstyleBehaviour.recordAutoInsert(editor, session, "}");
503
CstyleBehaviour.recordMaybeInsert(editor, session, "{");
510
} else if (text == '}') {
511
var rightChar = line.substring(cursor.column, cursor.column + 1);
512
if (rightChar == '}') {
513
var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
514
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
515
CstyleBehaviour.popAutoInsertedClosing();
522
} else if (text == "\n" || text == "\r\n") {
524
if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
525
closing = lang.stringRepeat("}", maybeInsertedBrackets);
526
CstyleBehaviour.clearMaybeInsertedClosing();
528
var rightChar = line.substring(cursor.column, cursor.column + 1);
529
if (rightChar == '}' || closing !== "") {
530
var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
534
var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
535
var next_indent = this.$getIndent(line);
538
text: '\n' + indent + '\n' + next_indent + closing,
539
selection: [1, indent.length, 1, indent.length]
545
this.add("braces", "deletion", function (state, action, editor, session, range) {
546
var selected = session.doc.getTextRange(range);
547
if (!range.isMultiLine() && selected == '{') {
548
var line = session.doc.getLine(range.start.row);
549
var rightChar = line.substring(range.end.column, range.end.column + 1);
550
if (rightChar == '}') {
554
maybeInsertedBrackets--;
559
this.add("parens", "insertion", function (state, action, editor, session, text) {
561
var selection = editor.getSelectionRange();
562
var selected = session.doc.getTextRange(selection);
563
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
565
text: '(' + selected + ')',
568
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
569
CstyleBehaviour.recordAutoInsert(editor, session, ")");
575
} else if (text == ')') {
576
var cursor = editor.getCursorPosition();
577
var line = session.doc.getLine(cursor.row);
578
var rightChar = line.substring(cursor.column, cursor.column + 1);
579
if (rightChar == ')') {
580
var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
581
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
582
CstyleBehaviour.popAutoInsertedClosing();
592
this.add("parens", "deletion", function (state, action, editor, session, range) {
593
var selected = session.doc.getTextRange(range);
594
if (!range.isMultiLine() && selected == '(') {
595
var line = session.doc.getLine(range.start.row);
596
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
597
if (rightChar == ')') {
604
this.add("brackets", "insertion", function (state, action, editor, session, text) {
606
var selection = editor.getSelectionRange();
607
var selected = session.doc.getTextRange(selection);
608
if (selected !== "" && editor.getWrapBehavioursEnabled()) {
610
text: '[' + selected + ']',
613
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
614
CstyleBehaviour.recordAutoInsert(editor, session, "]");
620
} else if (text == ']') {
621
var cursor = editor.getCursorPosition();
622
var line = session.doc.getLine(cursor.row);
623
var rightChar = line.substring(cursor.column, cursor.column + 1);
624
if (rightChar == ']') {
625
var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
626
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
627
CstyleBehaviour.popAutoInsertedClosing();
637
this.add("brackets", "deletion", function (state, action, editor, session, range) {
638
var selected = session.doc.getTextRange(range);
639
if (!range.isMultiLine() && selected == '[') {
640
var line = session.doc.getLine(range.start.row);
641
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
642
if (rightChar == ']') {
649
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
650
if (text == '"' || text == "'") {
652
var selection = editor.getSelectionRange();
653
var selected = session.doc.getTextRange(selection);
654
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
656
text: quote + selected + quote,
660
var cursor = editor.getCursorPosition();
661
var line = session.doc.getLine(cursor.row);
662
var leftChar = line.substring(cursor.column-1, cursor.column);
663
if (leftChar == '\\') {
666
var tokens = session.getTokens(selection.start.row);
668
var quotepos = -1; // Track whether we're inside an open quote.
670
for (var x = 0; x < tokens.length; x++) {
672
if (token.type == "string") {
674
} else if (quotepos < 0) {
675
quotepos = token.value.indexOf(quote);
677
if ((token.value.length + col) > selection.start.column) {
680
col += tokens[x].value.length;
682
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)))) {
683
if (!CstyleBehaviour.isSaneInsertion(editor, session))
689
} else if (token && token.type === "string") {
690
var rightChar = line.substring(cursor.column, cursor.column + 1);
691
if (rightChar == quote) {
702
this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
703
var selected = session.doc.getTextRange(range);
704
if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
705
var line = session.doc.getLine(range.start.row);
706
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
707
if (rightChar == selected) {
716
oop.inherits(CstyleBehaviour, Behaviour);
718
exports.CstyleBehaviour = CstyleBehaviour;
721
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
724
var oop = require("../../lib/oop");
725
var Range = require("../../range").Range;
726
var BaseFoldMode = require("./fold_mode").FoldMode;
728
var FoldMode = exports.FoldMode = function(commentRegex) {
730
this.foldingStartMarker = new RegExp(
731
this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
733
this.foldingStopMarker = new RegExp(
734
this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
738
oop.inherits(FoldMode, BaseFoldMode);
742
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
743
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
745
this.getFoldWidgetRange = function(session, foldStyle, row) {
746
var line = session.getLine(row);
747
var match = line.match(this.foldingStartMarker);
752
return this.openingBracketBlock(session, match[1], row, i);
754
return session.getCommentFoldRange(row, i + match[0].length, 1);
757
if (foldStyle !== "markbeginend")
760
var match = line.match(this.foldingStopMarker);
762
var i = match.index + match[0].length;
765
return this.closingBracketBlock(session, match[1], row, i);
767
return session.getCommentFoldRange(row, i, -1);
771
}).call(FoldMode.prototype);