lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: When deleting text with the keyboard of a device it's also removing text to the right of the pointer.

Open dist159 opened this issue 3 years ago • 5 comments

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

  1. Go to the lexical playground https://playground.lexical.dev in the browser of an android device
  2. Delete the predefined content and write a random paragraph
  3. Select in the text any point where there is still text to the right
  4. 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

dist159 avatar Apr 17 '23 16:04 dist159

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

Reza-tm avatar Jul 07 '23 16:07 Reza-tm

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.

kevinansfield avatar Aug 10 '23 13:08 kevinansfield

@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

cristopher-iov avatar Sep 15 '23 19:09 cristopher-iov

Re-opening as #7122 is getting reverted

etrepum avatar Feb 20 '25 14:02 etrepum

Same problem here on reddit

m4xolotl avatar Feb 28 '25 16:02 m4xolotl