mirror of
https://github.com/codex-team/editor.js
synced 2026-03-18 08:29:52 +01:00
fix(onchange): fire mutation event if there are other changes along with mutation-free nodes
This commit is contained in:
parent
34d4b028c4
commit
3a653a90c8
2 changed files with 11 additions and 9 deletions
|
|
@ -204,8 +204,17 @@ export default class Block extends EventsDispatcher<BlockEvents> {
|
|||
* Is fired when DOM mutation has been happened
|
||||
*/
|
||||
private didMutated = _.debounce((mutationsOrInputEvent: MutationRecord[] | InputEvent = []): void => {
|
||||
/**
|
||||
* We won't fire a Block mutation event for nodes that contain 'data-mutation-free' attributes
|
||||
*
|
||||
* Update from 2023, Feb 17:
|
||||
* Changed mutationsOrInputEvent.some() to mutationsOrInputEvent.every()
|
||||
* since there could be a real mutations same-time with mutation-free changes,
|
||||
* for example when Block Tune change: block is changing along with FakeCursor (mutation-free) removing
|
||||
* — we should fire 'didMutated' event in that case
|
||||
*/
|
||||
const shouldFireUpdate = mutationsOrInputEvent instanceof InputEvent ||
|
||||
!mutationsOrInputEvent.some(({
|
||||
!mutationsOrInputEvent.every(({
|
||||
addedNodes = [],
|
||||
removedNodes,
|
||||
}) => {
|
||||
|
|
|
|||
|
|
@ -221,14 +221,7 @@ describe('onChange callback', () => {
|
|||
.click();
|
||||
|
||||
cy.get('[data-cy=editorjs]')
|
||||
.get('span.cdx-settings-button[data-level=4]')
|
||||
.click()
|
||||
/**
|
||||
* For some reason, the first click fires the mutation of removeFakeCursor only, so we need to click again.
|
||||
* Reproduced only in Cypress.
|
||||
*
|
||||
* @todo debug it later
|
||||
*/
|
||||
.get('.ce-settings .ce-popover-item:nth-child(4)')
|
||||
.click();
|
||||
|
||||
cy.get('@onChange').should('be.calledWithMatch', EditorJSApiMock, Cypress.sinon.match({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue