Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACE editor annotations removes custome annotations for Code Ocean comments on Request for Comments page #2759

Open
seemantTUI opened this issue Jan 31, 2025 · 0 comments

Comments

@seemantTUI
Copy link

seemantTUI commented Jan 31, 2025

Hello,

Here’s the context to this issue:

Each file has an editable viewer (#commentitor.editor) where its content (file.content) is displayed alongside an option to add comments.
When adding a comment, everything works as expected: the comment is displayed, and it’s stored in the backend correctly.
After refreshing the page, comments are fetched from the backend and briefly appear, but they disappear after the file.content is rendered.
This issue only occurs for files of type html or js. For other file types (e.g., python), everything works fine.

Issue, ACE has syntax validation for some files a/c to their official website currently for JavaScript/CoffeeScript/CSS/XQuery.

When the syntax validation in ACE happens it sets its own annotations and somehow internally does not allow to set custom annotations. In our case we set custom annotations for code ocean comments. Therefore the comment box on the editor on Request for comments page comes for a fraction of second and then vanishes.

A work around for this is to set useWorker to false which disables the syntax validation for ACE editor.

    currentEditor.getSession().setOption("useWorker", false);

or to over come 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 .

      function setAnnotations(editor, fileid) {
        const session = editor.getSession();
        let customAnnotations = [];
        $.ajax({
            dataType: 'json',
            method: 'GET',
            url: Routes.comments_path(),
            data: { file_id: fileid }
        }).done(function (response) {
            $.each(response, function (index, comment) {
                comment.className = 'code-ocean_comment';
                comment.type = 'info'; // Required for proper rendering

                comment.custom = true;
            });

            customAnnotations.length = 0; // Clear previous custom annotations
            customAnnotations.push(...response);
            mergeAnnotations();
        });

        function mergeAnnotations() {
            let existingAnnotations = session.getAnnotations().filter(ann => !ann.custom);
            session.setAnnotations([...existingAnnotations, ...customAnnotations]);
        }

        // Ensure annotations are not overridden
        session.on('changeAnnotation', function () {
            mergeAnnotations();
        });
    }

For example: This is how comments are displayed if the file type is .py:

image

Now if the file type is .html or JS:

Adding the comment first time:

image

on refresh of page no comments is displayed:

image

Best Regards,
Seemant Singh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant