-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
ensureTrailingParagraph
config option
In some scenarios it is difficult to place a cursor after the last element. This ensures there's always space to select the position afterward and fixes a whole range of issues. It defaults to false otherwise it breaks a lot of tests.
- Loading branch information
Showing
14 changed files
with
256 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ExtensionMap } from '@test-fixtures/schema-helpers'; | ||
import { renderEditor } from 'jest-remirror'; | ||
import { ParagraphExtension, ParagraphExtensionOptions } from '../paragraph'; | ||
|
||
const { heading } = ExtensionMap.nodes; | ||
const create = (params: ParagraphExtensionOptions = { ensureTrailingParagraph: true }) => | ||
renderEditor({ | ||
plainNodes: [new ParagraphExtension({ ...params }), heading], | ||
}); | ||
|
||
describe('plugin', () => { | ||
let { | ||
add, | ||
nodes: { doc, p, heading: h }, | ||
} = create(); | ||
|
||
beforeEach(() => { | ||
({ | ||
add, | ||
nodes: { doc, p, heading: h }, | ||
} = create()); | ||
}); | ||
|
||
it('adds a new paragraph when needed', () => { | ||
const { state } = add(doc(h('Yo'))); | ||
expect(state.doc).toEqualRemirrorDocument(doc(h('Yo'), p())); | ||
}); | ||
|
||
it('does not add multiple paragraphs', () => { | ||
const { state } = add(doc(p('Yo'))); | ||
expect(state.doc).toEqualRemirrorDocument(doc(p('Yo'))); | ||
}); | ||
|
||
it('dynamically appends paragraphs', () => { | ||
const { state } = add(doc(p('Yo'), p('<cursor>'))).insertText('# Greatness'); | ||
expect(state.doc).toEqualRemirrorDocument(doc(p('Yo'), h('Greatness'), p())); | ||
}); | ||
|
||
it('does nothing when `ensureTrailingParagraph` is false', () => { | ||
({ | ||
add, | ||
nodes: { doc, p, heading: h }, | ||
} = create({ ensureTrailingParagraph: false })); | ||
|
||
const { state } = add(doc(p('Yo'), p('<cursor>'))).insertText('# Greatness'); | ||
expect(state.doc).toEqualRemirrorDocument(doc(p('Yo'), h('Greatness'))); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.