File tree Expand file tree Collapse file tree 2 files changed +7
-11
lines changed
Expand file tree Collapse file tree 2 files changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -14,10 +14,8 @@ import {TEXT_NODE} from '../shared/HTMLNodeType';
1414 * @return {?object }
1515 */
1616export function getOffsets ( outerNode ) {
17- let win = window ;
18- if ( outerNode . ownerDocument && outerNode . ownerDocument . defaultView ) {
19- win = outerNode . ownerDocument . defaultView ;
20- }
17+ const win =
18+ ( outerNode . ownerDocument && outerNode . ownerDocument . defaultView ) || window ;
2119 const selection = win . getSelection && win . getSelection ( ) ;
2220
2321 if ( ! selection || selection . rangeCount === 0 ) {
@@ -155,12 +153,12 @@ export function getModernOffsetsFromPoints(
155153 */
156154export function setOffsets ( node , offsets ) {
157155 const doc = node . ownerDocument || document ;
158-
159- if ( ! doc . defaultView . getSelection ) {
156+ const win = doc ? doc . defaultView : window ;
157+ if ( ! win . getSelection ) {
160158 return ;
161159 }
162160
163- const selection = doc . defaultView . getSelection ( ) ;
161+ const selection = win . getSelection ( ) ;
164162 const length = node [ getTextContentAccessor ( ) ] . length ;
165163 let start = Math . min ( offsets . start , length ) ;
166164 let end = offsets . end === undefined ? start : Math . min ( offsets . end , length ) ;
Original file line number Diff line number Diff line change @@ -65,10 +65,8 @@ function getSelection(node) {
6565 end : node . selectionEnd ,
6666 } ;
6767 } else {
68- let win = window ;
69- if ( node . ownerDocument && node . ownerDocument . defaultView ) {
70- win = node . ownerDocument . defaultView ;
71- }
68+ const win =
69+ ( node . ownerDocument && node . ownerDocument . defaultView ) || window ;
7270 if ( win . getSelection ) {
7371 const selection = win . getSelection ( ) ;
7472 return {
You can’t perform that action at this time.
0 commit comments