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

Commit aed35d2

Browse files
Jainil Parekhfacebook-github-bot
authored andcommitted
Fix for workchat composer cursor jumping
Summary: As figured out in T47552048, the issue of cursor jumping is happening because the draft editor's selection state is not in the correct state. After digging in, I discovered that the draft editor manages this state through the contenteditable div's onSelect event, but it is not being fired in certain cases. So I am changing the code to update the selection state when mouseUp and keyUp events are fired, and this fixes the issue as these events are fired even in those cases where onSelect is not. Although this means that there are some redundant updates to the selection state, this shouldn't cause any bugs. I suspect this is happening because of some change/bug on how chrome is firing events on contenteditable, since it doesn't repro on firefox and also I couldn't find any code changes that match the bug timeline. Reviewed By: claudiopro Differential Revision: D17054885 fbshipit-source-id: 06b1e96629828d4cb1c9cab36c2711c6464f1f3c
1 parent 594a14f commit aed35d2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/component/handlers/edit/DraftEditorEditHandler.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
'use strict';
1313

14+
import type DraftEditor from 'DraftEditor.react';
15+
16+
const UserAgent = require('UserAgent');
17+
1418
const onBeforeInput = require('editOnBeforeInput');
1519
const onBlur = require('editOnBlur');
1620
const onCompositionStart = require('editOnCompositionStart');
@@ -24,6 +28,12 @@ const onKeyDown = require('editOnKeyDown');
2428
const onPaste = require('editOnPaste');
2529
const onSelect = require('editOnSelect');
2630

31+
const isChrome = UserAgent.isBrowser('Chrome');
32+
33+
const selectionHandler: (e: DraftEditor) => void = isChrome
34+
? onSelect
35+
: e => {};
36+
2737
const DraftEditorEditHandler = {
2838
onBeforeInput,
2939
onBlur,
@@ -37,6 +47,12 @@ const DraftEditorEditHandler = {
3747
onKeyDown,
3848
onPaste,
3949
onSelect,
50+
// In certain cases, contenteditable on chrome does not fire the onSelect
51+
// event, causing problems with cursor positioning. Therefore, the selection
52+
// state update handler is added to more events to ensure that the selection
53+
// state is always synced with the actual cursor positions.
54+
onMouseUp: selectionHandler,
55+
onKeyUp: selectionHandler,
4056
};
4157

4258
module.exports = DraftEditorEditHandler;

0 commit comments

Comments
 (0)