| author | lshanmug | 2012-12-18 06:22:27 (EST) |
|---|---|---|
| committer | Silenio Quarti | 2013-01-24 10:41:28 (EST) |
| commit | 2b99dad62095274cd4e62e9fb45d4fa4888e68f7 (patch) (side-by-side diff) | |
| tree | 7eb259b6dc27f9bcfbbbaa17c07d592e6d3bb63a | |
| parent | 08dd87b8f1b3f825cb65260755f6b8394f514f4c (diff) | |
| download | org.eclipse.orion.client-2b99dad62095274cd4e62e9fb45d4fa4888e68f7.zip org.eclipse.orion.client-2b99dad62095274cd4e62e9fb45d4fa4888e68f7.tar.gz org.eclipse.orion.client-2b99dad62095274cd4e62e9fb45d4fa4888e68f7.tar.bz2 | |
Mark occurrences working with minimal editor
4 files changed, 91 insertions, 4 deletions
diff --git a/bundles/org.eclipse.orion.client.editor/web/examples/editor/minimaleditor.js b/bundles/org.eclipse.orion.client.editor/web/examples/editor/minimaleditor.js index 8110f45..cfde133 100644 --- a/bundles/org.eclipse.orion.client.editor/web/examples/editor/minimaleditor.js +++ b/bundles/org.eclipse.orion.client.editor/web/examples/editor/minimaleditor.js @@ -44,10 +44,11 @@ function(require, mTextView, mKeyBinding, mEditor, mEditorFeatures){ editor.setInput(null, null, null, true); var text = editor.getTextView().getText(); var problems = []; + var line, character; for (var i=0; i<text.length; i++) { if (text.charAt(i) === 'z') { - var line = editor.getTextView().getModel().getLineAtOffset(i) + 1; - var character = i - editor.getTextView().getModel().getLineStart(line); + line = editor.getTextView().getModel().getLineAtOffset(i) + 1; + character = i - editor.getTextView().getModel().getLineStart(line); problems.push({ start: character + 1, end: character + 1, @@ -57,6 +58,30 @@ function(require, mTextView, mKeyBinding, mEditor, mEditorFeatures){ } } editor.showProblems(problems); + + var occurrences = []; + var sel = editor.getTextView().getSelection(); + var word = editor.getTextView().getText(sel.start, sel.end); + var index = text.indexOf(word); + if (index !== -1) { + for (i = index; i < text.length - word.length; i++) { + var w = ''; + for (var j = 0; j < word.length; j++) { + w = w + text.charAt (i + j); + } + if (w === word) { + line = editor.getTextView().getModel().getLineAtOffset(i) + 1; + character = i - editor.getTextView().getModel().getLineStart(line); + occurrences.push({ + readAccess: (line % 2) === 0 ? false : true, + line: line + 1, + start: character + 1, + end: character + word.length, + description: ((line % 2) === 0 ? "write occurrence of " : "occurrence of ") + w }); + } + } + } + editor.showOccurrences(occurrences); return true; }); }; @@ -101,4 +126,4 @@ function(require, mTextView, mKeyBinding, mEditor, mEditorFeatures){ return "There are unsaved changes."; } }; -}); +});
\ No newline at end of file diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/editor.js b/bundles/org.eclipse.orion.client.editor/web/orion/editor/editor.js index e5f1d2a..71311f3 100644 --- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/editor.js +++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/editor.js @@ -603,6 +603,8 @@ define("orion/editor/editor", ['i18n!orion/editor/nls/messages', 'orion/textview styler.addAnnotationType(mAnnotations.AnnotationType.ANNOTATION_MATCHING_BRACKET); styler.addAnnotationType(mAnnotations.AnnotationType.ANNOTATION_CURRENT_BRACKET); styler.addAnnotationType(mAnnotations.AnnotationType.ANNOTATION_CURRENT_LINE); + styler.addAnnotationType(mAnnotations.AnnotationType.ANNOTATION_READ_OCCURRENCE); + styler.addAnnotationType(mAnnotations.AnnotationType.ANNOTATION_WRITE_OCCURRENCE); styler.addAnnotationType(HIGHLIGHT_ERROR_ANNOTATION); } } @@ -659,6 +661,8 @@ define("orion/editor/editor", ['i18n!orion/editor/nls/messages', 'orion/textview ruler.addAnnotationType(mAnnotations.AnnotationType.ANNOTATION_MATCHING_BRACKET); ruler.addAnnotationType(mAnnotations.AnnotationType.ANNOTATION_CURRENT_BRACKET); ruler.addAnnotationType(mAnnotations.AnnotationType.ANNOTATION_CURRENT_LINE); + ruler.addAnnotationType(mAnnotations.AnnotationType.ANNOTATION_READ_OCCURRENCE); + ruler.addAnnotationType(mAnnotations.AnnotationType.ANNOTATION_WRITE_OCCURRENCE); } this.setOverviewRulerVisible(true); } @@ -755,6 +759,38 @@ define("orion/editor/editor", ['i18n!orion/editor/nls/messages', 'orion/textview annotationModel.replaceAnnotations(remove, add); }, + showOccurrences: function(occurrences) { + var annotationModel = this._annotationModel; + if (!annotationModel) { + return; + } + var remove = [], add = []; + var model = annotationModel.getTextModel(); + var annotations = annotationModel.getAnnotations(0, model.getCharCount()), annotation; + while (annotations.hasNext()) { + annotation = annotations.next(); + if (annotation.type === mAnnotations.AnnotationType.ANNOTATION_READ_OCCURRENCE || annotation.type === mAnnotations.AnnotationType.ANNOTATION_WRITE_OCCURRENCE) { + remove.push(annotation); + } + } + if (occurrences) { + for (var i = 0; i < occurrences.length; i++) { + var occurrence = occurrences[i]; + if (occurrence) { + var lineIndex = occurrence.line - 1; + var lineStart = model.getLineStart(lineIndex); + var start = lineStart + occurrence.start - 1; + var end = lineStart + occurrence.end; + var type = occurrence.readAccess === true ? mAnnotations.AnnotationType.ANNOTATION_READ_OCCURRENCE : mAnnotations.AnnotationType.ANNOTATION_WRITE_OCCURRENCE; + var description = occurrence.description; + annotation = mAnnotations.AnnotationType.createAnnotation(type, start, end, description); + add.push(annotation); + } + } + } + annotationModel.replaceAnnotations(remove, add); + }, + /** * Reveals and selects a portion of text. * @param {Number} start diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/textview/annotations.css b/bundles/org.eclipse.orion.client.editor/web/orion/textview/annotations.css index 140c5d9..39c88cf 100644 --- a/bundles/org.eclipse.orion.client.editor/web/orion/textview/annotations.css +++ b/bundles/org.eclipse.orion.client.editor/web/orion/textview/annotations.css @@ -12,6 +12,8 @@ .annotation.matchingBracket,
.annotation.currentLine,
.annotation.matchingSearch,
+.annotation.readOccurrence,
+.annotation.writeOccurrence,
.annotation.currentSearch {
}
@@ -136,6 +138,14 @@ background-color: #53D1FF;
border: 1px solid black;
}
+.annotationOverview.readOccurrence {
+ background-color: lightgray;
+ border: 1px solid black;
+}
+.annotationOverview.writeOccurrence {
+ background-color: Gold;
+ border: 1px solid darkred;
+}
/* Styles for text range */
.annotationRange {
@@ -176,6 +186,12 @@ .annotationRange.currentSearch {
background-color: #53D1FF;
}
+.annotationRange.readOccurrence {
+ background-color: lightgray;
+}
+.annotationRange.writeOccurrence {
+ background-color: yellow;
+}
/* Styles for lines of text */
.annotationLine {
diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/textview/annotations.js b/bundles/org.eclipse.orion.client.editor/web/orion/textview/annotations.js index d6e5271..4938ca4 100644 --- a/bundles/org.eclipse.orion.client.editor/web/orion/textview/annotations.js +++ b/bundles/org.eclipse.orion.client.editor/web/orion/textview/annotations.js @@ -137,6 +137,14 @@ define("orion/textview/annotations", ['i18n!orion/textview/nls/messages', 'orion * Matching search annotation type.
*/
AnnotationType.ANNOTATION_MATCHING_SEARCH = "orion.annotation.matchingSearch"; //$NON-NLS-0$
+ /**
+ * Read Occurrence annotation type.
+ */
+ AnnotationType.ANNOTATION_READ_OCCURRENCE = "orion.annotation.readOccurrence"; //$NON-NLS-0$
+ /**
+ * Write Occurrence annotation type.
+ */
+ AnnotationType.ANNOTATION_WRITE_OCCURRENCE = "orion.annotation.writeOccurrence"; //$NON-NLS-0$
/** @private */
var annotationTypes = {};
@@ -216,6 +224,8 @@ define("orion/textview/annotations", ['i18n!orion/textview/nls/messages', 'orion registerType(AnnotationType.ANNOTATION_MATCHING_BRACKET);
registerType(AnnotationType.ANNOTATION_CURRENT_SEARCH);
registerType(AnnotationType.ANNOTATION_MATCHING_SEARCH);
+ registerType(AnnotationType.ANNOTATION_READ_OCCURRENCE);
+ registerType(AnnotationType.ANNOTATION_WRITE_OCCURRENCE);
registerType(AnnotationType.ANNOTATION_CURRENT_LINE, true);
AnnotationType.registerType(AnnotationType.ANNOTATION_FOLDING, FoldingAnnotation);
@@ -415,7 +425,7 @@ define("orion/textview/annotations", ['i18n!orion/textview/nls/messages', 'orion getAnnotations: function(start, end) {
var annotations = this._annotations, current;
//TODO binary search does not work for range intersection when there are overlaping ranges, need interval search tree for this
- var i = 0; + var i = 0;
var skip = function() {
while (i < annotations.length) {
var a = annotations[i++];
|

