mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-17 20:51:20 +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,25 +396,32 @@ export function createAndroidInputManager({
|
|||||||
let canStoreDiff = true
|
let canStoreDiff = true
|
||||||
|
|
||||||
if (type.startsWith('delete')) {
|
if (type.startsWith('delete')) {
|
||||||
if (Range.isExpanded(targetRange)) {
|
const direction = type.endsWith('Backward') ? 'backward' : 'forward'
|
||||||
const [start, end] = Range.edges(targetRange)
|
let [start, end] = Range.edges(targetRange)
|
||||||
const leaf = Node.leaf(editor, start.path)
|
let [leaf, path] = Editor.leaf(editor, start.path)
|
||||||
|
|
||||||
|
if (Range.isExpanded(targetRange)) {
|
||||||
if (leaf.text.length === start.offset && end.offset === 0) {
|
if (leaf.text.length === start.offset && end.offset === 0) {
|
||||||
const next = Editor.next(editor, {
|
const next = Editor.next(editor, {
|
||||||
at: start.path,
|
at: start.path,
|
||||||
match: Text.isText,
|
match: Text.isText,
|
||||||
})
|
})
|
||||||
if (next && Path.equals(next[1], end.path)) {
|
if (next && Path.equals(next[1], end.path)) {
|
||||||
targetRange = { anchor: end, focus: end }
|
// 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 = {
|
const diff = {
|
||||||
text: '',
|
text: '',
|
||||||
start: start.offset,
|
start: start.offset,
|
||||||
|
Reference in New Issue
Block a user