-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Selecting a single character then typing it doesn't replace it #398
Comments
Weird bug, thanks for reporting. |
If I understand this correctly, I reproduced it. Select the character and have to key it twice before it replaces it and not happening if the character is different. Seems to me this is maybe something in how the editor detects changes in state. I watched the draft.js talk about how it handles intermediary states between transforms while you are typing and it said that it throws them out. If this is the case, maybe it doesn't realize that the state has actually changed when you key it in the first time. What seems to support that, is if you select 2 of the same character, like |
Nice catch! I've never noticed this before. I believe @steviesama is correct here, and the editor doesn't think the state has changed within the This seems fixable by checking whether the typed character matches the selected character, then simply updating the |
**what is the change?:** When rebasing we accidentally removed a variable and this commit adds it back. There was also ~5 lint errors introduced by this PR and this commit fixes those. **why make this change?:** To get CI passing and make this PR mergable. **test plan:** `yarn lint && yarn test && flow src` And did some manual testing. **issue:** Related to PR fixing facebookarchive#398
Summary: Fixes #1830 (bug introduced in #719; this is a proper fix for #398). * When we're allowing native insertion, we don't want to modify the selection because doing so blocks browser features like spellcheck from working * In all other cases when typing, we *do* want to force the selection – failing to do this is why the original issue occurred * We use the `insert-characters` change type for both native and non-native insertions * Instead of guessing in `EditorState.push` whether to force a selection, accept it as a parameter * Gate all changes by `draft_non_native_insertion_forces_selection` I verified with the feature flag disabled (same behavior as before): * Typing over a character works, and the cursor moves as expected (because of the `chars === currentlySelectedChars` check) * With editor contents "ABC\ndef", replacing "d", "e", or "f" with the character above *fails* to replace the char (because that check is buggy). And with the feature flag enabled (new behavior): * Typing over a character still works (but does so without the buggy check) * With editor contents "ABC\ndef", replacing "d", "e", or "f" with the character above *succeeds* at replacing the char. Reviewed By: flarnie Differential Revision: D9209691 fbshipit-source-id: f63551dbad689391aa9c2a69f1d6ba395b8bf1ac
I can replicate it on the DraftJS demo page by typing a single character (such as "t"), selecting it, then trying to type "t" again. "t" should get replaced, with the selection collapsing after the "t". Instead, this does not happen until I type "t" again. This does not happen if the character is different.
The
editorState
passed intoonChange
seems to think its selection'sanchorOffset
andfocusOffset
are the same after entering the character, which would be the correct behavior, but this isn't reflected in the selection itself.The text was updated successfully, but these errors were encountered: