mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 12:14:14 +02:00
Fix several errors in the deprecated getEventRange
(#2847)
This version of the method has drifted from `editor.findEventRange`, and now crashes when it's being used. This commit fixes an import and changes some code to match the new code in `editor.findEventRange`.
This commit is contained in:
committed by
Ian Storm Taylor
parent
5f26890ff9
commit
af8a0baafe
@@ -3,7 +3,7 @@ import invariant from 'tiny-invariant'
|
|||||||
import warning from 'tiny-warning'
|
import warning from 'tiny-warning'
|
||||||
import { Value } from 'slate'
|
import { Value } from 'slate'
|
||||||
|
|
||||||
import findPath from './find-node'
|
import findPath from './find-path'
|
||||||
import findRange from './find-range'
|
import findRange from './find-range'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,13 +50,11 @@ function getEventRange(event, editor) {
|
|||||||
: y - rect.top < rect.top + rect.height - y
|
: y - rect.top < rect.top + rect.height - y
|
||||||
|
|
||||||
const range = document.createRange()
|
const range = document.createRange()
|
||||||
const iterable = isPrevious ? 'previousTexts' : 'nextTexts'
|
|
||||||
const move = isPrevious ? 'moveToEndOfNode' : 'moveToStartOfNode'
|
const move = isPrevious ? 'moveToEndOfNode' : 'moveToStartOfNode'
|
||||||
const entry = document[iterable](path)
|
const entry = document[isPrevious ? 'getPreviousText' : 'getNextText'](path)
|
||||||
|
|
||||||
if (entry) {
|
if (entry) {
|
||||||
const [n] = entry
|
return range[move](entry)
|
||||||
return range[move](n)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
Reference in New Issue
Block a user