how do i hide the codemirror caret #7118

Open
opened 2025-02-03 19:41:27 +01:00 by marijnh · 0 comments
marijnh commented 2025-02-03 19:41:27 +01:00 (Migrated from gitlab.com)

again, im working on a github clone except i want to hide the caret shown. how do i do this?

const c = {
    lineNumbers: true,
    mode: "javascript",
    theme: "csmpt-code", // custom theme
    gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
    lineWrapping: true,
    readOnly: true,
    autoCloseBrackets: {
      pairs: "()[]{}''\"\"``<>",
      triples: "",
      explode: "[]{}()<>",
    },
  };

        const e = CodeMirror.fromTextArea(textArea, c);

// Ensure that the editor is properly initialized
e.refresh(); // Refresh to handle any layout issues

// Focus the editor programmatically after initialization
e.focus(); // Focus the editor

// Set the code content
e.setValue(snippet.code);

// Function to remove 'CodeMirror-focused' class
const removeFocusedClass = () => {
  const wrapper = e.getWrapperElement();
  wrapper.classList.remove('CodeMirror-focused');
};

// Remove class initially
setTimeout(removeFocusedClass, 0);

// Continuously remove the 'CodeMirror-focused' class on focus
e.getWrapperElement().addEventListener('focus', removeFocusedClass, true);

again, im working on a github clone except i want to hide the caret shown. how do i do this? ```js const c = { lineNumbers: true, mode: "javascript", theme: "csmpt-code", // custom theme gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"], lineWrapping: true, readOnly: true, autoCloseBrackets: { pairs: "()[]{}''\"\"``<>", triples: "", explode: "[]{}()<>", }, }; const e = CodeMirror.fromTextArea(textArea, c); // Ensure that the editor is properly initialized e.refresh(); // Refresh to handle any layout issues // Focus the editor programmatically after initialization e.focus(); // Focus the editor // Set the code content e.setValue(snippet.code); // Function to remove 'CodeMirror-focused' class const removeFocusedClass = () => { const wrapper = e.getWrapperElement(); wrapper.classList.remove('CodeMirror-focused'); }; // Remove class initially setTimeout(removeFocusedClass, 0); // Continuously remove the 'CodeMirror-focused' class on focus e.getWrapperElement().addEventListener('focus', removeFocusedClass, true); ```
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/codemirror5#7118
No description provided.