
Setup
Step 1: Add Comment components
- Add the
Velt Commentscomponent to the root of your app. - This component is required to render comments in your app.
- Set the
text modeprop tofalseto hide the default text comment tool.
- React / Next.js
- Other Frameworks
Step 2: Install the Velt CodeMirror extension
Step 3: Configure the CodeMirror editor with the Velt Comments extension
- React / Next.js
- Other Frameworks
Step 4: Add a comment button to your CodeMirror editor
Add a button that users can click to add comments after selecting text. Important: When clicking a button, the browser moves focus to the button which clears the editor selection. You need to save the selection onmousedown (before focus changes) and restore it before adding the comment.
- React / Next.js
- Other Frameworks
Step 5: Call addComment to add a comment
- Call this method to add a comment to selected text in the CodeMirror editor. You can use this when the user clicks on the comment button or presses a keyboard shortcut.
- Params:
AddCommentRequest. It has the following properties:editor: instance of the CodeMirror EditorView.editorId: Id of the CodeMirror editor. Use this if you have multiple CodeMirror editors on the same page in your app. (optional)context: Add any custom metadata to the Comment Annotation. Learn more. (optional)
- React / Next.js
- Other Frameworks
Step 6: Render comments in CodeMirror editor
- Get the comment data from Velt SDK and render it in the CodeMirror editor.
- Params:
RenderCommentsRequest. It has the following properties:editor: Instance of the CodeMirror EditorView.editorId: Id of the CodeMirror editor. Use this if you have multiple CodeMirror editors on the same page in your app. (optional)commentAnnotations: Array of Comment Annotation objects.
- React / Next.js
- Other Frameworks
Step 7: Persist Velt Comment Marks (optional)
- By default, Velt comment marks (
<velt-comment-text>) are persisted in the CodeMirror editor by Velt SDK. When the editor loads and the Velt SDK initializes, the marks will be automatically added to the editor. - If you plan to store the contents of the CodeMirror editor on your end with the comment marks already included, you can disable this feature.
- Default:
true
Step 8: Style the commented text
- You can style the commented text by adding CSS for the
velt-comment-textelement.
APIs
CodemirrorVeltComments()
Creates the Velt Comments extension for CodeMirror.- Params:
config?:CodemirrorVeltCommentsConfigeditorId?: string- Unique identifier for this editor instance (for multi-editor scenarios)persistVeltMarks?: boolean- Whether to persist Velt marks. Default:true
- Returns: CodeMirror
Extension
- React / Next.js
- Other Frameworks
addComment()
Creates a comment annotation for the currently selected text in the editor.- Params:
request:AddCommentRequesteditor: EditorVieweditorId?: stringcontext?: object
- Returns:
Promise<void>
- React / Next.js
- Other Frameworks
renderComments()
Renders and highlights comment annotations in the editor.- Params:
request:RenderCommentsRequesteditor: EditorVieweditorId?: stringcommentAnnotations?:CommentAnnotation[]
- Returns:
void
- React / Next.js
- Other Frameworks

