bzr branch
http://gegoxaren.bato24.eu/bzr/lenasys/trunk
15.1.1
by galaxyAbstractor
Started implementation of a new codeviewer using Ace |
1 |
define('ace/mode/powershell', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/powershell_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) { |
2 |
||
3 |
||
4 |
var oop = require("../lib/oop"); |
|
5 |
var TextMode = require("./text").Mode; |
|
6 |
var Tokenizer = require("../tokenizer").Tokenizer; |
|
7 |
var PowershellHighlightRules = require("./powershell_highlight_rules").PowershellHighlightRules; |
|
8 |
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; |
|
9 |
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; |
|
10 |
var CStyleFoldMode = require("./folding/cstyle").FoldMode; |
|
11 |
||
12 |
var Mode = function() { |
|
13 |
this.$tokenizer = new Tokenizer(new PowershellHighlightRules().getRules()); |
|
14 |
this.$outdent = new MatchingBraceOutdent(); |
|
15 |
this.$behaviour = new CstyleBehaviour(); |
|
16 |
this.foldingRules = new CStyleFoldMode({start: "^\\s*(<#)", end: "^[#\\s]>\\s*$"}); |
|
17 |
};
|
|
18 |
oop.inherits(Mode, TextMode); |
|
19 |
||
20 |
(function() { |
|
21 |
||
22 |
this.lineCommentStart = "#"; |
|
23 |
this.blockComment = {start: "<#", end: "#>"}; |
|
24 |
|
|
25 |
this.getNextLineIndent = function(state, line, tab) { |
|
26 |
var indent = this.$getIndent(line); |
|
27 |
||
28 |
var tokenizedLine = this.$tokenizer.getLineTokens(line, state); |
|
29 |
var tokens = tokenizedLine.tokens; |
|
30 |
||
31 |
if (tokens.length && tokens[tokens.length-1].type == "comment") { |
|
32 |
return indent; |
|
33 |
} |
|
34 |
|
|
35 |
if (state == "start") { |
|
36 |
var match = line.match(/^.*[\{\(\[]\s*$/); |
|
37 |
if (match) { |
|
38 |
indent += tab; |
|
39 |
} |
|
40 |
} |
|
41 |
||
42 |
return indent; |
|
43 |
}; |
|
44 |
||
45 |
this.checkOutdent = function(state, line, input) { |
|
46 |
return this.$outdent.checkOutdent(line, input); |
|
47 |
}; |
|
48 |
||
49 |
this.autoOutdent = function(state, doc, row) { |
|
50 |
this.$outdent.autoOutdent(doc, row); |
|
51 |
}; |
|
52 |
||
53 |
||
54 |
this.createWorker = function(session) { |
|
55 |
return null; |
|
56 |
}; |
|
57 |
||
58 |
}).call(Mode.prototype); |
|
59 |
||
60 |
exports.Mode = Mode; |
|
61 |
});
|
|
62 |
define('ace/mode/powershell_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) { |
|
63 |
||
64 |
||
65 |
var oop = require("../lib/oop"); |
|
66 |
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; |
|
67 |
||
68 |
var PowershellHighlightRules = function() { |
|
69 |
||
70 |
var keywords = ( |
|
71 |
"function|if|else|elseif|switch|while|default|for|do|until|break|continue|" + |
|
72 |
"foreach|return|filter|in|trap|throw|param|begin|process|end" |
|
73 |
); |
|
74 |
||
75 |
var builtinFunctions = ( |
|
76 |
"Get-Alias|Import-Alias|New-Alias|Set-Alias|Get-AuthenticodeSignature|Set-AuthenticodeSignature|" + |
|
77 |
"Set-Location|Get-ChildItem|Clear-Item|Get-Command|Measure-Command|Trace-Command|" + |
|
78 |
"Add-Computer|Checkpoint-Computer|Remove-Computer|Restart-Computer|Restore-Computer|Stop-Computer|" + |
|
79 |
"Reset-ComputerMachinePassword|Test-ComputerSecureChannel|Add-Content|Get-Content|Set-Content|Clear-Content|" + |
|
80 |
"Get-Command|Invoke-Command|Enable-ComputerRestore|Disable-ComputerRestore|Get-ComputerRestorePoint|Test-Connection|" + |
|
81 |
"ConvertFrom-CSV|ConvertTo-CSV|ConvertTo-Html|ConvertTo-Xml|ConvertFrom-SecureString|ConvertTo-SecureString|" + |
|
82 |
"Copy-Item|Export-Counter|Get-Counter|Import-Counter|Get-Credential|Get-Culture|" + |
|
83 |
"Get-ChildItem|Get-Date|Set-Date|Remove-Item|Compare-Object|Get-Event|" + |
|
84 |
"Get-WinEvent|New-Event|Remove-Event|Unregister-Event|Wait-Event|Clear-EventLog|" + |
|
85 |
"Get-Eventlog|Limit-EventLog|New-Eventlog|Remove-EventLog|Show-EventLog|Write-EventLog|" + |
|
86 |
"Get-EventSubscriber|Register-EngineEvent|Register-ObjectEvent|Register-WmiEvent|Get-ExecutionPolicy|Set-ExecutionPolicy|" + |
|
87 |
"Export-Alias|Export-Clixml|Export-Console|Export-Csv|ForEach-Object|Format-Custom|" + |
|
88 |
"Format-List|Format-Table|Format-Wide|Export-FormatData|Get-FormatData|Get-Item|" + |
|
89 |
"Get-ChildItem|Get-Help|Add-History|Clear-History|Get-History|Invoke-History|" + |
|
90 |
"Get-Host|Read-Host|Write-Host|Get-HotFix|Import-Clixml|Import-Csv|" + |
|
91 |
"Invoke-Command|Invoke-Expression|Get-Item|Invoke-Item|New-Item|Remove-Item|" + |
|
92 |
"Set-Item|Clear-ItemProperty|Copy-ItemProperty|Get-ItemProperty|Move-ItemProperty|New-ItemProperty|" + |
|
93 |
"Remove-ItemProperty|Rename-ItemProperty|Set-ItemProperty|Get-Job|Receive-Job|Remove-Job|" + |
|
94 |
"Start-Job|Stop-Job|Wait-Job|Stop-Process|Update-List|Get-Location|" + |
|
95 |
"Pop-Location|Push-Location|Set-Location|Send-MailMessage|Add-Member|Get-Member|" + |
|
96 |
"Move-Item|Compare-Object|Group-Object|Measure-Object|New-Object|Select-Object|" + |
|
97 |
"Sort-Object|Where-Object|Out-Default|Out-File|Out-GridView|Out-Host|" + |
|
98 |
"Out-Null|Out-Printer|Out-String|Convert-Path|Join-Path|Resolve-Path|" + |
|
99 |
"Split-Path|Test-Path|Get-Pfxcertificate|Pop-Location|Push-Location|Get-Process|" + |
|
100 |
"Start-Process|Stop-Process|Wait-Process|Enable-PSBreakpoint|Disable-PSBreakpoint|Get-PSBreakpoint|" + |
|
101 |
"Set-PSBreakpoint|Remove-PSBreakpoint|Get-PSDrive|New-PSDrive|Remove-PSDrive|Get-PSProvider|" + |
|
102 |
"Set-PSdebug|Enter-PSSession|Exit-PSSession|Export-PSSession|Get-PSSession|Import-PSSession|" + |
|
103 |
"New-PSSession|Remove-PSSession|Disable-PSSessionConfiguration|Enable-PSSessionConfiguration|Get-PSSessionConfiguration|Register-PSSessionConfiguration|" + |
|
104 |
"Set-PSSessionConfiguration|Unregister-PSSessionConfiguration|New-PSSessionOption|Add-PsSnapIn|Get-PsSnapin|Remove-PSSnapin|" + |
|
105 |
"Get-Random|Read-Host|Remove-Item|Rename-Item|Rename-ItemProperty|Select-Object|" + |
|
106 |
"Select-XML|Send-MailMessage|Get-Service|New-Service|Restart-Service|Resume-Service|" + |
|
107 |
"Set-Service|Start-Service|Stop-Service|Suspend-Service|Sort-Object|Start-Sleep|" + |
|
108 |
"ConvertFrom-StringData|Select-String|Tee-Object|New-Timespan|Trace-Command|Get-Tracesource|" + |
|
109 |
"Set-Tracesource|Start-Transaction|Complete-Transaction|Get-Transaction|Use-Transaction|Undo-Transaction|" + |
|
110 |
"Start-Transcript|Stop-Transcript|Add-Type|Update-TypeData|Get-Uiculture|Get-Unique|" + |
|
111 |
"Update-Formatdata|Update-Typedata|Clear-Variable|Get-Variable|New-Variable|Remove-Variable|" + |
|
112 |
"Set-Variable|New-WebServiceProxy|Where-Object|Write-Debug|Write-Error|Write-Host|" + |
|
113 |
"Write-Output|Write-Progress|Write-Verbose|Write-Warning|Set-WmiInstance|Invoke-WmiMethod|" + |
|
114 |
"Get-WmiObject|Remove-WmiObject|Connect-WSMan|Disconnect-WSMan|Test-WSMan|Invoke-WSManAction|" + |
|
115 |
"Disable-WSManCredSSP|Enable-WSManCredSSP|Get-WSManCredSSP|New-WSManInstance|Get-WSManInstance|Set-WSManInstance|" + |
|
116 |
"Remove-WSManInstance|Set-WSManQuickConfig|New-WSManSessionOption" |
|
117 |
); |
|
118 |
||
119 |
var keywordMapper = this.createKeywordMapper({ |
|
120 |
"support.function": builtinFunctions, |
|
121 |
"keyword": keywords |
|
122 |
}, "identifier"); |
|
123 |
||
124 |
var binaryOperatorsRe = "eq|ne|ge|gt|lt|le|like|notlike|match|notmatch|replace|contains|notcontains|" + |
|
125 |
"ieq|ine|ige|igt|ile|ilt|ilike|inotlike|imatch|inotmatch|ireplace|icontains|inotcontains|" + |
|
126 |
"is|isnot|as|" + |
|
127 |
"and|or|band|bor|not"; |
|
128 |
||
129 |
this.$rules = { |
|
130 |
"start" : [ |
|
131 |
{ |
|
132 |
token : "comment", |
|
133 |
regex : "#.*$" |
|
134 |
}, { |
|
135 |
token : "comment.start", |
|
136 |
regex : "<#", |
|
137 |
next : "comment" |
|
138 |
}, { |
|
139 |
token : "string", // single line |
|
140 |
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' |
|
141 |
}, { |
|
142 |
token : "string", // single line |
|
143 |
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" |
|
144 |
}, { |
|
145 |
token : "constant.numeric", // hex |
|
146 |
regex : "0[xX][0-9a-fA-F]+\\b" |
|
147 |
}, { |
|
148 |
token : "constant.numeric", // float |
|
149 |
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" |
|
150 |
}, { |
|
151 |
token : "constant.language.boolean", |
|
152 |
regex : "[$](?:[Tt]rue|[Ff]alse)\\b" |
|
153 |
}, { |
|
154 |
token : "constant.language", |
|
155 |
regex : "[$][Nn]ull\\b" |
|
156 |
}, { |
|
157 |
token : "variable.instance", |
|
158 |
regex : "[$][a-zA-Z][a-zA-Z0-9_]*\\b" |
|
159 |
}, { |
|
160 |
token : keywordMapper, |
|
161 |
regex : "[a-zA-Z_$][a-zA-Z0-9_$\\-]*\\b" |
|
162 |
}, { |
|
163 |
token : "keyword.operator", |
|
164 |
regex : "\\-(?:" + binaryOperatorsRe + ")" |
|
165 |
}, { |
|
166 |
token : "keyword.operator", |
|
167 |
regex : "&|\\*|\\+|\\-|\\=|\\+=|\\-=" |
|
168 |
}, { |
|
169 |
token : "lparen", |
|
170 |
regex : "[[({]" |
|
171 |
}, { |
|
172 |
token : "rparen", |
|
173 |
regex : "[\\])}]" |
|
174 |
}, { |
|
175 |
token : "text", |
|
176 |
regex : "\\s+" |
|
177 |
} |
|
178 |
], |
|
179 |
"comment" : [ |
|
180 |
{ |
|
181 |
token : "comment.end", |
|
182 |
regex : "#>", |
|
183 |
next : "start" |
|
184 |
}, { |
|
185 |
token : "doc.comment.tag", |
|
186 |
regex : "^\\.\\w+" |
|
187 |
}, { |
|
188 |
token : "comment", |
|
189 |
regex : "\\w+" |
|
190 |
}, { |
|
191 |
token : "comment", |
|
192 |
regex : "." |
|
193 |
} |
|
194 |
] |
|
195 |
}; |
|
196 |
};
|
|
197 |
||
198 |
oop.inherits(PowershellHighlightRules, TextHighlightRules); |
|
199 |
||
200 |
exports.PowershellHighlightRules = PowershellHighlightRules; |
|
201 |
});
|
|
202 |
||
203 |
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) { |
|
204 |
||
205 |
||
206 |
var Range = require("../range").Range; |
|
207 |
||
208 |
var MatchingBraceOutdent = function() {}; |
|
209 |
||
210 |
(function() { |
|
211 |
||
212 |
this.checkOutdent = function(line, input) { |
|
213 |
if (! /^\s+$/.test(line)) |
|
214 |
return false; |
|
215 |
||
216 |
return /^\s*\}/.test(input); |
|
217 |
}; |
|
218 |
||
219 |
this.autoOutdent = function(doc, row) { |
|
220 |
var line = doc.getLine(row); |
|
221 |
var match = line.match(/^(\s*\})/); |
|
222 |
||
223 |
if (!match) return 0; |
|
224 |
||
225 |
var column = match[1].length; |
|
226 |
var openBracePos = doc.findMatchingBracket({row: row, column: column}); |
|
227 |
||
228 |
if (!openBracePos || openBracePos.row == row) return 0; |
|
229 |
||
230 |
var indent = this.$getIndent(doc.getLine(openBracePos.row)); |
|
231 |
doc.replace(new Range(row, 0, row, column-1), indent); |
|
232 |
}; |
|
233 |
||
234 |
this.$getIndent = function(line) { |
|
235 |
return line.match(/^\s*/)[0]; |
|
236 |
}; |
|
237 |
||
238 |
}).call(MatchingBraceOutdent.prototype); |
|
239 |
||
240 |
exports.MatchingBraceOutdent = MatchingBraceOutdent; |
|
241 |
});
|
|
242 |
||
243 |
define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) { |
|
244 |
||
245 |
||
246 |
var oop = require("../../lib/oop"); |
|
247 |
var Behaviour = require("../behaviour").Behaviour; |
|
248 |
var TokenIterator = require("../../token_iterator").TokenIterator; |
|
249 |
var lang = require("../../lib/lang"); |
|
250 |
||
251 |
var SAFE_INSERT_IN_TOKENS = |
|
252 |
["text", "paren.rparen", "punctuation.operator"]; |
|
253 |
var SAFE_INSERT_BEFORE_TOKENS = |
|
254 |
["text", "paren.rparen", "punctuation.operator", "comment"]; |
|
255 |
||
256 |
||
257 |
var autoInsertedBrackets = 0; |
|
258 |
var autoInsertedRow = -1; |
|
259 |
var autoInsertedLineEnd = ""; |
|
260 |
var maybeInsertedBrackets = 0; |
|
261 |
var maybeInsertedRow = -1; |
|
262 |
var maybeInsertedLineStart = ""; |
|
263 |
var maybeInsertedLineEnd = ""; |
|
264 |
||
265 |
var CstyleBehaviour = function () { |
|
266 |
|
|
267 |
CstyleBehaviour.isSaneInsertion = function(editor, session) { |
|
268 |
var cursor = editor.getCursorPosition(); |
|
269 |
var iterator = new TokenIterator(session, cursor.row, cursor.column); |
|
270 |
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) { |
|
271 |
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1); |
|
272 |
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) |
|
273 |
return false; |
|
274 |
} |
|
275 |
iterator.stepForward(); |
|
276 |
return iterator.getCurrentTokenRow() !== cursor.row || |
|
277 |
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS); |
|
278 |
}; |
|
279 |
|
|
280 |
CstyleBehaviour.$matchTokenType = function(token, types) { |
|
281 |
return types.indexOf(token.type || token) > -1; |
|
282 |
}; |
|
283 |
|
|
284 |
CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) { |
|
285 |
var cursor = editor.getCursorPosition(); |
|
286 |
var line = session.doc.getLine(cursor.row); |
|
287 |
if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0])) |
|
288 |
autoInsertedBrackets = 0; |
|
289 |
autoInsertedRow = cursor.row; |
|
290 |
autoInsertedLineEnd = bracket + line.substr(cursor.column); |
|
291 |
autoInsertedBrackets++; |
|
292 |
}; |
|
293 |
|
|
294 |
CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) { |
|
295 |
var cursor = editor.getCursorPosition(); |
|
296 |
var line = session.doc.getLine(cursor.row); |
|
297 |
if (!this.isMaybeInsertedClosing(cursor, line)) |
|
298 |
maybeInsertedBrackets = 0; |
|
299 |
maybeInsertedRow = cursor.row; |
|
300 |
maybeInsertedLineStart = line.substr(0, cursor.column) + bracket; |
|
301 |
maybeInsertedLineEnd = line.substr(cursor.column); |
|
302 |
maybeInsertedBrackets++; |
|
303 |
}; |
|
304 |
|
|
305 |
CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) { |
|
306 |
return autoInsertedBrackets > 0 && |
|
307 |
cursor.row === autoInsertedRow && |
|
308 |
bracket === autoInsertedLineEnd[0] && |
|
309 |
line.substr(cursor.column) === autoInsertedLineEnd; |
|
310 |
}; |
|
311 |
|
|
312 |
CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) { |
|
313 |
return maybeInsertedBrackets > 0 && |
|
314 |
cursor.row === maybeInsertedRow && |
|
315 |
line.substr(cursor.column) === maybeInsertedLineEnd && |
|
316 |
line.substr(0, cursor.column) == maybeInsertedLineStart; |
|
317 |
}; |
|
318 |
|
|
319 |
CstyleBehaviour.popAutoInsertedClosing = function() { |
|
320 |
autoInsertedLineEnd = autoInsertedLineEnd.substr(1); |
|
321 |
autoInsertedBrackets--; |
|
322 |
}; |
|
323 |
|
|
324 |
CstyleBehaviour.clearMaybeInsertedClosing = function() { |
|
325 |
maybeInsertedBrackets = 0; |
|
326 |
maybeInsertedRow = -1; |
|
327 |
}; |
|
328 |
||
329 |
this.add("braces", "insertion", function (state, action, editor, session, text) { |
|
330 |
var cursor = editor.getCursorPosition(); |
|
331 |
var line = session.doc.getLine(cursor.row); |
|
332 |
if (text == '{') { |
|
333 |
var selection = editor.getSelectionRange(); |
|
334 |
var selected = session.doc.getTextRange(selection); |
|
335 |
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) { |
|
336 |
return { |
|
337 |
text: '{' + selected + '}', |
|
338 |
selection: false |
|
339 |
}; |
|
340 |
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) { |
|
341 |
if (/[\]\}\)]/.test(line[cursor.column])) { |
|
342 |
CstyleBehaviour.recordAutoInsert(editor, session, "}"); |
|
343 |
return { |
|
344 |
text: '{}', |
|
345 |
selection: [1, 1] |
|
346 |
}; |
|
347 |
} else { |
|
348 |
CstyleBehaviour.recordMaybeInsert(editor, session, "{"); |
|
349 |
return { |
|
350 |
text: '{', |
|
351 |
selection: [1, 1] |
|
352 |
}; |
|
353 |
} |
|
354 |
} |
|
355 |
} else if (text == '}') { |
|
356 |
var rightChar = line.substring(cursor.column, cursor.column + 1); |
|
357 |
if (rightChar == '}') { |
|
358 |
var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row}); |
|
359 |
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { |
|
360 |
CstyleBehaviour.popAutoInsertedClosing(); |
|
361 |
return { |
|
362 |
text: '', |
|
363 |
selection: [1, 1] |
|
364 |
}; |
|
365 |
} |
|
366 |
} |
|
367 |
} else if (text == "\n" || text == "\r\n") { |
|
368 |
var closing = ""; |
|
369 |
if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) { |
|
370 |
closing = lang.stringRepeat("}", maybeInsertedBrackets); |
|
371 |
CstyleBehaviour.clearMaybeInsertedClosing(); |
|
372 |
} |
|
373 |
var rightChar = line.substring(cursor.column, cursor.column + 1); |
|
374 |
if (rightChar == '}' || closing !== "") { |
|
375 |
var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}'); |
|
376 |
if (!openBracePos) |
|
377 |
return null; |
|
378 |
||
379 |
var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString()); |
|
380 |
var next_indent = this.$getIndent(line); |
|
381 |
||
382 |
return { |
|
383 |
text: '\n' + indent + '\n' + next_indent + closing, |
|
384 |
selection: [1, indent.length, 1, indent.length] |
|
385 |
}; |
|
386 |
} |
|
387 |
} |
|
388 |
}); |
|
389 |
||
390 |
this.add("braces", "deletion", function (state, action, editor, session, range) { |
|
391 |
var selected = session.doc.getTextRange(range); |
|
392 |
if (!range.isMultiLine() && selected == '{') { |
|
393 |
var line = session.doc.getLine(range.start.row); |
|
394 |
var rightChar = line.substring(range.end.column, range.end.column + 1); |
|
395 |
if (rightChar == '}') { |
|
396 |
range.end.column++; |
|
397 |
return range; |
|
398 |
} else { |
|
399 |
maybeInsertedBrackets--; |
|
400 |
} |
|
401 |
} |
|
402 |
}); |
|
403 |
||
404 |
this.add("parens", "insertion", function (state, action, editor, session, text) { |
|
405 |
if (text == '(') { |
|
406 |
var selection = editor.getSelectionRange(); |
|
407 |
var selected = session.doc.getTextRange(selection); |
|
408 |
if (selected !== "" && editor.getWrapBehavioursEnabled()) { |
|
409 |
return { |
|
410 |
text: '(' + selected + ')', |
|
411 |
selection: false |
|
412 |
}; |
|
413 |
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) { |
|
414 |
CstyleBehaviour.recordAutoInsert(editor, session, ")"); |
|
415 |
return { |
|
416 |
text: '()', |
|
417 |
selection: [1, 1] |
|
418 |
}; |
|
419 |
} |
|
420 |
} else if (text == ')') { |
|
421 |
var cursor = editor.getCursorPosition(); |
|
422 |
var line = session.doc.getLine(cursor.row); |
|
423 |
var rightChar = line.substring(cursor.column, cursor.column + 1); |
|
424 |
if (rightChar == ')') { |
|
425 |
var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row}); |
|
426 |
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { |
|
427 |
CstyleBehaviour.popAutoInsertedClosing(); |
|
428 |
return { |
|
429 |
text: '', |
|
430 |
selection: [1, 1] |
|
431 |
}; |
|
432 |
} |
|
433 |
} |
|
434 |
} |
|
435 |
}); |
|
436 |
||
437 |
this.add("parens", "deletion", function (state, action, editor, session, range) { |
|
438 |
var selected = session.doc.getTextRange(range); |
|
439 |
if (!range.isMultiLine() && selected == '(') { |
|
440 |
var line = session.doc.getLine(range.start.row); |
|
441 |
var rightChar = line.substring(range.start.column + 1, range.start.column + 2); |
|
442 |
if (rightChar == ')') { |
|
443 |
range.end.column++; |
|
444 |
return range; |
|
445 |
} |
|
446 |
} |
|
447 |
}); |
|
448 |
||
449 |
this.add("brackets", "insertion", function (state, action, editor, session, text) { |
|
450 |
if (text == '[') { |
|
451 |
var selection = editor.getSelectionRange(); |
|
452 |
var selected = session.doc.getTextRange(selection); |
|
453 |
if (selected !== "" && editor.getWrapBehavioursEnabled()) { |
|
454 |
return { |
|
455 |
text: '[' + selected + ']', |
|
456 |
selection: false |
|
457 |
}; |
|
458 |
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) { |
|
459 |
CstyleBehaviour.recordAutoInsert(editor, session, "]"); |
|
460 |
return { |
|
461 |
text: '[]', |
|
462 |
selection: [1, 1] |
|
463 |
}; |
|
464 |
} |
|
465 |
} else if (text == ']') { |
|
466 |
var cursor = editor.getCursorPosition(); |
|
467 |
var line = session.doc.getLine(cursor.row); |
|
468 |
var rightChar = line.substring(cursor.column, cursor.column + 1); |
|
469 |
if (rightChar == ']') { |
|
470 |
var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row}); |
|
471 |
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { |
|
472 |
CstyleBehaviour.popAutoInsertedClosing(); |
|
473 |
return { |
|
474 |
text: '', |
|
475 |
selection: [1, 1] |
|
476 |
}; |
|
477 |
} |
|
478 |
} |
|
479 |
} |
|
480 |
}); |
|
481 |
||
482 |
this.add("brackets", "deletion", function (state, action, editor, session, range) { |
|
483 |
var selected = session.doc.getTextRange(range); |
|
484 |
if (!range.isMultiLine() && selected == '[') { |
|
485 |
var line = session.doc.getLine(range.start.row); |
|
486 |
var rightChar = line.substring(range.start.column + 1, range.start.column + 2); |
|
487 |
if (rightChar == ']') { |
|
488 |
range.end.column++; |
|
489 |
return range; |
|
490 |
} |
|
491 |
} |
|
492 |
}); |
|
493 |
||
494 |
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { |
|
495 |
if (text == '"' || text == "'") { |
|
496 |
var quote = text; |
|
497 |
var selection = editor.getSelectionRange(); |
|
498 |
var selected = session.doc.getTextRange(selection); |
|
499 |
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) { |
|
500 |
return { |
|
501 |
text: quote + selected + quote, |
|
502 |
selection: false |
|
503 |
}; |
|
504 |
} else { |
|
505 |
var cursor = editor.getCursorPosition(); |
|
506 |
var line = session.doc.getLine(cursor.row); |
|
507 |
var leftChar = line.substring(cursor.column-1, cursor.column); |
|
508 |
if (leftChar == '\\') { |
|
509 |
return null; |
|
510 |
} |
|
511 |
var tokens = session.getTokens(selection.start.row); |
|
512 |
var col = 0, token; |
|
513 |
var quotepos = -1; // Track whether we're inside an open quote. |
|
514 |
||
515 |
for (var x = 0; x < tokens.length; x++) { |
|
516 |
token = tokens[x]; |
|
517 |
if (token.type == "string") { |
|
518 |
quotepos = -1; |
|
519 |
} else if (quotepos < 0) { |
|
520 |
quotepos = token.value.indexOf(quote); |
|
521 |
} |
|
522 |
if ((token.value.length + col) > selection.start.column) { |
|
523 |
break; |
|
524 |
} |
|
525 |
col += tokens[x].value.length; |
|
526 |
} |
|
527 |
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)))) { |
|
528 |
if (!CstyleBehaviour.isSaneInsertion(editor, session)) |
|
529 |
return; |
|
530 |
return { |
|
531 |
text: quote + quote, |
|
532 |
selection: [1,1] |
|
533 |
}; |
|
534 |
} else if (token && token.type === "string") { |
|
535 |
var rightChar = line.substring(cursor.column, cursor.column + 1); |
|
536 |
if (rightChar == quote) { |
|
537 |
return { |
|
538 |
text: '', |
|
539 |
selection: [1, 1] |
|
540 |
}; |
|
541 |
} |
|
542 |
} |
|
543 |
} |
|
544 |
} |
|
545 |
}); |
|
546 |
||
547 |
this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { |
|
548 |
var selected = session.doc.getTextRange(range); |
|
549 |
if (!range.isMultiLine() && (selected == '"' || selected == "'")) { |
|
550 |
var line = session.doc.getLine(range.start.row); |
|
551 |
var rightChar = line.substring(range.start.column + 1, range.start.column + 2); |
|
552 |
if (rightChar == selected) { |
|
553 |
range.end.column++; |
|
554 |
return range; |
|
555 |
} |
|
556 |
} |
|
557 |
}); |
|
558 |
||
559 |
};
|
|
560 |
||
561 |
oop.inherits(CstyleBehaviour, Behaviour); |
|
562 |
||
563 |
exports.CstyleBehaviour = CstyleBehaviour; |
|
564 |
});
|
|
565 |
||
566 |
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) { |
|
567 |
||
568 |
||
569 |
var oop = require("../../lib/oop"); |
|
570 |
var Range = require("../../range").Range; |
|
571 |
var BaseFoldMode = require("./fold_mode").FoldMode; |
|
572 |
||
573 |
var FoldMode = exports.FoldMode = function(commentRegex) { |
|
574 |
if (commentRegex) { |
|
575 |
this.foldingStartMarker = new RegExp( |
|
576 |
this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start) |
|
577 |
); |
|
578 |
this.foldingStopMarker = new RegExp( |
|
579 |
this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end) |
|
580 |
); |
|
581 |
} |
|
582 |
};
|
|
583 |
oop.inherits(FoldMode, BaseFoldMode); |
|
584 |
||
585 |
(function() { |
|
586 |
||
587 |
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/; |
|
588 |
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/; |
|
589 |
||
590 |
this.getFoldWidgetRange = function(session, foldStyle, row) { |
|
591 |
var line = session.getLine(row); |
|
592 |
var match = line.match(this.foldingStartMarker); |
|
593 |
if (match) { |
|
594 |
var i = match.index; |
|
595 |
||
596 |
if (match[1]) |
|
597 |
return this.openingBracketBlock(session, match[1], row, i); |
|
598 |
||
599 |
return session.getCommentFoldRange(row, i + match[0].length, 1); |
|
600 |
} |
|
601 |
||
602 |
if (foldStyle !== "markbeginend") |
|
603 |
return; |
|
604 |
||
605 |
var match = line.match(this.foldingStopMarker); |
|
606 |
if (match) { |
|
607 |
var i = match.index + match[0].length; |
|
608 |
||
609 |
if (match[1]) |
|
610 |
return this.closingBracketBlock(session, match[1], row, i); |
|
611 |
||
612 |
return session.getCommentFoldRange(row, i, -1); |
|
613 |
} |
|
614 |
}; |
|
615 |
||
616 |
}).call(FoldMode.prototype); |
|
617 |
||
618 |
});
|