mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 04:04:06 +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:
@@ -396,25 +396,32 @@ 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)) {
|
||||
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 = {
|
||||
text: '',
|
||||
start: start.offset,
|
||||
|
Reference in New Issue
Block a user