| author | Jayaprakash Arthanareeswaran | 2012-02-02 05:33:41 (EST) |
|---|---|---|
| committer | Mark Macdonald | 2012-02-13 10:36:56 (EST) |
| commit | 1d6d6c8323f4a0f5a0a8ec93f1b668a376088e97 (patch) (side-by-side diff) | |
| tree | a67eb7ea15d5fc2b5fceab77b786101c8e8293b2 | |
| parent | 5c507f5f62510afe156fe9748cbb970fe469ea47 (diff) | |
| download | org.eclipse.orion.client-1d6d6c8323f4a0f5a0a8ec93f1b668a376088e97.zip org.eclipse.orion.client-1d6d6c8323f4a0f5a0a8ec93f1b668a376088e97.tar.gz org.eclipse.orion.client-1d6d6c8323f4a0f5a0a8ec93f1b668a376088e97.tar.bz2 | |
Fix for bug 369289: Hook up CodeMirror error styles to annotation model in CodeMirrorStyler
| -rw-r--r-- | bundles/org.eclipse.orion.client.editor/web/orion/editor/mirror.js | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/mirror.js b/bundles/org.eclipse.orion.client.editor/web/orion/editor/mirror.js index cef9dda..b1f8dff 100644 --- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/mirror.js +++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/mirror.js @@ -733,6 +733,10 @@ define("orion/editor/mirror", ["orion/textview/eventTarget"], function(mEventTar modeApplier.highlight(lineIndex, Math.min(lineIndex + LINESTYLE_OVERSHOOT, lineCount - 1), true /*don't dispatch*/); style = modeApplier.getLineStyle(lineIndex); } + + var min = Number.MAX_VALUE, max = -1; + var model = this.textView.getModel(); + if (style) { // Now we have a style for the line. It may not be correct in the case where lineIndex is at the end of a large // buffer. But in that case, the highlight job kicked off by ModelChanged will eventually reach it and fix it up. @@ -740,8 +744,46 @@ define("orion/editor/mirror", ["orion/textview/eventTarget"], function(mEventTar if (rangesAndErrors) { e.ranges = rangesAndErrors[0]; - // TODO: deal with error annotations in rangesAndErrors[1] - // We should use code from aSyncStyler here + for (var i=0; i < e.ranges.length; i++) { + min = Math.min(min, model.getLineAtOffset(e.ranges[i].start)); + max = Math.max(max, model.getLineAtOffset(e.ranges[i].end)); + } + + //console.debug("Got style for lines " + (min+1) + " to " + (max+1)); + var annotationModel = this.annotationModel; + if (annotationModel) { + var toRemove = []; + var toAdd = []; + + if (rangesAndErrors[1]) { + for (var i=0; i < rangesAndErrors[1].length; i++) { + var error = rangesAndErrors[1][i]; + if (error.style.styleClass === "cm-error") { + toAdd.push({ + start: error.start, + end: error.end, + type: "orion.annotation.highlightError", + title: "Syntax error.", + html: "<div class='annotationHTML error'></div>", + rangeStyle: {styleClass: "annotationRange error"} + }); + } + } + + } + min = Math.max(min, 0); + max = Math.min(max, model.getLineCount() -1); + var annos = annotationModel.getAnnotations(model.getLineStart(min), model.getLineEnd(max)); + while (annos.hasNext()) { + var anno = annos.next(); + if (anno.type === "orion.annotation.highlightError") { + toRemove.push(anno); + } + } + annotationModel.replaceAnnotations(toRemove, toAdd); + //console.debug("Redrawing lines " + (min+1) + " to " + (max+1)); + this.textView.redrawLines(min, max+1); + } } } }, |

