Skip to content

Commit

Permalink
Code review-based cleanup and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed Nov 17, 2017
1 parent 174375c commit 39a9589
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
5 changes: 1 addition & 4 deletions packages/react-dom/src/client/ReactInputSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ export function restoreSelection(priorSelectionInformation) {
}
});

if (
curActiveElement !== priorActiveElement &&
isInDocument(priorActiveElement)
) {
if (curActiveElement !== priorActiveElement) {
focusNodePreservingScroll(priorActiveElement);
}
}
Expand Down
26 changes: 16 additions & 10 deletions packages/react-dom/src/events/SelectEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ function getSelection(node) {
}
}

/**
* Get document associated with the event target.
*
* @param {object} nativeEventTarget
* @return {Document}
*/
function getEventTargetDocument(eventTarget) {
return eventTarget.window === eventTarget
? eventTarget.document
: eventTarget.nodeType === DOCUMENT_NODE
? eventTarget
: eventTarget.ownerDocument;
}

/**
* Poll selection to see whether it's changed.
*
Expand All @@ -93,10 +107,7 @@ function constructSelectEvent(nativeEvent, nativeEventTarget) {
// selection (this matches native `select` event behavior). In HTML5, select
// fires only on input and textarea thus if there's no focused element we
// won't dispatch.
var doc =
nativeEventTarget.ownerDocument ||
nativeEventTarget.document ||
nativeEventTarget;
var doc = getEventTargetDocument(nativeEventTarget);

if (
mouseDown ||
Expand Down Expand Up @@ -152,12 +163,7 @@ var SelectEventPlugin = {
nativeEvent,
nativeEventTarget,
) {
var doc =
nativeEventTarget.window === nativeEventTarget
? nativeEventTarget.document
: nativeEventTarget.nodeType === DOCUMENT_NODE
? nativeEventTarget
: nativeEventTarget.ownerDocument;
var doc = getEventTargetDocument(nativeEventTarget);
// Track whether all listeners exists for this plugin. If none exist, we do
// not extract events. See #3639.
if (!doc || !isListeningToAllDependencies('onSelect', doc)) {
Expand Down
8 changes: 3 additions & 5 deletions packages/react-dom/src/events/SyntheticClipboardEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import SyntheticEvent from 'events/SyntheticEvent';
*/
var ClipboardEventInterface = {
clipboardData: function(event) {
if ('clipboardData' in event) {
return event.clipboardData;
}
var doc = (event.target && event.target.ownerDocument) || document;
return doc.defaultView.clipboardData;
return 'clipboardData' in event
? event.clipboardData
: window.clipboardData;
},
};

Expand Down

0 comments on commit 39a9589

Please sign in to comment.