mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 20:24:01 +02:00
Fix android linebreak deletion bug (#5908)
* removed unnecessary edge case deletion logic on android * woops looks like that edge case was necessary after all. readding it with extra logic to handle forward deletion * changeset and lint
This commit is contained in:
5
.changeset/sour-lions-juggle.md
Normal file
5
.changeset/sour-lions-juggle.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate-react': patch
|
||||
---
|
||||
|
||||
Fixed issue on android where deleting forward at the end of a block would delete the first character in the next block instead of the linebreak
|
@@ -396,24 +396,31 @@ export function createAndroidInputManager({
|
||||
let canStoreDiff = true
|
||||
|
||||
if (type.startsWith('delete')) {
|
||||
if (Range.isExpanded(targetRange)) {
|
||||
const [start, end] = Range.edges(targetRange)
|
||||
const leaf = Node.leaf(editor, start.path)
|
||||
const direction = type.endsWith('Backward') ? 'backward' : 'forward'
|
||||
let [start, end] = Range.edges(targetRange)
|
||||
let [leaf, path] = Editor.leaf(editor, start.path)
|
||||
|
||||
if (Range.isExpanded(targetRange)) {
|
||||
if (leaf.text.length === start.offset && end.offset === 0) {
|
||||
const next = Editor.next(editor, {
|
||||
at: start.path,
|
||||
match: Text.isText,
|
||||
})
|
||||
if (next && Path.equals(next[1], end.path)) {
|
||||
// when deleting a linebreak, targetRange will span across the break (ie start in the node before and end in the node after)
|
||||
// if the node before is empty, this will look like a hanging range and get unhung later--which will take the break we want to remove out of the range
|
||||
// so to avoid this we collapse the target range to default to single character deletion
|
||||
if (direction === 'backward') {
|
||||
targetRange = { anchor: end, focus: end }
|
||||
start = end
|
||||
;[leaf, path] = next
|
||||
} else {
|
||||
targetRange = { anchor: start, focus: start }
|
||||
end = start
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const direction = type.endsWith('Backward') ? 'backward' : 'forward'
|
||||
const [start, end] = Range.edges(targetRange)
|
||||
const [leaf, path] = Editor.leaf(editor, start.path)
|
||||
|
||||
const diff = {
|
||||
text: '',
|
||||
|
Reference in New Issue
Block a user