mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 10:29:48 +02:00
fix pointForward and pointBackward (#2053)
* fix next being undefined in pointForward. Adds a check that next exists * fix both pointForward and pointBackward * fix for lint tests
This commit is contained in:
committed by
Ian Storm Taylor
parent
d4b52e3eb5
commit
7ff7a89ea7
@@ -662,6 +662,7 @@ function pointBackward(change, point, n = 1) {
|
||||
const p = selection[point]
|
||||
const isInVoid = document.hasVoidParent(p.path)
|
||||
|
||||
// what is this?
|
||||
if (!isInVoid && p.offset - n >= 0) {
|
||||
const range = selection[`move${Point}Backward`](n)
|
||||
change.select(range)
|
||||
@@ -674,8 +675,9 @@ function pointBackward(change, point, n = 1) {
|
||||
const block = document.getClosestBlock(p.path)
|
||||
const isInBlock = block.hasNode(previous.key)
|
||||
const isPreviousInVoid = previous && document.hasVoidParent(previous.key)
|
||||
change.moveToEndOfNode(previous)
|
||||
change[`move${Point}ToEndOfNode`](previous)
|
||||
|
||||
// when is this called?
|
||||
if (!isInVoid && !isPreviousInVoid && isInBlock) {
|
||||
const range = change.value.selection[`move${Point}Backward`](n)
|
||||
change.select(range)
|
||||
@@ -693,20 +695,22 @@ function pointForward(change, point, n = 1) {
|
||||
const text = document.getNode(p.path)
|
||||
const isInVoid = document.hasVoidParent(p.path)
|
||||
|
||||
// what is this?
|
||||
if (!isInVoid && p.offset + n <= text.text.length) {
|
||||
const range = selection[`move${Point}Forward`](n)
|
||||
change.select(range)
|
||||
return
|
||||
}
|
||||
|
||||
const block = document.getClosestBlock(p.path)
|
||||
const isInBlock = block.hasNode(next.key)
|
||||
const next = document.getNextText(p.path)
|
||||
const isNextInVoid = next && document.hasVoidParent(next.key)
|
||||
if (!next) return
|
||||
|
||||
change.moveAnchorToStartOf(next)
|
||||
const block = document.getClosestBlock(p.path)
|
||||
const isInBlock = block.hasNode(next.key)
|
||||
const isNextInVoid = document.hasVoidParent(next.key)
|
||||
change[`move${Point}ToStartOfNode`](next)
|
||||
|
||||
// when is this called?
|
||||
if (!isInVoid && !isNextInVoid && isInBlock) {
|
||||
const range = change.value.selection[`move${Point}Forward`](n)
|
||||
change.select(range)
|
||||
|
22
yarn.lock
22
yarn.lock
@@ -3903,8 +3903,8 @@ get-value@^2.0.3, get-value@^2.0.6:
|
||||
resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28"
|
||||
|
||||
get-window@^1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/get-window/-/get-window-1.1.1.tgz#0750f8970c88a54ac1294deb97add9568b3db594"
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/get-window/-/get-window-1.1.2.tgz#65fbaa999fb87f86ea5d30770f4097707044f47f"
|
||||
dependencies:
|
||||
get-document "1"
|
||||
|
||||
@@ -5118,8 +5118,8 @@ jsx-ast-utils@^2.0.1:
|
||||
array-includes "^3.0.3"
|
||||
|
||||
keycode@^2.1.2:
|
||||
version "2.1.9"
|
||||
resolved "https://registry.yarnpkg.com/keycode/-/keycode-2.1.9.tgz#964a23c54e4889405b4861a5c9f0480d45141dfa"
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/keycode/-/keycode-2.2.0.tgz#3d0af56dc7b8b8e5cba8d0a97f107204eec22b04"
|
||||
|
||||
killable@^1.0.0:
|
||||
version "1.0.0"
|
||||
@@ -5391,18 +5391,18 @@ lodash.uniq@^4.5.0:
|
||||
version "4.5.0"
|
||||
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
|
||||
|
||||
lodash@^4.0.0, lodash@^4.1.0, lodash@^4.1.1, lodash@^4.13.1, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1:
|
||||
lodash@^4.0.0, lodash@^4.1.0, lodash@^4.13.1, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1:
|
||||
version "4.17.4"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
|
||||
|
||||
lodash@^4.1.1, lodash@^4.17.5, lodash@^4.3.0:
|
||||
version "4.17.10"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
|
||||
|
||||
lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.6.1:
|
||||
version "4.17.5"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"
|
||||
|
||||
lodash@^4.17.5, lodash@^4.3.0:
|
||||
version "4.17.10"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
|
||||
|
||||
loglevel@^1.4.1:
|
||||
version "1.6.1"
|
||||
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.1.tgz#e0fc95133b6ef276cdc8887cdaf24aa6f156f8fa"
|
||||
@@ -7032,8 +7032,8 @@ react-immutable-proptypes@^2.1.0:
|
||||
resolved "https://registry.yarnpkg.com/react-immutable-proptypes/-/react-immutable-proptypes-2.1.0.tgz#023d6f39bb15c97c071e9e60d00d136eac5fa0b4"
|
||||
|
||||
react-portal@^3.1.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/react-portal/-/react-portal-3.1.0.tgz#865c44fb72a1da106c649206936559ce891ee899"
|
||||
version "3.2.0"
|
||||
resolved "https://registry.yarnpkg.com/react-portal/-/react-portal-3.2.0.tgz#4224e19b2b05d5cbe730a7ba0e34ec7585de0043"
|
||||
dependencies:
|
||||
prop-types "^15.5.8"
|
||||
|
||||
|
Reference in New Issue
Block a user