Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mark occurrences working with minimal editor
  • Loading branch information
lshanmug committed Dec 18, 2012
1 parent 02720d5 commit 774b6bb
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
Expand Up @@ -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,
Expand All @@ -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;
});
};
Expand Down Expand Up @@ -101,4 +126,4 @@ function(require, mTextView, mKeyBinding, mEditor, mEditorFeatures){
return "There are unsaved changes.";
}
};
});
});
36 changes: 36 additions & 0 deletions bundles/org.eclipse.orion.client.editor/web/orion/editor/editor.js
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -12,6 +12,8 @@
.annotation.matchingBracket,
.annotation.currentLine,
.annotation.matchingSearch,
.annotation.readOccurrence,
.annotation.writeOccurrence,
.annotation.currentSearch {
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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++];
Expand Down

0 comments on commit 774b6bb

Please sign in to comment.