Skip to content

Commit 5d7d04c

Browse files
committed
fix: lose selection in controlled mode
1 parent ad70de8 commit 5d7d04c

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/editor/index.tsx

+16-11
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,16 @@ class Editor extends React.Component<EditorProps, EditorState> {
485485
if (this.state.text === value) {
486486
return;
487487
}
488-
this.setState(
489-
{
490-
text: value,
491-
},
492-
() => {
493-
emitter.emit(emitter.EVENT_CHANGE, value, event, typeof event === 'undefined');
494-
if (newSelection) {
495-
setTimeout(() => this.setSelection(newSelection));
496-
}
497-
},
498-
);
488+
this.setState({
489+
text: value,
490+
});
491+
if (this.props.onChange) {
492+
this.props.onChange({ text, html: this.getHtmlValue() }, event);
493+
}
494+
emitter.emit(emitter.EVENT_CHANGE, value, event, typeof event === 'undefined');
495+
if (newSelection) {
496+
setTimeout(() => this.setSelection(newSelection));
497+
}
499498
if (!this.hasContentChanged) {
500499
this.hasContentChanged = true;
501500
}
@@ -576,6 +575,12 @@ class Editor extends React.Component<EditorProps, EditorState> {
576575
return emitter.EVENT_VIEW_CHANGE;
577576
case 'keydown':
578577
return emitter.EVENT_KEY_DOWN;
578+
case 'blur':
579+
return emitter.EVENT_BLUR;
580+
case 'focus':
581+
return emitter.EVENT_FOCUS;
582+
case 'scroll':
583+
return emitter.EVENT_SCROLL;
579584
}
580585
}
581586
/**

src/share/var.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22

33
export type UploadFunc = ((file: File) => Promise<string>) | ((file: File, callback: (url: string) => void) => void);
44

5-
export type EditorEvent = 'change' | 'fullscreen' | 'viewchange' | 'keydown';
5+
export type EditorEvent = 'change' | 'fullscreen' | 'viewchange' | 'keydown' | 'focus' | 'blur' | 'scroll';
66

77
export interface EditorConfig {
88
theme?: string;

0 commit comments

Comments
 (0)