Download this file
| 1 | // writearea.test.mjs — the empty area's drag holds a stale anchor inside |
| 2 | // the document (build note 84): a document shortened mid-drag, by a |
| 3 | // teammate's merge, must not throw. |
| 4 | import { test } from 'node:test' |
| 5 | import assert from 'node:assert/strict' |
| 6 | import { EditorState } from 'prosemirror-state' |
| 7 | import { createSchema } from './schema.mjs' |
| 8 | import { mount } from './fidelity.mjs' |
| 9 | import { select } from './writearea.mjs' |
| 10 | |
| 11 | function viewOf (body) { |
| 12 | const schema = createSchema(() => null) |
| 13 | const view = { |
| 14 | state: EditorState.create({ doc: mount(schema, body).doc }), |
| 15 | dispatch: tr => { view.state = view.state.apply(tr) } |
| 16 | } |
| 17 | return view |
| 18 | } |
| 19 | |
| 20 | test('a drag whose anchor the document no longer reaches selects to its end', () => { |
| 21 | const view = viewOf('Short now.') |
| 22 | const size = view.state.doc.content.size |
| 23 | assert.doesNotThrow(() => select(view, size + 40, 3)) |
| 24 | assert.equal(view.state.selection.from, 3) |
| 25 | assert.equal(view.state.selection.to, size - 1) |
| 26 | assert.doesNotThrow(() => select(view, -5, size + 9)) |
| 27 | }) |
| 28 | |