|
| 1 | +import {EditorState, TextSelection} from 'prosemirror-state'; |
| 2 | +import {EditorView} from 'prosemirror-view'; |
| 3 | +import {builders} from 'prosemirror-test-builder'; |
| 4 | + |
| 5 | +import {ExtensionsManager} from '../../../core'; |
| 6 | +import {BaseSchemaSpecs, BaseNode} from '../specs'; |
| 7 | +import {CodeSpecs, codeMarkName} from '../../markdown/Code/CodeSpecs'; |
| 8 | +import {BaseInputRules} from './index'; |
| 9 | + |
| 10 | +const { |
| 11 | + schema, |
| 12 | + plugins, |
| 13 | +} = new ExtensionsManager({ |
| 14 | + extensions: (builder) => |
| 15 | + builder.use(BaseSchemaSpecs, {}).use(CodeSpecs).use(BaseInputRules), |
| 16 | +}).build(); |
| 17 | + |
| 18 | +const {doc, p, c} = builders<'doc' | 'p', 'c'>(schema, { |
| 19 | + doc: {nodeType: BaseNode.Doc}, |
| 20 | + p: {nodeType: BaseNode.Paragraph}, |
| 21 | + c: {markType: codeMarkName}, |
| 22 | +}); |
| 23 | + |
| 24 | +describe('BaseInputRules ellipsis', () => { |
| 25 | + it('does not replace triple dots inside inline code', () => { |
| 26 | + const startDoc = doc(p(c('text<a>'))); |
| 27 | + const state = EditorState.create({ |
| 28 | + schema, |
| 29 | + doc: startDoc, |
| 30 | + selection: TextSelection.create(startDoc, startDoc.tag.a), |
| 31 | + plugins, |
| 32 | + }); |
| 33 | + const view = new EditorView(document.createElement('div'), {state}); |
| 34 | + |
| 35 | + const handled = view.someProp('handleTextInput', (f: any) => |
| 36 | + f(view, startDoc.tag.a, startDoc.tag.a, '...'), |
| 37 | + ); |
| 38 | + |
| 39 | + if (!handled) { |
| 40 | + view.dispatch(view.state.tr.insertText('...', startDoc.tag.a, startDoc.tag.a)); |
| 41 | + } |
| 42 | + |
| 43 | + expect(view.state.doc).toMatchNode(doc(p(c('text...')))); |
| 44 | + }); |
| 45 | + |
| 46 | + it('replaces triple dots in regular text', () => { |
| 47 | + const startDoc = doc(p('text<a>')); |
| 48 | + const state = EditorState.create({ |
| 49 | + schema, |
| 50 | + doc: startDoc, |
| 51 | + selection: TextSelection.create(startDoc, startDoc.tag.a), |
| 52 | + plugins, |
| 53 | + }); |
| 54 | + const view = new EditorView(document.createElement('div'), {state}); |
| 55 | + |
| 56 | + const handled = view.someProp('handleTextInput', (f: any) => |
| 57 | + f(view, startDoc.tag.a, startDoc.tag.a, '...'), |
| 58 | + ); |
| 59 | + |
| 60 | + if (!handled) { |
| 61 | + view.dispatch(view.state.tr.insertText('...', startDoc.tag.a, startDoc.tag.a)); |
| 62 | + } |
| 63 | + |
| 64 | + expect(view.state.doc).toMatchNode(doc(p('text…'))); |
| 65 | + }); |
| 66 | +}); |
0 commit comments