mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-27 09:04:31 +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:
committed by
Ian Storm Taylor
parent
0c7703e206
commit
5cec47541d
@@ -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 })
|
||||
})
|
||||
}
|
||||
|
@@ -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>
|
||||
|
@@ -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>
|
||||
)
|
Reference in New Issue
Block a user