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

Commit

Permalink
More caution when removing all ranges in blur handler
Browse files Browse the repository at this point in the history
Summary:
Now we only do it if the current selection is still in the wrong element..

Should mitigate #1190.

Reviewed By: flarnie

Differential Revision: D5570526

fbshipit-source-id: 0b5b88542993773d71db0fffeb09c1b5c65c627e
  • Loading branch information
sophiebits authored and facebook-github-bot committed Aug 7, 2017
1 parent 744e9b4 commit 036e3a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/component/handlers/edit/editOnBlur.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

import type DraftEditor from 'DraftEditor.react';

var EditorState = require('EditorState');
var UserAgent = require('UserAgent');
const DraftFeatureFlags = require('DraftFeatureFlags');
const EditorState = require('EditorState');
const UserAgent = require('UserAgent');

var getActiveElement = require('getActiveElement');
const containsNode = require('containsNode');
const getActiveElement = require('getActiveElement');

var isWebKit = UserAgent.isEngine('WebKit');
const isWebKit = UserAgent.isEngine('WebKit');

function editOnBlur(editor: DraftEditor, e: SyntheticEvent): void {
// Webkit has a bug in which blurring a contenteditable by clicking on
Expand All @@ -29,7 +31,16 @@ function editOnBlur(editor: DraftEditor, e: SyntheticEvent): void {
// to force it when blurring occurs within the window (as opposed to
// clicking to another tab or window).
if (isWebKit && getActiveElement() === document.body) {
global.getSelection().removeAllRanges();
const selection = global.getSelection();
const editorNode = editor.refs.editor;
if (
!DraftFeatureFlags.draft_cautious_range_removal_on_blur ||
selection.rangeCount === 1 &&
containsNode(editorNode, selection.anchorNode) &&
containsNode(editorNode, selection.focusNode)
) {
selection.removeAllRanges();
}
}

var editorState = editor._latestEditorState;
Expand Down
1 change: 1 addition & 0 deletions src/component/utils/DraftFeatureFlags-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

var DraftFeatureFlags = {
draft_accept_selection_after_refocus: false,
draft_cautious_range_removal_on_blur: false,
draft_killswitch_allow_nontextnodes: false,
draft_segmented_entities_behavior: false,
};
Expand Down

0 comments on commit 036e3a8

Please sign in to comment.