// writearea.test.mjs — the empty area's drag holds a stale anchor inside // the document (build note 84): a document shortened mid-drag, by a // teammate's merge, must not throw. import { test } from 'node:test' import assert from 'node:assert/strict' import { EditorState } from 'prosemirror-state' import { createSchema } from './schema.mjs' import { mount } from './fidelity.mjs' import { select } from './writearea.mjs' function viewOf (body) { const schema = createSchema(() => null) const view = { state: EditorState.create({ doc: mount(schema, body).doc }), dispatch: tr => { view.state = view.state.apply(tr) } } return view } test('a drag whose anchor the document no longer reaches selects to its end', () => { const view = viewOf('Short now.') const size = view.state.doc.content.size assert.doesNotThrow(() => select(view, size + 40, 3)) assert.equal(view.state.selection.from, 3) assert.equal(view.state.selection.to, size - 1) assert.doesNotThrow(() => select(view, -5, size + 9)) })