Skip to content

Commit 8b328ed

Browse files
authoredJun 30, 2019
[Fix]: Handle native inputs changes (#815)
1 parent b64b41c commit 8b328ed

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed
 

Diff for: ‎dist/editor.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎docs/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- `Improvements` — Inline Toolbar now works on mobile devices [#706](https://github.com/codex-team/editor.js/issues/706)
66
- `Improvements` — Toolbar looks better on mobile devices [#706](https://github.com/codex-team/editor.js/issues/706)
7+
- `Fix` — EditorConfig's `onChange` callback now fires when native inputs\` content has been changed [#794](https://github.com/codex-team/editor.js/issues/794)
78
- `New` — New [`blocks.insert()`](api.md) API method [#715](https://github.com/codex-team/editor.js/issues/715).
89
- `Deprecated`[`blocks.insertNewBlock()`](api.md) method is deprecated. Use `blocks.insert()` instead.
910
- `Fix` — Resolve bug with deleting leading new lines [#726](https://github.com/codex-team/editor.js/issues/726)

Diff for: ‎src/components/modules/modificationsObserver.ts

+23
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,24 @@ export default class ModificationsObserver extends Module {
3232
* @type {Function}
3333
*/
3434
private mutationDebouncer = _.debounce( () => {
35+
this.updateNativeInputs();
3536
this.config.onChange();
3637
}, ModificationsObserver.DebounceTimer);
3738

39+
/**
40+
* Array of native inputs in Blocks.
41+
* Changes in native inputs are not handled by modification observer, so we need to set change event listeners on them
42+
*/
43+
private nativeInputs: HTMLElement[] = [];
44+
3845
/**
3946
* Clear timeout and set null to mutationDebouncer property
4047
*/
4148
public destroy() {
4249
this.mutationDebouncer = null;
4350
this.observer.disconnect();
4451
this.observer = null;
52+
this.nativeInputs.forEach((input) => this.Editor.Listeners.off(input, 'input', this.mutationDebouncer));
4553
}
4654

4755
/**
@@ -142,4 +150,19 @@ export default class ModificationsObserver extends Module {
142150
this.mutationDebouncer();
143151
}
144152
}
153+
154+
/**
155+
* Gets native inputs and set oninput event handler
156+
*/
157+
private updateNativeInputs(): void {
158+
if (this.nativeInputs) {
159+
this.nativeInputs.forEach((input) => {
160+
this.Editor.Listeners.off(input, 'input');
161+
});
162+
}
163+
164+
this.nativeInputs = Array.from(this.Editor.UI.nodes.redactor.querySelectorAll('textarea, input, select'));
165+
166+
this.nativeInputs.forEach((input) => this.Editor.Listeners.on(input, 'input', this.mutationDebouncer));
167+
}
145168
}

0 commit comments

Comments
 (0)