1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-02 22:28:46 +01:00

Cleanup onSelect comments (#1086)

* remove extra unnecessary onSelect logic

* re-add with comment

* fix comments and logic more

* Update content.js
This commit is contained in:
Ian Storm Taylor 2017-09-07 16:00:09 -07:00 committed by GitHub
parent 59c538c2aa
commit 1e519fb4e6
3 changed files with 29 additions and 11 deletions

View File

@ -795,17 +795,32 @@ class Content extends React.Component {
const focusBlock = document.getClosestBlock(focus.key)
const anchorBlock = document.getClosestBlock(anchor.key)
// When going from a non-void block to the start of a void-block
// the focus is most of the time collpased to the end of the void block.
// This is getting the void-block selected as well when it shouldn't.
// Make sure it is collapsed to the start in those cases.
if (anchorBlock && !anchorBlock.isVoid && focusBlock && focusBlock.isVoid && focus.offset == 1) {
// COMPAT: If the anchor point is at the start of a non-void, and the
// focus point is inside a void node with an offset that isn't `0`, set
// the focus offset to `0`. This is due to void nodes <span>'s being
// positioned off screen, resulting in the offset always being greater
// than `0`. Since we can't know what it really should be, and since an
// offset of `0` is less destructive because it creates a hanging
// selection, go with `0`. (2017/09/07)
if (
anchorBlock &&
!anchorBlock.isVoid &&
anchor.offset == 0 &&
focusBlock &&
focusBlock.isVoid &&
focus.offset != 0
) {
properties.focusOffset = 0
}
// If the selection is at the end of a non-void inline node, and there is
// a node after it, put it in the node after instead.
if (anchorInline && !anchorInline.isVoid && anchor.offset == anchorText.text.length) {
// COMPAT: If the selection is at the end of a non-void inline node, and
// there is a node after it, put it in the node after instead. This
// standardizes the behavior, since it's indistinguishable to the user.
if (
anchorInline &&
!anchorInline.isVoid &&
anchor.offset == anchorText.text.length
) {
const block = document.getClosestBlock(anchor.key)
const next = block.getNextText(anchor.key)
if (next) {
@ -814,7 +829,11 @@ class Content extends React.Component {
}
}
if (focusInline && !focusInline.isVoid && focus.offset == focusText.text.length) {
if (
focusInline &&
!focusInline.isVoid &&
focus.offset == focusText.text.length
) {
const block = document.getClosestBlock(focus.key)
const next = block.getNextText(focus.key)
if (next) {

View File

@ -8,7 +8,6 @@ import TRANSFER_TYPES from '../constants/transfer-types'
import Base64 from '../serializers/base-64'
import Leaf from './leaf'
import SlateTypes from '../utils/prop-types'
import Text from '../models/text'
import Void from './void'
import getWindow from 'get-window'
import scrollToSelection from '../utils/scroll-to-selection'

View File

@ -155,7 +155,7 @@ function Plugin(options = {}) {
// COMPAT: In Chrome & Safari, it isn't possible to have a selection at
// the starting edge of a text node after another inline node. It will
// have been automatically changed. So we can't render natively because
// the cursor isn't technique in the right spot. (2016/12/01)
// the cursor isn't technically in the right spot. (2016/12/01)
(!(pInline && !pInline.isVoid && startOffset == 0)) &&
(!(nInline && !nInline.isVoid && startOffset == startText.text.length)) &&
// COMPAT: When inserting a Space character, Chrome will sometimes