Skip to content

Commit 8e1e08c

Browse files
committed
Line level comment box not displayed for file type html or js
The issue is with setting the Annotations, ACE syntax validation has its own annotations which removes/mendles with the custom annotations for our code ocean comments. This is a known issue refer the below github issue. securingsincity/react-ace#483 To overcome this I added a flag to our custom annotations and seperate it from the ACE annotations and then push them together as annotations by having an event Listener on change of annotation refer to the below code .
1 parent 33b3793 commit 8e1e08c

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

app/assets/javascripts/request_for_comments.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,33 @@ $(document).on('turbolinks:load', function () {
140140

141141
function setAnnotations(editor, fileid) {
142142
const session = editor.getSession();
143-
144-
const jqrequest = $.ajax({
143+
let customAnnotations = [];
144+
$.ajax({
145145
dataType: 'json',
146146
method: 'GET',
147147
url: Routes.comments_path(),
148-
data: {
149-
file_id: fileid
150-
}
151-
});
152-
153-
jqrequest.done(function (response) {
148+
data: { file_id: fileid }
149+
}).done(function (response) {
154150
$.each(response, function (index, comment) {
155151
comment.className = 'code-ocean_comment';
156-
comment.type = 'info'; // Required for the annotation to be rendered correctly (besides being hidden through CSS).
152+
comment.type = 'info'; // Required for proper rendering
153+
154+
comment.custom = true;
157155
});
158-
session.setAnnotations(response);
156+
157+
customAnnotations.length = 0; // Clear previous custom annotations
158+
customAnnotations.push(...response);
159+
mergeAnnotations();
160+
});
161+
162+
function mergeAnnotations() {
163+
let existingAnnotations = session.getAnnotations().filter(ann => !ann.custom);
164+
session.setAnnotations([...existingAnnotations, ...customAnnotations]);
165+
}
166+
167+
// Ensure annotations are not overridden
168+
session.on('changeAnnotation', function () {
169+
mergeAnnotations();
159170
});
160171
}
161172

0 commit comments

Comments
 (0)