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';
14
14
* @return {?object }
15
15
*/
16
16
export 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 ;
21
19
const selection = win . getSelection && win . getSelection ( ) ;
22
20
23
21
if ( ! selection || selection . rangeCount === 0 ) {
@@ -155,12 +153,12 @@ export function getModernOffsetsFromPoints(
155
153
*/
156
154
export function setOffsets ( node , offsets ) {
157
155
const doc = node . ownerDocument || document ;
158
-
159
- if ( ! doc . defaultView . getSelection ) {
156
+ const win = doc ? doc . defaultView : window ;
157
+ if ( ! win . getSelection ) {
160
158
return ;
161
159
}
162
160
163
- const selection = doc . defaultView . getSelection ( ) ;
161
+ const selection = win . getSelection ( ) ;
164
162
const length = node [ getTextContentAccessor ( ) ] . length ;
165
163
let start = Math . min ( offsets . start , length ) ;
166
164
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) {
65
65
end : node . selectionEnd ,
66
66
} ;
67
67
} 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 ;
72
70
if ( win . getSelection ) {
73
71
const selection = win . getSelection ( ) ;
74
72
return {
You can’t perform that action at this time.
0 commit comments