Skip to content

Commit

Permalink
fix: lose selection in controlled mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sylingd committed Jul 5, 2020
1 parent ad70de8 commit 5d7d04c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions src/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,16 @@ class Editor extends React.Component<EditorProps, EditorState> {
if (this.state.text === value) {
return;
}
this.setState(
{
text: value,
},
() => {
emitter.emit(emitter.EVENT_CHANGE, value, event, typeof event === 'undefined');
if (newSelection) {
setTimeout(() => this.setSelection(newSelection));
}
},
);
this.setState({
text: value,
});
if (this.props.onChange) {
this.props.onChange({ text, html: this.getHtmlValue() }, event);
}
emitter.emit(emitter.EVENT_CHANGE, value, event, typeof event === 'undefined');
if (newSelection) {
setTimeout(() => this.setSelection(newSelection));
}
if (!this.hasContentChanged) {
this.hasContentChanged = true;
}
Expand Down Expand Up @@ -576,6 +575,12 @@ class Editor extends React.Component<EditorProps, EditorState> {
return emitter.EVENT_VIEW_CHANGE;
case 'keydown':
return emitter.EVENT_KEY_DOWN;
case 'blur':
return emitter.EVENT_BLUR;
case 'focus':
return emitter.EVENT_FOCUS;
case 'scroll':
return emitter.EVENT_SCROLL;
}
}
/**
Expand Down
2 changes: 1 addition & 1 deletion src/share/var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';

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

export type EditorEvent = 'change' | 'fullscreen' | 'viewchange' | 'keydown';
export type EditorEvent = 'change' | 'fullscreen' | 'viewchange' | 'keydown' | 'focus' | 'blur' | 'scroll';

export interface EditorConfig {
theme?: string;
Expand Down

0 comments on commit 5d7d04c

Please sign in to comment.