Skip to content

Commit

Permalink
Remove webkit check on 'clearRanges' hack
Browse files Browse the repository at this point in the history
Summary:
The issue where a range is not cleared was showing up across all browsers, so
we removed the 'webkit' check and clarified the comment.

Related to facebookarchive#1190

Reviewed By: spicyj

Differential Revision: D5580833

fbshipit-source-id: 3949d036654597c77adb6247310f3c6b8d364702
  • Loading branch information
flarnie authored and facebook-github-bot committed Aug 9, 2017
1 parent 036e3a8 commit 9a55eef
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/component/handlers/edit/editOnBlur.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ import type DraftEditor from 'DraftEditor.react';

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

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

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

function editOnBlur(editor: DraftEditor, e: SyntheticEvent): void {
// Webkit has a bug in which blurring a contenteditable by clicking on
// other active elements will trigger the `blur` event but will not remove
// the DOM selection from the contenteditable. We therefore force the
// issue to be certain, checking whether the active element is `body`
// to force it when blurring occurs within the window (as opposed to
// clicking to another tab or window).
if (isWebKit && getActiveElement() === document.body) {
// In a contentEditable element, when you select a range and then click
// another active element, this does trigger a `blur` event but will not
// remove the DOM selection from the contenteditable.
// This is consistent across all browsers, but we prefer that the editor
// behave like a textarea, where a `blur` event clears the DOM selection.
// We therefore force the issue to be certain, checking whether the active
// element is `body` to force it when blurring occurs within the window (as
// opposed to clicking to another tab or window).
if (getActiveElement() === document.body) {
const selection = global.getSelection();
const editorNode = editor.refs.editor;
if (
Expand Down

0 comments on commit 9a55eef

Please sign in to comment.