Skip to content

Commit

Permalink
fix(selection): range could be null
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Jun 17, 2018
1 parent c5d6225 commit 3cc2ec2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/selection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ combineLatest(
(instant === 'ctrl' && (e.ctrlKey || e.metaKey))
) {
// harmless side effects
selectCusorWord(e)
selectCursorWord(e)
return e
}
return undefined
Expand Down Expand Up @@ -356,7 +356,7 @@ function isTypeField (traget: EventTarget | null): boolean {
/**
* Select the word under the cursor position
*/
function selectCusorWord (e: MouseEvent): void {
function selectCursorWord (e: MouseEvent): void {
const x = e.clientX
const y = e.clientY

Expand All @@ -368,10 +368,12 @@ function selectCusorWord (e: MouseEvent): void {

if (document['caretPositionFromPoint']) {
const pos = document['caretPositionFromPoint'](x, y)
if (!pos) { return }
offsetNode = pos.offsetNode
offset = pos.offset
} else if (document['caretRangeFromPoint']) {
const pos = document['caretRangeFromPoint'](x, y)
if (!pos) { return }
offsetNode = pos.startContainer
offset = pos.startOffset
} else {
Expand Down

0 comments on commit 3cc2ec2

Please sign in to comment.