Skip to content

Instantly share code, notes, and snippets.

@s-cork
s-cork / indentation_guides.ts
Last active July 23, 2022 13:01
Codemirror 6 indentation guides
import { RangeSetBuilder } from "@codemirror/state";
import { Extension } from "@codemirror/state";
import { Decoration, DecorationSet, EditorView, ViewPlugin, ViewUpdate, WidgetType } from "@codemirror/view";
export function indentationGuides(): Extension {
return [ViewPlugin.fromClass(IndentationGuides, { decorations: (v) => v.decorations }), indentationTheme];
}
// markers can be used at positions on a line over a range
const indentationMark = Decoration.mark({ class: "cm-indentation-guide" });
@s-cork
s-cork / codemirror.tsx
Last active September 15, 2021 07:11
Codemirror 6 with react
import React, { useEffect, useMemo, useCallback, useLayoutEffect, useState } from "react";
import { EditorView } from "@codemirror/view";
import { EditorState, Compartment, EditorStateConfig, StateEffect, Extension } from "@codemirror/state";
import { indentUnit } from "@codemirror/language";
/** creates an editor view from an initial state - destroys the view on cleanup */
export function useEditorView(initState: (() => EditorStateConfig) | EditorStateConfig = {}): EditorView {
const view = useMemo(
() => new EditorView({ state: EditorState.create(typeof initState === "function" ? initState() : initState) }),
[]
@s-cork
s-cork / gif.txt
Last active March 17, 2021 01:51
p5 skulpt
http://g.recordit.co/CWfjWxrBqz.gif