Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit b86b5ce

Browse files
flarniefacebook-github-bot
authored andcommitted
Pass synthetic event to 'handleBeforeInput' callback
Summary: For purposes of logging, so that we can get the exact timestamp from the event object for this event. Reviewed By: bvaughn Differential Revision: D7954113 fbshipit-source-id: 94e90385cd47bf0fe045d91fb8fb5167a1fffc05
1 parent fa88ee1 commit b86b5ce

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

docs/APIReference-Editor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ for details on usage.
225225

226226
#### handleBeforeInput
227227
```
228-
handleBeforeInput?: (chars: string, editorState: EditorState) => DraftHandleValue
228+
handleBeforeInput?: (chars: string, editorState: EditorState, eventTimeStamp: number) => DraftHandleValue
229229
```
230230
Handle the characters to be inserted from a `beforeInput` event. Returning `'handled'`
231231
causes the default behavior of the `beforeInput` event to be prevented (i.e. it is

src/component/base/DraftEditorProps.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export type DraftEditorProps = {
128128
handleBeforeInput?: (
129129
chars: string,
130130
editorState: EditorState,
131+
eventTimeStamp: number,
131132
) => DraftHandleValue,
132133

133134
handlePastedText?: (

src/component/handlers/composition/DraftEditorCompositionHandler.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ const DraftEditorCompositionHandler = {
7272
* twice could break the DOM, we only use the first event. Example: Arabic
7373
* Google Input Tools on Windows 8.1 fires `compositionend` three times.
7474
*/
75-
onCompositionEnd: function(editor: DraftEditor): void {
75+
onCompositionEnd: function(editor: DraftEditor, e: SyntheticEvent<>): void {
7676
resolved = false;
7777
stillComposing = false;
7878
setTimeout(() => {
7979
if (!resolved) {
80-
DraftEditorCompositionHandler.resolveComposition(editor);
80+
DraftEditorCompositionHandler.resolveComposition(editor, e);
8181
}
8282
}, RESOLVE_DELAY);
8383
},
@@ -93,7 +93,7 @@ const DraftEditorCompositionHandler = {
9393
// 20ms timer expires (ex: type option-E then backspace, or type A then
9494
// backspace in 2-Set Korean), we should immediately resolve the
9595
// composition and reinterpret the key press in edit mode.
96-
DraftEditorCompositionHandler.resolveComposition(editor);
96+
DraftEditorCompositionHandler.resolveComposition(editor, e);
9797
editor._onKeyDown(e);
9898
return;
9999
}
@@ -129,7 +129,10 @@ const DraftEditorCompositionHandler = {
129129
* Resetting innerHTML will move focus to the beginning of the editor,
130130
* so we update to force it back to the correct place.
131131
*/
132-
resolveComposition: function(editor: DraftEditor): void {
132+
resolveComposition: function(
133+
editor: DraftEditor,
134+
event: SyntheticEvent<>,
135+
): void {
133136
if (stillComposing) {
134137
return;
135138
}
@@ -165,7 +168,11 @@ const DraftEditorCompositionHandler = {
165168
gkx('draft_handlebeforeinput_composed_text') &&
166169
editor.props.handleBeforeInput &&
167170
isEventHandled(
168-
editor.props.handleBeforeInput(composedChars, editorState),
171+
editor.props.handleBeforeInput(
172+
composedChars,
173+
editorState,
174+
event.timeStamp,
175+
),
169176
)
170177
) {
171178
return;

src/component/handlers/edit/editOnBeforeInput.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ function editOnBeforeInput(
100100
// start of the block.
101101
if (
102102
editor.props.handleBeforeInput &&
103-
isEventHandled(editor.props.handleBeforeInput(chars, editorState))
103+
isEventHandled(
104+
editor.props.handleBeforeInput(chars, editorState, e.timeStamp),
105+
)
104106
) {
105107
e.preventDefault();
106108
return;

0 commit comments

Comments
 (0)