Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use correct document and window/global objects
  • Loading branch information
haikyuu committed Sep 20, 2018
commit cdaa02e1d27f49666236360824eda2e04d8776fe
19 changes: 3 additions & 16 deletions src/component/base/DraftEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,7 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
* ie9-beta-minor-change-list.aspx
*/
if (isIE) {
document.execCommand('AutoUrlDetect', false, false);
}
const {iframeWindow, iframeDocument} = this.props;
if (iframeWindow) {
document._iframeWindow = iframeWindow;
}
if (iframeDocument) {
document._iframeDocument = iframeDocument;
this.editor.ownerDocument.execCommand('AutoUrlDetect', false, false);
}
}

Expand Down Expand Up @@ -486,10 +479,7 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
const scrollParent = Style.getScrollParent(editorNode);
const {x, y} = scrollPosition || getScrollPosition(scrollParent);

invariant(
isHTMLElement(editorNode),
'editorNode is not an HTMLElement',
);
invariant(isHTMLElement(editorNode), 'editorNode is not an HTMLElement');

editorNode.focus();

Expand All @@ -513,10 +503,7 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {

blur = (): void => {
const editorNode = ReactDOM.findDOMNode(this.editor);
invariant(
isHTMLElement(editorNode),
'editorNode is not an HTMLElement',
);
invariant(isHTMLElement(editorNode), 'editorNode is not an HTMLElement');
editorNode.blur();
};

Expand Down
6 changes: 4 additions & 2 deletions src/component/handlers/drag/DraftEditorDragHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ function getSelectionForEvent(
/* $FlowFixMe(>=0.68.0 site=www,mobile) This comment suppresses an error
* found when Flow v0.68 was deployed. To see the error delete this comment
* and run Flow. */
if (typeof document.caretRangeFromPoint === 'function') {
const dropRange = document.caretRangeFromPoint(event.x, event.y);
const {ownerDocument} = event.target;

if (typeof ownerDocument.caretRangeFromPoint === 'function') {
const dropRange = ownerDocument.caretRangeFromPoint(event.x, event.y);
node = dropRange.startContainer;
offset = dropRange.startOffset;
} else if (event.rangeParent) {
Expand Down
7 changes: 4 additions & 3 deletions src/component/selection/expandRangeToStartOfLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
const UnicodeUtils = require('UnicodeUtils');

const getRangeClientRects = require('getRangeClientRects');
const getCorrectDocumentFromNode = require('getCorrectDocumentFromNode');
const invariant = require('invariant');

/**
* Return the computed line height, in pixels, for the provided element.
*/
function getLineHeightPx(element: Element): number {
const computed = getComputedStyle(element);
const div = document.createElement('div');
const correctDocument = getCorrectDocumentFromNode(element);
const div = correctDocument.createElement('div');
div.style.fontFamily = computed.fontFamily;
div.style.fontSize = computed.fontSize;
div.style.fontStyle = computed.fontStyle;
Expand All @@ -30,7 +31,7 @@ function getLineHeightPx(element: Element): number {
div.style.position = 'absolute';
div.textContent = 'M';

const documentBody = document.body;
const documentBody = correctDocument.body;
invariant(documentBody, 'Missing document.body');

// forced layout here
Expand Down
7 changes: 5 additions & 2 deletions src/component/selection/findAncestorOffsetKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
'use strict';

const getSelectionOffsetKeyForNode = require('getSelectionOffsetKeyForNode');

const getCorrectDocumentFromNode = require('getCorrectDocumentFromNode');
/**
* Get the key from the node's nearest offset-aware ancestor.
*/
function findAncestorOffsetKey(node: Node): ?string {
let searchNode = node;
while (searchNode && searchNode !== document.documentElement) {
while (
searchNode &&
searchNode !== getCorrectDocumentFromNode(node).documentElement
) {
const key = getSelectionOffsetKeyForNode(searchNode);
if (key != null) {
return key;
Expand Down