1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-27 17:09:53 +02:00

Fix triple selection extending to next block (#1605)

* Fix triple selection extending to next block

* Remove unused startOffset

* Add Iscollapsed check to prevent failing setBlock on initial block position

* Fix across-blocks.js test

* Test new hanging selection behaviour

* Lint

* Revert e902fa1acb

* Lint

* Use ternary operator instead of if/else
This commit is contained in:
Francesco Agnoletto
2018-02-09 02:10:46 +01:00
committed by Ian Storm Taylor
parent 0c7703e206
commit 5cec47541d
3 changed files with 55 additions and 3 deletions

View File

@@ -948,7 +948,26 @@ Changes.setBlockAtRange = (change, range, properties, options = {}) => {
const { document } = value
const blocks = document.getBlocksAtRange(range)
blocks.forEach(block => {
const { startKey, startOffset, endKey, endOffset, isCollapsed } = range
const isStartVoid = document.hasVoidParent(startKey)
const startBlock = document.getClosestBlock(startKey)
const endBlock = document.getClosestBlock(endKey)
// Check if we have a "hanging" selection case where the even though the
// selection extends into the start of the end node, we actually want to
// ignore that for UX reasons.
const isHanging =
isCollapsed == false &&
startOffset == 0 &&
endOffset == 0 &&
isStartVoid == false &&
startKey == startBlock.getFirstText().key &&
endKey == endBlock.getFirstText().key
// If it's a hanging selection, ignore the last block.
const sets = isHanging ? blocks.slice(0, -1) : blocks
sets.forEach(block => {
change.setNodeByKey(block.key, properties, { normalize })
})
}

View File

@@ -13,7 +13,7 @@ export const input = (
<anchor />word
</paragraph>
<paragraph>
<focus />another
a<focus />nother
</paragraph>
</document>
</value>
@@ -26,7 +26,7 @@ export const output = (
<anchor />word
</code>
<code>
<focus />another
a<focus />nother
</code>
</document>
</value>

View File

@@ -0,0 +1,33 @@
/** @jsx h */
import h from '../../../helpers/h'
export default function(change) {
change.setBlock({ type: 'code' })
}
export const input = (
<value>
<document>
<paragraph>
<anchor />word
</paragraph>
<paragraph>
<focus />another
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<code>
<anchor />word
</code>
<paragraph>
<focus />another
</paragraph>
</document>
</value>
)