Bug: When deleting text with the keyboard of a device it's also removing text to the right of the pointer.
In the editor when doing a long press of the delete key in an android device it removes the text to the right of the text pointer.
Lexical version: v0.9.2
Steps To Reproduce
Tested device: Samgung Galaxy S22 Ultra with default keyboard
- Go to the lexical playground https://playground.lexical.dev in the browser of an android device
- Delete the predefined content and write a random paragraph
- Select in the text any point where there is still text to the right
- keep pressing the delete key in the keyboard
The current behavior
It deletes text to the left and right of the pointer
https://user-images.githubusercontent.com/59893365/232548029-4b6f358a-7955-475d-a83b-15948bb577cc.mp4
The expected behavior
It should only delete text to the left of the pointer.
https://user-images.githubusercontent.com/59893365/232548647-52290174-df6f-411a-93ef-a035e819d340.mp4
we are using lexical in production and we have the same problem 🥲 . For now we decided to use html textarea instead of lexical editor. We love lexical and I hope this problem will be solved soon so that we can return to lexical sooner
We're seeing the same issue too, no long-press on the backspace key needed. I can replicate in the Android Studio emulator, there it seems limited to on-screen backspace presses, pressing backspace on the computer's keyboard doesn't show the same buggy behaviour.
There's a somewhat related bug with backspace not actually deleting anything but causing a cursor jump to a previous cursor position although I don't have an exact replication for that so far.
@trueadm I did a little research on this issue and found the reason why it happens.
In this PR that line now returns false, I don't really understand why it could have changed but that causes it to not enter that if and go to else.
I was testing a bit and giving a value to the _compositionKey property fixes it.
if ($isRangeSelection(selection)) {
// Used for handling backspace in Android.
const isAndroidDevice = !!navigator.userAgent.match(/Android/i);
if (isAndroidDevice) {
$setCompositionKey(selection.anchor.key);
}
if (
isPossiblyAndroidKeyPress(event.timeStamp) &&
editor.isComposing() &&
selection.anchor.key === selection.focus.key
) {
$setCompositionKey(null);
lastKeyDownTimeStamp = 0;
// Fixes an Android bug where selection flickers when backspacing
setTimeout(() => {
updateEditor(editor, () => {
$setCompositionKey(null);
});
}, ANDROID_COMPOSITION_LATENCY);
if ($isRangeSelection(selection)) {
const anchorNode = selection.anchor.getNode();
anchorNode.markDirty();
selection.format = anchorNode.getFormat();
selection.style = anchorNode.getStyle();
}
} else {
event.preventDefault();
dispatchCommand(editor, DELETE_CHARACTER_COMMAND, true);
}
return;
}
I don't know if it's the best solution, but I hope it can be a guide.
Evidence: https://www.loom.com/share/24898783cffd4023bf85460966702898
Re-opening as #7122 is getting reverted
Same problem here on reddit