|
Lines 24-30
Link Here
|
| 24 |
|
24 |
|
| 25 |
// Styles |
25 |
// Styles |
| 26 |
var caretLineStyle = {styleClass: "meta annotation currentLine"}; //$NON-NLS-0$ |
26 |
var caretLineStyle = {styleClass: "meta annotation currentLine"}; //$NON-NLS-0$ |
| 27 |
|
27 |
var NEW = 1; |
| 28 |
var PUNCTUATION_SECTION_BEGIN = ".begin"; //$NON-NLS-0$ |
28 |
var PUNCTUATION_SECTION_BEGIN = ".begin"; //$NON-NLS-0$ |
| 29 |
var PUNCTUATION_SECTION_END = ".end"; //$NON-NLS-0$ |
29 |
var PUNCTUATION_SECTION_END = ".end"; //$NON-NLS-0$ |
| 30 |
|
30 |
|
|
Lines 39-45
Link Here
|
| 39 |
var spacePattern = {regex: /[ ]/g, style: {styleClass: "punctuation separator space", unmergeable: true}}; //$NON-NLS-0$ |
39 |
var spacePattern = {regex: /[ ]/g, style: {styleClass: "punctuation separator space", unmergeable: true}}; //$NON-NLS-0$ |
| 40 |
var tabPattern = {regex: /\t/g, style: {styleClass: "punctuation separator tab", unmergeable: true}}; //$NON-NLS-0$ |
40 |
var tabPattern = {regex: /\t/g, style: {styleClass: "punctuation separator tab", unmergeable: true}}; //$NON-NLS-0$ |
| 41 |
|
41 |
|
| 42 |
var _findMatch = function(regex, text, startIndex, testBeforeMatch) { |
42 |
var _findMatch_latest = function(regex, model, startIndex, endIndex, testBeforeMatch) { |
|
|
43 |
/* |
| 44 |
* testBeforeMatch provides a potential optimization for callers that do not strongly expect to find |
| 45 |
* a match. If this argument is defined then test() is initially called on the regex, which executes |
| 46 |
* significantly faster than exec(). If a match is found then the regex's lastIndex is reverted to |
| 47 |
* its pre-test() value, and exec() is then invoked on it in order to get the match details. |
| 48 |
*/ |
| 49 |
|
| 50 |
var initialLastIndex = regex.lastIndex; |
| 51 |
|
| 52 |
var lineIndex = model.getLineAtOffset(startIndex); |
| 53 |
var endLineIndex = model.getLineAtOffset(endIndex); |
| 54 |
|
| 55 |
var lineStart = model.getLineStart(lineIndex); |
| 56 |
|
| 57 |
var lineString = model.getLine(lineIndex); |
| 58 |
regex.lastIndex = startIndex - lineStart; // TODO is the -1 still appropriate? |
| 59 |
while (lineIndex <= endLineIndex) { |
| 60 |
var result; |
| 61 |
if (testBeforeMatch) { |
| 62 |
var revertIndex = regex.lastIndex; |
| 63 |
if (regex.test(lineString)) { |
| 64 |
regex.lastIndex = revertIndex; |
| 65 |
result = regex.exec(lineString); |
| 66 |
} |
| 67 |
} else { |
| 68 |
result = regex.exec(lineString); |
| 69 |
} |
| 70 |
if (result) { |
| 71 |
result.index += model.getLineStart(lineIndex); |
| 72 |
regex.lastIndex = initialLastIndex; |
| 73 |
return result; |
| 74 |
} |
| 75 |
if (endLineIndex < ++lineIndex) break; |
| 76 |
// lineString = model.getLine(lineIndex, true); |
| 77 |
lineStart = model.getLineStart(lineIndex); |
| 78 |
// if (lineStart + lineString.length > endIndex) { |
| 79 |
// lineString = lineString.substring(0, endIndex - lineStart) |
| 80 |
// } |
| 81 |
/* |
| 82 |
* TODO the following passes includeLineDelimiter then subtracts 1 to make it run faster, |
| 83 |
* which is potentially wrong. |
| 84 |
*/ |
| 85 |
var lineEnd = model.getLineEnd(lineIndex, true) - 1; |
| 86 |
if (endIndex < lineEnd) { |
| 87 |
lineString = model.getText(/*model.getLineStart(lineIndex)*/lineStart, endIndex); |
| 88 |
} else { |
| 89 |
lineString = model.getText(/*model.getLineStart(lineIndex)*/lineStart, lineEnd); |
| 90 |
// lineString = model.getLine(lineIndex); // slower |
| 91 |
} |
| 92 |
regex.lastIndex = 0; |
| 93 |
} |
| 94 |
regex.lastIndex = initialLastIndex; |
| 95 |
return null; |
| 96 |
}; |
| 97 |
|
| 98 |
var _findMatch_orig = function(regex, model, startIndex, endIndex, testBeforeMatch) { |
| 99 |
var text = model.getText(/*startIndex*/0, endIndex); |
| 100 |
|
| 43 |
/* |
101 |
/* |
| 44 |
* testBeforeMatch provides a potential optimization for callers that do not strongly expect to find |
102 |
* testBeforeMatch provides a potential optimization for callers that do not strongly expect to find |
| 45 |
* a match. If this argument is defined then test() is initially called on the regex, which executes |
103 |
* a match. If this argument is defined then test() is initially called on the regex, which executes |
|
Lines 99-104
Link Here
|
| 99 |
regex.lastIndex = initialLastIndex; |
157 |
regex.lastIndex = initialLastIndex; |
| 100 |
return null; |
158 |
return null; |
| 101 |
}; |
159 |
}; |
|
|
160 |
|
| 161 |
var _findMatch_new = function(regex, model, startIndex, endIndex, testBeforeMatch) { |
| 162 |
var text = model.getText(/*startIndex*/0, endIndex); |
| 163 |
|
| 164 |
/* |
| 165 |
* testBeforeMatch provides a potential optimization for callers that do not strongly expect to find |
| 166 |
* a match. If this argument is defined then test() is initially called on the regex, which executes |
| 167 |
* significantly faster than exec(). If a match is found then the regex's lastIndex is reverted to |
| 168 |
* its pre-test() value, and exec() is then invoked on it in order to get the match details. |
| 169 |
*/ |
| 170 |
|
| 171 |
var result; |
| 172 |
var initialLastIndex = regex.lastIndex; |
| 173 |
regex.lastIndex = startIndex; |
| 174 |
if (testBeforeMatch) { |
| 175 |
var revertIndex = regex.lastIndex; |
| 176 |
if (regex.test(text)) { |
| 177 |
regex.lastIndex = revertIndex; |
| 178 |
result = regex.exec(text); |
| 179 |
} |
| 180 |
} else { |
| 181 |
result = regex.exec(text); |
| 182 |
} |
| 183 |
regex.lastIndex = initialLastIndex; |
| 184 |
return result; |
| 185 |
}; |
| 186 |
var _findMatch = NEW ? _findMatch_latest : _findMatch_orig; |
| 187 |
|
| 102 |
var substituteCaptureValues = function(regex, resolvedResult) { |
188 |
var substituteCaptureValues = function(regex, resolvedResult) { |
| 103 |
var regexString = regex.toString(); |
189 |
var regexString = regex.toString(); |
| 104 |
captureReferenceRegex.lastIndex = 0; |
190 |
captureReferenceRegex.lastIndex = 0; |
|
Lines 117-125
Link Here
|
| 117 |
/* return an updated regex, remove the leading '/' and trailing /FLAGS */ |
203 |
/* return an updated regex, remove the leading '/' and trailing /FLAGS */ |
| 118 |
return new RegExp(regexString.substring(1, regexString.length - 1 - FLAGS.length), FLAGS); |
204 |
return new RegExp(regexString.substring(1, regexString.length - 1 - FLAGS.length), FLAGS); |
| 119 |
}; |
205 |
}; |
| 120 |
var updateMatch = function(match, text, matches, minimumIndex) { |
206 |
var updateMatch = function(match, matches, model, startIndex, endIndex) { |
| 121 |
var regEx = match.pattern.regex ? match.pattern.regex : match.pattern.regexBegin; |
207 |
var regEx = match.pattern.regex ? match.pattern.regex : match.pattern.regexBegin; |
| 122 |
var result = _findMatch(regEx, text, minimumIndex, true); |
208 |
var result = _findMatch(regEx, model, startIndex, endIndex, true); |
| 123 |
if (result) { |
209 |
if (result) { |
| 124 |
match.result = result; |
210 |
match.result = result; |
| 125 |
for (var i = 0; i < matches.length; i++) { |
211 |
for (var i = 0; i < matches.length; i++) { |
|
Lines 163-170
Link Here
|
| 163 |
resultStyles.push({start: i, end: fullStyle.end, style: fullStyle.style}); |
249 |
resultStyles.push({start: i, end: fullStyle.end, style: fullStyle.style}); |
| 164 |
} |
250 |
} |
| 165 |
}; |
251 |
}; |
| 166 |
var parse = function(text, offset, block, styles, ignoreCaptures) { |
252 |
var parse = function(model, /*offset*/startIndex, endIndex, block, styles, ignoreCaptures) { |
| 167 |
if (!text) { |
253 |
if (startIndex === endIndex) { |
| 168 |
return; |
254 |
return; |
| 169 |
} |
255 |
} |
| 170 |
var patterns = block.getLinePatterns(); |
256 |
var patterns = block.getLinePatterns(); |
|
Lines 176-182
Link Here
|
| 176 |
patterns.forEach(function(current) { |
262 |
patterns.forEach(function(current) { |
| 177 |
var regex = current.regex || current.regexBegin; |
263 |
var regex = current.regex || current.regexBegin; |
| 178 |
regex.oldLastIndex = regex.lastIndex; |
264 |
regex.oldLastIndex = regex.lastIndex; |
| 179 |
var result = _findMatch(regex, text, 0); |
265 |
var result = _findMatch(regex, model, startIndex, endIndex); |
| 180 |
if (result) { |
266 |
if (result) { |
| 181 |
matches.push({result: result, pattern: current}); |
267 |
matches.push({result: result, pattern: current}); |
| 182 |
} |
268 |
} |
|
Lines 198-204
Link Here
|
| 198 |
|
284 |
|
| 199 |
if (current.result.index < index) { |
285 |
if (current.result.index < index) { |
| 200 |
/* processing of another match has moved index beyond this match */ |
286 |
/* processing of another match has moved index beyond this match */ |
| 201 |
updateMatch(current, text, matches, index); |
287 |
updateMatch(current, matches, model, index, endIndex); |
| 202 |
continue; |
288 |
continue; |
| 203 |
} |
289 |
} |
| 204 |
|
290 |
|
|
Lines 209-218
Link Here
|
| 209 |
if (current.pattern.regex) { /* line pattern defined by a "match" */ |
295 |
if (current.pattern.regex) { /* line pattern defined by a "match" */ |
| 210 |
result = current.result; |
296 |
result = current.result; |
| 211 |
end = start + result[0].length; |
297 |
end = start + result[0].length; |
| 212 |
var tokenStyle = {start: offset + start, end: offset + end, style: current.pattern.pattern.name}; |
298 |
var tokenStyle = {start: /*offset +*/ start, end: /*offset +*/ end, style: current.pattern.pattern.name}; |
| 213 |
if (!ignoreCaptures) { |
299 |
if (!ignoreCaptures) { |
| 214 |
if (current.pattern.pattern.captures) { |
300 |
if (current.pattern.pattern.captures) { |
| 215 |
getCaptureStyles(result, current.pattern.pattern.captures, offset + start, substyles); |
301 |
getCaptureStyles(result, current.pattern.pattern.captures, /*offset +*/ start, substyles); |
| 216 |
} |
302 |
} |
| 217 |
substyles.sort(function(a,b) { |
303 |
substyles.sort(function(a,b) { |
| 218 |
if (a.start < b.start) { |
304 |
if (a.start < b.start) { |
|
Lines 240-270
Link Here
|
| 240 |
var endRegex = current.pattern.regexEnd; |
326 |
var endRegex = current.pattern.regexEnd; |
| 241 |
endRegex = substituteCaptureValues(endRegex, current.result); |
327 |
endRegex = substituteCaptureValues(endRegex, current.result); |
| 242 |
|
328 |
|
| 243 |
result = _findMatch(endRegex, text, current.result.index + current.result[0].length); |
329 |
result = _findMatch(endRegex, model, current.result.index + current.result[0].length, endIndex); |
| 244 |
if (!result) { |
330 |
if (!result) { |
| 245 |
eolRegex.lastIndex = 0; |
331 |
eolRegex.lastIndex = 0; |
| 246 |
result = eolRegex.exec(text); |
332 |
result = _findMatch(eolRegex, model, /*startIndex*/endIndex, endIndex); // TODO verify that this works |
| 247 |
} |
333 |
} |
| 248 |
end = result.index + result[0].length; |
334 |
end = result.index + result[0].length; |
| 249 |
styles.push({start: offset + start, end: offset + end, style: current.pattern.pattern.name}); |
335 |
styles.push({start: /*offset +*/ start, end: /*offset +*/ end, style: current.pattern.pattern.name}); |
| 250 |
} |
336 |
} |
| 251 |
index = result.index + result[0].length; |
337 |
index = result.index + result[0].length; |
| 252 |
updateMatch(current, text, matches, index); |
338 |
updateMatch(current, matches, model, index, endIndex); |
| 253 |
} |
339 |
} |
| 254 |
patterns.forEach(function(current) { |
340 |
patterns.forEach(function(current) { |
| 255 |
var regex = current.regex || current.regexBegin; |
341 |
var regex = current.regex || current.regexBegin; |
| 256 |
regex.lastIndex = regex.oldLastIndex; |
342 |
regex.lastIndex = regex.oldLastIndex; |
| 257 |
}); |
343 |
}); |
| 258 |
}; |
344 |
}; |
| 259 |
var computeBlocks = function(model, text, block, offset) { |
345 |
var computeBlocks = function(model, startIndex, endIndex, block/*, offset*/) { |
| 260 |
if (!text) { |
346 |
if (startIndex === endIndex) { |
| 261 |
return []; |
347 |
return []; |
| 262 |
} |
348 |
} |
| 263 |
|
349 |
|
| 264 |
var results = []; |
350 |
var results = []; |
| 265 |
var matches = []; |
351 |
var matches = []; |
| 266 |
block.getBlockPatterns().forEach(function(current) { |
352 |
block.getBlockPatterns().forEach(function(current) { |
| 267 |
var result = _findMatch(current.regexBegin || current.regex, text, 0); |
353 |
var result = _findMatch(current.regexBegin || current.regex, model, startIndex, endIndex); |
| 268 |
if (result) { |
354 |
if (result) { |
| 269 |
matches.push({result: result, pattern: current}); |
355 |
matches.push({result: result, pattern: current}); |
| 270 |
} |
356 |
} |
|
Lines 289-299
Link Here
|
| 289 |
|
375 |
|
| 290 |
if (current.result.index < index) { |
376 |
if (current.result.index < index) { |
| 291 |
/* processing of another match has moved index beyond this match */ |
377 |
/* processing of another match has moved index beyond this match */ |
| 292 |
updateMatch(current, text, matches, index); |
378 |
updateMatch(current, matches, model, index, endIndex); |
| 293 |
continue; |
379 |
continue; |
| 294 |
} |
380 |
} |
| 295 |
|
381 |
|
| 296 |
var start = offset + current.result.index; |
382 |
var start = /*offset +*/ current.result.index; |
| 297 |
var contentStart = current.result.index; |
383 |
var contentStart = current.result.index; |
| 298 |
var resultEnd = null; |
384 |
var resultEnd = null; |
| 299 |
|
385 |
|
|
Lines 335-366
Link Here
|
| 335 |
|
421 |
|
| 336 |
var lastIndex = contentStart; |
422 |
var lastIndex = contentStart; |
| 337 |
while (!resultEnd) { |
423 |
while (!resultEnd) { |
| 338 |
var result = _findMatch(endRegex, text, lastIndex); |
424 |
var result = _findMatch(resolvedEndRegex, model, lastIndex, endIndex); |
| 339 |
if (!result) { |
425 |
if (!result) { |
| 340 |
eolRegex.lastIndex = 0; |
426 |
eolRegex.lastIndex = 0; |
| 341 |
result = eolRegex.exec(text); |
427 |
result = _findMatch(eolRegex, model, /*startIndex*/endIndex, endIndex); // TODO verify that this works |
| 342 |
} |
428 |
} |
| 343 |
var testBlock = new Block( |
429 |
var testBlock = new Block( |
| 344 |
{ |
430 |
{ |
| 345 |
start: start, |
431 |
start: start, |
| 346 |
end: offset + result.index + result[0].length, |
432 |
end: /*offset +*/ result.index + result[0].length, |
| 347 |
contentStart: offset + contentStart, |
433 |
contentStart: /*offset +*/ contentStart, |
| 348 |
contentEnd: offset + result.index |
434 |
contentEnd: /*offset +*/ result.index |
| 349 |
}, |
435 |
}, |
| 350 |
testPattern, |
436 |
testPattern, |
| 351 |
block.getStyler(), |
437 |
block.getStyler(), |
| 352 |
model, |
438 |
model, |
| 353 |
block); |
439 |
block); |
| 354 |
var subBlocks = testBlock.getBlocks(); |
440 |
var subBlocks = testBlock.getBlocks(); |
| 355 |
if (!subBlocks.length || subBlocks[subBlocks.length - 1].end <= (result.index + offset)) { |
441 |
if (!subBlocks.length || subBlocks[subBlocks.length - 1].end <= (result.index /*+ offset*/)) { |
| 356 |
resultEnd = testBlock; |
442 |
resultEnd = testBlock; |
| 357 |
} |
443 |
} |
| 358 |
lastIndex = result.index + result[0].length; |
444 |
lastIndex = result.index + result[0].length; |
| 359 |
} |
445 |
} |
| 360 |
} |
446 |
} |
| 361 |
results.push(resultEnd); |
447 |
results.push(resultEnd); |
| 362 |
index = resultEnd.end - offset; |
448 |
index = resultEnd.end/*- offset*/; |
| 363 |
updateMatch(current, text, matches, index); |
449 |
updateMatch(current, matches, model, index, endIndex); |
| 364 |
} |
450 |
} |
| 365 |
return results; |
451 |
return results; |
| 366 |
}; |
452 |
}; |
|
Lines 372-378
Link Here
|
| 372 |
var subPatterns = block.getLinePatterns(); |
458 |
var subPatterns = block.getLinePatterns(); |
| 373 |
if (subPatterns.length && block.pattern && block.pattern.pattern.name && block.pattern.pattern.name.indexOf("comment") === 0) { |
459 |
if (subPatterns.length && block.pattern && block.pattern.pattern.name && block.pattern.pattern.name.indexOf("comment") === 0) { |
| 374 |
var substyles = []; |
460 |
var substyles = []; |
| 375 |
parse(baseModel.getText(block.contentStart, block.end), block.contentStart, block, substyles, true); |
461 |
parse(baseModel, block.contentStart, block.end, block, substyles, true); |
| 376 |
for (var i = 0; i < substyles.length; i++) { |
462 |
for (var i = 0; i < substyles.length; i++) { |
| 377 |
if (substyles[i].style === "meta.annotation.task.todo") { |
463 |
if (substyles[i].style === "meta.annotation.task.todo") { |
| 378 |
annotations.push(mAnnotations.AnnotationType.createAnnotation(annotationType, substyles[i].start, substyles[i].end, baseModel.getText(substyles[i].start, substyles[i].end))); |
464 |
annotations.push(mAnnotations.AnnotationType.createAnnotation(annotationType, substyles[i].start, substyles[i].end, baseModel.getText(substyles[i].start, substyles[i].end))); |
|
Lines 489-495
Link Here
|
| 489 |
this._enclosurePatterns = {}; |
575 |
this._enclosurePatterns = {}; |
| 490 |
if (model) { |
576 |
if (model) { |
| 491 |
this._initPatterns(); |
577 |
this._initPatterns(); |
| 492 |
this._subBlocks = computeBlocks(model, model.getText(this.start, this.end), this, this.start); |
578 |
this._subBlocks = computeBlocks(model, this.start, this.end, this, 0/*, this.start*/); // TODO should the bounds be contentStart/contentEnd? |
| 493 |
} |
579 |
} |
| 494 |
} |
580 |
} |
| 495 |
Block.prototype = { |
581 |
Block.prototype = { |
|
Lines 730-738
Link Here
|
| 730 |
} |
816 |
} |
| 731 |
var block = this._findBlock(this._rootBlock, offset); |
817 |
var block = this._findBlock(this._rootBlock, offset); |
| 732 |
var lineIndex = model.getLineAtOffset(offset); |
818 |
var lineIndex = model.getLineAtOffset(offset); |
| 733 |
var lineText = model.getLine(lineIndex); |
|
|
| 734 |
var styles = []; |
819 |
var styles = []; |
| 735 |
parse(lineText, model.getLineStart(lineIndex), block, styles); |
820 |
parse(model, model.getLineStart(lineIndex), model.getLineEnd(lineIndex), block, styles); |
| 736 |
for (var i = 0; i < styles.length; i++) { |
821 |
for (var i = 0; i < styles.length; i++) { |
| 737 |
if (offset < styles[i].start) { |
822 |
if (offset < styles[i].start) { |
| 738 |
break; |
823 |
break; |
|
Lines 871-876
Link Here
|
| 871 |
return result; |
956 |
return result; |
| 872 |
}, |
957 |
}, |
| 873 |
_findMatchingBracket: function(model, block, offset) { |
958 |
_findMatchingBracket: function(model, block, offset) { |
|
|
959 |
if (1) return -1; |
| 960 |
|
| 874 |
var lineIndex = model.getLineAtOffset(offset); |
961 |
var lineIndex = model.getLineAtOffset(offset); |
| 875 |
var lineEnd = model.getLineEnd(lineIndex); |
962 |
var lineEnd = model.getLineEnd(lineIndex); |
| 876 |
var text = model.getText(offset, lineEnd); |
963 |
var text = model.getText(offset, lineEnd); |
|
Lines 978-1005
Link Here
|
| 978 |
_getPatternManager: function() { |
1065 |
_getPatternManager: function() { |
| 979 |
return this.patternManager; |
1066 |
return this.patternManager; |
| 980 |
}, |
1067 |
}, |
| 981 |
_getStyles: function(block, model, text, start) { |
1068 |
_getStyles: function(block, model, startIndex, endIndex) { |
| 982 |
if (model.getBaseModel) { |
1069 |
// if (model.getBaseModel) { // TODO verify that this works with blocks folded |
| 983 |
start = model.mapOffset(start); |
1070 |
// start = model.mapOffset(start); |
| 984 |
} |
1071 |
// } |
| 985 |
var end = start + text.length; |
1072 |
// var end = start + text.length; |
| 986 |
|
1073 |
|
| 987 |
var styles = []; |
1074 |
var styles = []; |
| 988 |
var offset = start, blocks = block.getBlocks(); |
1075 |
var offset = startIndex, blocks = block.getBlocks(); |
| 989 |
var startIndex = this._binarySearch(blocks, start, true); |
1076 |
var blockStartIndex = this._binarySearch(blocks, startIndex, true); |
| 990 |
for (var i = startIndex; i < blocks.length; i++) { |
1077 |
for (var i = blockStartIndex; i < blocks.length; i++) { |
| 991 |
if (blocks[i].start >= end) { break; } |
1078 |
if (blocks[i].start >= endIndex) { break; } |
| 992 |
var blockStart = blocks[i].start; |
1079 |
var blockStart = blocks[i].start; |
| 993 |
var blockEnd = blocks[i].end; |
1080 |
var blockEnd = blocks[i].end; |
| 994 |
if (offset < blockStart) { |
1081 |
if (offset < blockStart) { |
| 995 |
/* content on that line that preceeds the start of the block */ |
1082 |
/* content on that line that preceeds the start of the block */ |
| 996 |
parse(text.substring(offset - start, blockStart - start), offset, block, styles); |
1083 |
parse(model, offset/* - start*/, blockStart/* - start*/, block, styles); |
| 997 |
} |
1084 |
} |
| 998 |
var s = Math.max(offset, blockStart); |
1085 |
var s = Math.max(offset, blockStart); |
| 999 |
if (s === blockStart) { |
1086 |
if (s === blockStart) { |
| 1000 |
/* currently at the block's "start" match, which specifies its style by either a capture or name */ |
1087 |
/* currently at the block's "start" match, which specifies its style by either a capture or name */ |
| 1001 |
if (blocks[i].pattern.regexBegin) { |
1088 |
if (blocks[i].pattern.regexBegin) { |
| 1002 |
var result = _findMatch(blocks[i].pattern.regexBegin, text.substring(s - start), 0); |
1089 |
var result = _findMatch(blocks[i].pattern.regexBegin, model, s - startIndex, model.getCharCount()); |
| 1003 |
if (result) { |
1090 |
if (result) { |
| 1004 |
/* the begin match is still valid */ |
1091 |
/* the begin match is still valid */ |
| 1005 |
var captures = blocks[i].pattern.pattern.beginCaptures || blocks[i].pattern.pattern.captures; |
1092 |
var captures = blocks[i].pattern.pattern.beginCaptures || blocks[i].pattern.pattern.captures; |
|
Lines 1017-1029
Link Here
|
| 1017 |
* Compute the end match now in order to determine the end-bound of the contained content, but do not add the |
1104 |
* Compute the end match now in order to determine the end-bound of the contained content, but do not add the |
| 1018 |
* end match's styles to the styles array until content styles have been computed so that ordering is preserved. |
1105 |
* end match's styles to the styles array until content styles have been computed so that ordering is preserved. |
| 1019 |
*/ |
1106 |
*/ |
| 1020 |
var e = Math.min(end, blockEnd); |
1107 |
var e = Math.min(endIndex, blockEnd); |
| 1021 |
var endStyles = []; |
1108 |
var endStyles = []; |
| 1022 |
if (e === blockEnd) { |
1109 |
if (e === blockEnd) { |
| 1023 |
/* currently at the block's "end" match, which specifies its style by either a capture or name */ |
1110 |
/* currently at the block's "end" match, which specifies its style by either a capture or name */ |
| 1024 |
if (blocks[i].pattern.regexEnd) { |
1111 |
if (blocks[i].pattern.regexEnd) { |
| 1025 |
var testString = text.substring(e - offset - (blocks[i].end - blocks[i].contentEnd)); |
1112 |
var result = _findMatch(blocks[i].pattern.regexEnd, model, e - offset - (blocks[i].end - blocks[i].contentEnd), model.getCharCount()); |
| 1026 |
var result = _findMatch(blocks[i].pattern.regexEnd, testString, 0); |
|
|
| 1027 |
if (result) { |
1113 |
if (result) { |
| 1028 |
/* the end match is still valid */ |
1114 |
/* the end match is still valid */ |
| 1029 |
var captures = blocks[i].pattern.pattern.endCaptures || blocks[i].pattern.pattern.captures; |
1115 |
var captures = blocks[i].pattern.pattern.endCaptures || blocks[i].pattern.pattern.captures; |
|
Lines 1037-1043
Link Here
|
| 1037 |
} |
1123 |
} |
| 1038 |
} |
1124 |
} |
| 1039 |
|
1125 |
|
| 1040 |
var blockSubstyles = this._getStyles(blocks[i], model, text.substring(s - start, e - start), s); |
1126 |
var blockSubstyles = this._getStyles(blocks[i], model, s, e); |
| 1041 |
var blockStyle = blocks[i].pattern.pattern.contentName || blocks[i].pattern.pattern.name; |
1127 |
var blockStyle = blocks[i].pattern.pattern.contentName || blocks[i].pattern.pattern.name; |
| 1042 |
if (blockStyle) { |
1128 |
if (blockStyle) { |
| 1043 |
/* |
1129 |
/* |
|
Lines 1061-1069
Link Here
|
| 1061 |
styles = styles.concat(endStyles); |
1147 |
styles = styles.concat(endStyles); |
| 1062 |
offset = blockEnd; |
1148 |
offset = blockEnd; |
| 1063 |
} |
1149 |
} |
| 1064 |
if (offset < end) { |
1150 |
if (offset < endIndex) { |
| 1065 |
/* content on that line that follows the end of the block */ |
1151 |
/* content on that line that follows the end of the block */ |
| 1066 |
parse(text.substring(offset - start, end - start), offset, block, styles); |
1152 |
parse(model, offset, endIndex, block, styles); |
| 1067 |
} |
1153 |
} |
| 1068 |
if (model.getBaseModel) { |
1154 |
if (model.getBaseModel) { |
| 1069 |
for (var j = 0; j < styles.length; j++) { |
1155 |
for (var j = 0; j < styles.length; j++) { |
|
Lines 1084-1093
Link Here
|
| 1084 |
if (e.textView === this.view) { |
1170 |
if (e.textView === this.view) { |
| 1085 |
e.style = this._getLineStyle(e.lineIndex); |
1171 |
e.style = this._getLineStyle(e.lineIndex); |
| 1086 |
} |
1172 |
} |
| 1087 |
e.ranges = this._getStyles(this._rootBlock, e.textView.getModel(), e.lineText, e.lineStart); |
1173 |
var model = e.textView.getModel(); |
|
|
1174 |
e.ranges = this._getStyles(this._rootBlock, model, e.lineStart, model.getLineEnd(e.lineIndex)); |
| 1088 |
e.ranges.forEach(function(current) { |
1175 |
e.ranges.forEach(function(current) { |
| 1089 |
if (current.style) { |
1176 |
if (current.style) { |
| 1090 |
current.style = {styleClass: current.style.replace(/\./g, " ")}; |
1177 |
current.style = {styleClass: current.style.replace(/\./g, " ")}; //$NON-NLS-1$ |
| 1091 |
} |
1178 |
} |
| 1092 |
}); |
1179 |
}); |
| 1093 |
if (this._isRenderingWhitespace()) { |
1180 |
if (this._isRenderingWhitespace()) { |
|
Lines 1212-1218
Link Here
|
| 1212 |
te = charCount; //TODO could it be smaller? |
1299 |
te = charCount; //TODO could it be smaller? |
| 1213 |
} |
1300 |
} |
| 1214 |
var text = baseModel.getText(ts, te), block; |
1301 |
var text = baseModel.getText(ts, te), block; |
| 1215 |
newBlocks = computeBlocks(baseModel, text, this._rootBlock, ts); |
1302 |
var startTime = new Date().getTime(); |
|
|
1303 |
newBlocks = computeBlocks(baseModel, ts, te, this._rootBlock, 0/*ts*/); |
| 1304 |
var endTime = new Date().getTime(); |
| 1305 |
window.console.log(endTime - startTime); |
| 1216 |
} while (newBlocks.length && blocks.length && blockEnd < blockCount && newBlocks[newBlocks.length - 1].pattern.pattern.id !== blocks[blockEnd - 1].pattern.pattern.id); |
1306 |
} while (newBlocks.length && blocks.length && blockEnd < blockCount && newBlocks[newBlocks.length - 1].pattern.pattern.id !== blocks[blockEnd - 1].pattern.pattern.id); |
| 1217 |
|
1307 |
|
| 1218 |
for (var i = blockStart; i < blocks.length; i++) { |
1308 |
for (var i = blockStart; i < blocks.length; i++) { |