diff --git a/packages/apps/client/src/ScriptEditor/Editor.tsx b/packages/apps/client/src/ScriptEditor/Editor.tsx index d1a2ba1..eef2a8c 100644 --- a/packages/apps/client/src/ScriptEditor/Editor.tsx +++ b/packages/apps/client/src/ScriptEditor/Editor.tsx @@ -1,14 +1,14 @@ import React, { useEffect, useRef } from 'react' import { undo, redo, history } from 'prosemirror-history' import { keymap } from 'prosemirror-keymap' -import { EditorState, SelectionBookmark, TextSelection } from 'prosemirror-state' +import { EditorState, SelectionBookmark } from 'prosemirror-state' import { EditorView } from 'prosemirror-view' import { Fragment, Node, Slice } from 'prosemirror-model' import { baseKeymap } from 'prosemirror-commands' -import { ReplaceStep, replaceStep } from 'prosemirror-transform' +import { replaceStep } from 'prosemirror-transform' import { schema } from './scriptSchema' import 'prosemirror-view/style/prosemirror.css' -import { updateModel } from './plugins/updateModel' +import { EXTERNAL_STATE_CHANGE, updateModel } from './plugins/updateModel' import { readOnlyNodeFilter } from './plugins/readOnlyNodeFilter' import { randomId } from '../lib/lib' import { formatingKeymap } from './keymaps' @@ -101,7 +101,7 @@ export function Editor({ keymap(formatingKeymap), keymap(baseKeymap), readOnlyNodeFilter(), - updateModel(() => {}), + updateModel((lineId, change) => console.log(lineId, change)), ], doc, }) @@ -169,6 +169,7 @@ export function Editor({ if (!step) return const tr = editorState.tr.step(step) + tr.setMeta(EXTERNAL_STATE_CHANGE, true) let newState = editorState.apply(tr) if (selectionBookmark) newState = restoreSelection(newState, selectionBookmark) diff --git a/packages/apps/client/src/ScriptEditor/plugins/updateModel.ts b/packages/apps/client/src/ScriptEditor/plugins/updateModel.ts index a1952a0..2681c89 100644 --- a/packages/apps/client/src/ScriptEditor/plugins/updateModel.ts +++ b/packages/apps/client/src/ScriptEditor/plugins/updateModel.ts @@ -3,6 +3,8 @@ import { UILineId } from '../../model/UILine' import { Node } from 'prosemirror-model' import { schema } from '../scriptSchema' +export const EXTERNAL_STATE_CHANGE = 'externalStateChange' + export function updateModel(onChange?: (lineId: UILineId, contents: SomeContents) => void) { return new Plugin({ appendTransaction: (trs, oldState, newState) => { @@ -10,6 +12,7 @@ export function updateModel(onChange?: (lineId: UILineId, contents: SomeContents if (!anyChanges) return null for (const tr of trs) { + if (tr.getMeta(EXTERNAL_STATE_CHANGE)) return for (const step of tr.steps) { step.getMap().forEach((oldStart, oldEnd, newStart, newEnd) => { oldState.doc.nodesBetween(oldStart, oldEnd, (_node, _pos, parent) => { diff --git a/packages/apps/client/src/lib/mdParser/index.ts b/packages/apps/client/src/lib/mdParser/index.ts index 3080711..400796b 100644 --- a/packages/apps/client/src/lib/mdParser/index.ts +++ b/packages/apps/client/src/lib/mdParser/index.ts @@ -104,9 +104,9 @@ export default function createParser(): Parser { performance.mark('astFromMarkdownishEnd') - console.log(performance.measure('astFromMarkdownish', 'astFromMarkdownishBegin', 'astFromMarkdownishEnd')) + // console.log(performance.measure('astFromMarkdownish', 'astFromMarkdownishBegin', 'astFromMarkdownishEnd')) - console.log(document) + // console.log(document) return document }