Skip to content

Instantly share code, notes, and snippets.

@josephdpurcell
Created December 8, 2022 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephdpurcell/46f41a65a4195c3886f52c9e2ec20296 to your computer and use it in GitHub Desktop.
Save josephdpurcell/46f41a65a4195c3886f52c9e2ec20296 to your computer and use it in GitHub Desktop.
How to enable autocomplete and autocorrect on CodeMirror6

Setup dependencies:

npm init -y
npm i codemirror @codemirror/lang-javascript
npm i rollup @rollup/plugin-node-resolve

Create an editor:

editor.js

import {EditorView, basicSetup} from "codemirror"
import {javascript} from "@codemirror/lang-javascript"

let editor = new EditorView({
  extensions: [basicSetup, javascript()],
  parent: document.body
})

Bundle the editor:

node_modules/.bin/rollup editor.js -f iife -o editor.bundle.js   -p @rollup/plugin-node-resolve

Create an HTML page to load it:

index.html

<!doctype html>
<meta charset=utf8>
<h1>CodeMirror!</h1>
<script src="editor.bundle.js"></script>

Serve it using whatever:

browser-sync start --server --no-open --files "*.js" "demo/*.js" "*.css" "*.html" --serveStatic "./*" --port 8080 --host 0.0.0.0 --listen 0.0.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment