Skip to content

Commit

Permalink
fix: bulleted/numbered list is not detected as change(fix #757) (#1020)
Browse files Browse the repository at this point in the history
* fix: initalize _ignoreChange in getCursorPosition function

* chore: add `change` event test case(ol, ul wysiwyg command)
  • Loading branch information
js87zz authored Jun 8, 2020
1 parent d9b9412 commit d03b508
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
20 changes: 17 additions & 3 deletions apps/editor/test/unit/wysiwygCommands/ol.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import EventManager from '@/eventManager';
import WwTableSelectionManager from '@/wwTableSelectionManager';

describe('OL', () => {
let wwe, sq, container;
let wwe, sq, container, eventManager;

beforeEach(() => {
beforeEach(done => {
container = document.createElement('div');
eventManager = new EventManager();
document.body.appendChild(container);

wwe = new WysiwygEditor(container, new EventManager());
wwe = new WysiwygEditor(container, eventManager);

wwe.init();

Expand All @@ -27,6 +28,11 @@ describe('OL', () => {
wwe.componentManager.addManager('list', WwListManager);
wwe.componentManager.addManager('tableSelection', WwTableSelectionManager);
sq.focus();

// wait for squire events routine
setTimeout(() => {
done();
}, 0);
});

// we need to wait squire input event process
Expand Down Expand Up @@ -263,4 +269,12 @@ describe('OL', () => {
expect(range.startOffset).toBe(startOffset);
expect(range.endOffset).toBe(endOffset);
});

it('should emit change event', () => {
eventManager.listen('change', editor => {
expect(editor).toBe(wwe);
});

OL.exec(wwe);
});
});
20 changes: 17 additions & 3 deletions apps/editor/test/unit/wysiwygCommands/ul.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import EventManager from '@/eventManager';
import WwTableSelectionManager from '@/wwTableSelectionManager';

describe('UL', () => {
let wwe, sq, container;
let wwe, sq, container, eventManager;

beforeEach(() => {
beforeEach(done => {
container = document.createElement('div');
eventManager = new EventManager();
document.body.appendChild(container);

wwe = new WysiwygEditor(container, new EventManager());
wwe = new WysiwygEditor(container, eventManager);

wwe.init();

Expand All @@ -27,6 +28,11 @@ describe('UL', () => {
wwe.componentManager.addManager('list', WwListManager);
wwe.componentManager.addManager('tableSelection', WwTableSelectionManager);
sq.focus();

// wait for squire events routine
setTimeout(() => {
done();
}, 0);
});

// we need to wait squire input event process
Expand Down Expand Up @@ -245,4 +251,12 @@ describe('UL', () => {
expect(range.startOffset).toBe(startOffset);
expect(range.endOffset).toBe(endOffset);
});

it('should emit change event', () => {
eventManager.listen('change', editor => {
expect(editor).toBe(wwe);
});

UL.exec(wwe);
});
});
1 change: 1 addition & 0 deletions libs/squire/build/squire-raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2993,6 +2993,7 @@ proto.getCursorPosition = function ( range ) {
parent = node.parentNode;
parent.removeChild( node );
mergeInlines( parent, range );
this._ignoreChange = false;
}
return rect;
};
Expand Down
4 changes: 2 additions & 2 deletions libs/squire/build/squire.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions libs/squire/source/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ proto.getCursorPosition = function ( range ) {
parent = node.parentNode;
parent.removeChild( node );
mergeInlines( parent, range );
this._ignoreChange = false;
}
return rect;
};
Expand Down

0 comments on commit d03b508

Please sign in to comment.