Skip to content

Instantly share code, notes, and snippets.

View BrianHung's full-sized avatar
💻
LLMs + local-first apps = autocomplete

Brian Hung BrianHung

💻
LLMs + local-first apps = autocomplete
View GitHub Profile
@BrianHung
BrianHung / prosemirror-history-combine-commands.ts
Last active February 6, 2024 08:08 — forked from anarchang/prosemirror-history-combine-commands.ts
Combine commands on the ProseMirror undo stack
/**
* Given two commands (commandA and commandB), returns a new command that when applied
* to a ProseMirror state that uses the prosemirror-history plugin applies commandA and
* then commandB so that both commands are undone with a single undo action.
**/
const combineCommands =
(commandA: Command, commandB: Command) =>
(state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {
return commandA(state, (transactionA: Transaction) => {
const { state: stateA } = state.applyTransaction(transactionA)