mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-26 08:34:28 +02: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:
@@ -795,17 +795,32 @@ class Content extends React.Component {
|
|||||||
const focusBlock = document.getClosestBlock(focus.key)
|
const focusBlock = document.getClosestBlock(focus.key)
|
||||||
const anchorBlock = document.getClosestBlock(anchor.key)
|
const anchorBlock = document.getClosestBlock(anchor.key)
|
||||||
|
|
||||||
// When going from a non-void block to the start of a void-block
|
// COMPAT: If the anchor point is at the start of a non-void, and the
|
||||||
// the focus is most of the time collpased to the end of the void block.
|
// focus point is inside a void node with an offset that isn't `0`, set
|
||||||
// This is getting the void-block selected as well when it shouldn't.
|
// the focus offset to `0`. This is due to void nodes <span>'s being
|
||||||
// Make sure it is collapsed to the start in those cases.
|
// positioned off screen, resulting in the offset always being greater
|
||||||
if (anchorBlock && !anchorBlock.isVoid && focusBlock && focusBlock.isVoid && focus.offset == 1) {
|
// 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
|
properties.focusOffset = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the selection is at the end of a non-void inline node, and there is
|
// COMPAT: If the selection is at the end of a non-void inline node, and
|
||||||
// a node after it, put it in the node after instead.
|
// there is a node after it, put it in the node after instead. This
|
||||||
if (anchorInline && !anchorInline.isVoid && anchor.offset == anchorText.text.length) {
|
// 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 block = document.getClosestBlock(anchor.key)
|
||||||
const next = block.getNextText(anchor.key)
|
const next = block.getNextText(anchor.key)
|
||||||
if (next) {
|
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 block = document.getClosestBlock(focus.key)
|
||||||
const next = block.getNextText(focus.key)
|
const next = block.getNextText(focus.key)
|
||||||
if (next) {
|
if (next) {
|
||||||
|
@@ -8,7 +8,6 @@ import TRANSFER_TYPES from '../constants/transfer-types'
|
|||||||
import Base64 from '../serializers/base-64'
|
import Base64 from '../serializers/base-64'
|
||||||
import Leaf from './leaf'
|
import Leaf from './leaf'
|
||||||
import SlateTypes from '../utils/prop-types'
|
import SlateTypes from '../utils/prop-types'
|
||||||
import Text from '../models/text'
|
|
||||||
import Void from './void'
|
import Void from './void'
|
||||||
import getWindow from 'get-window'
|
import getWindow from 'get-window'
|
||||||
import scrollToSelection from '../utils/scroll-to-selection'
|
import scrollToSelection from '../utils/scroll-to-selection'
|
||||||
|
@@ -155,7 +155,7 @@ function Plugin(options = {}) {
|
|||||||
// COMPAT: In Chrome & Safari, it isn't possible to have a selection at
|
// 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
|
// the starting edge of a text node after another inline node. It will
|
||||||
// have been automatically changed. So we can't render natively because
|
// 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)) &&
|
(!(pInline && !pInline.isVoid && startOffset == 0)) &&
|
||||||
(!(nInline && !nInline.isVoid && startOffset == startText.text.length)) &&
|
(!(nInline && !nInline.isVoid && startOffset == startText.text.length)) &&
|
||||||
// COMPAT: When inserting a Space character, Chrome will sometimes
|
// COMPAT: When inserting a Space character, Chrome will sometimes
|
||||||
|
Reference in New Issue
Block a user