Page MenuHomePhabricator

On-screen keyboard disappears when cursor encounters non-breaking space in Chrome; cannot delete nbsp in Firefox
Open, Needs TriagePublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Edit a Wikipedia page on mobile, live edit version
  • Find a non breaking space (usually next to specific punctuation, in French at least) is n grey on screenshot
  • Position the cursor few characters after (in the next word i.e.)
  • Try do delete (backspace)

What happens?:
When the cursor arrive at the non breaking space, the Google keyboard disappears (retracts down), making it impossible to delete or edit.

Also happens when clicking directly next to the non breaking space, but click event confuses keyboard reaction event.

What should have happened instead?:
Keyboard stay visible

Software version (skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):
Android 13, chrome, Google keyboard

Screenshot_20221214-084401.png (344×494 px, 170 KB)

Event Timeline

Hi @Roumpf, thanks for taking the time to report this!
I can reproduce this in "Visual editing" mode on https://fr.m.wikipedia.org/wiki/Bouteille_oignon using Google Chrome 108.0 on Android 10.
I can also reproduce a (different) problem in Firefox 107.2.0 as the non-breaking space just does not get deleted, the cursor seems to ignore it and skip it.

Aklapper renamed this task from Keyboard disappearing when cursor encounter non breaking space. to On-screen keyboard disappears when cursor encounters non-breaking space in Chrome; cannot delete nbsp in Firefox.Dec 14 2022, 9:48 AM
VPuffetMichel subscribed.

@dchan Assigning to you to have a look.

This appears to happen because English Gboard + Android Chrome lets the cursor land inside a contenteditable=false span. It does not happen with certain other Gboard languages (e.g. Cantonese). Below is a minimal test case.

Steps to reproduce:

  1. In Android Chrome with English Gboard active, open data:text/html,<h1 contenteditable>ABC<span contenteditable="false">XY</span>DEF</h1>.
  2. Place the cursor between D and E.
  3. Press Gboard backspace, so the D disappears.

Expected behaviour: The cursor lies at the start of the EF text node. The keyboard remains open

Observed behaviour: The cursor lies at the end of the XY text node, *inside* the contenteditable=false span (!) The keyboard closes.

I've written what may be a viable fixup (it moves the cursor programmatically, and the keyboard doesn't close if you do so quickly enough), and I'm investigating its robustness with other IMEs, platforms and markup.

Yes, here is a viable fixup for the above case:

  1. On an input event of inputType 'deleteContentBackward', save the current cursor position (but only if the selection is collapsed).
  2. If a subsequent keyup event occurs during the same tick, and lands inside a contentEditable=false node, then restore the saved cursor position.
  3. In any case, clear the saved cursor position at the end of the tick (i.e. using setTimeout).

The fixup has to occur in the keyup event: waiting for the more logical selectionchange event means the soft keyboard has already closed and it's too late.

However, once that case is fixed, we run into a second case, explained below.

Steps to reproduce:

  1. In Android Chrome with English Gboard active, open data:text/html,<h1 contenteditable>ABC<span contenteditable="false">XY</span>DEF</h1>.
  2. Place the cursor between D and E.
  3. Press Gboard backspace, so the D disappears.
  4. Press backspace again.

Expected behaviour: The contentEditable=false span is deleted. (Note this happens on desktop Chromium, or Android Chrome with Cantonese Gboard). The virtual keyboard remains open.

Observed behaviour: The contentEditable=false span is selected but not deleted. The virtual keyboard closes.

This seems to happen because English Gboard in some cases handles text backspace via composition events, as if it were deleting IME candidate text — even though in this case, the supposedly changeable "candidate text" is not even contentEditable. You can see that by backspacing text like conng<span contentEditable="false">ratu</span>lattions that contains a ce=false span and also a misspelling. The whole word becomes a candidate and the correctly spelled word is even suggested (and if you pick it, it can silently overwrite the ce=false span).

In this case the event sequence observed is pretty strange:

  1. keydown with keyCode=229 (which indicates IME composition) — the selection has NOT yet changed
  2. beforeInput with inputType='deleteContentBackward' — now the selection HAS changed
  3. keyup with keyCode=229
  4. selectionchange

It looks a lot like the fact the selection ce=false suppresses the input event but not the beforeInput event.
I've written what may be a viable fixup to this, which manually deletes the DOM node in the beforeInput. It appears to work in this case, except the events do something different if the ce=false span is followed by whitespace (or alternatively, certain non-Latin text, e.g. Han characters). I need to investigate to ensure it doesn't break other cases IMEs, platforms and markup.

Change 881705 had a related patch set uploaded (by Divec; author: Divec):

[VisualEditor/VisualEditor@master] WIP: Fix English Gboard backspace over aliens

https://gerrit.wikimedia.org/r/881705

Based on investigations, I believe Change 881705 fixes the likeliest occurrences of this Gboard bug. I don't think it breaks any case that works at the moment, even though it allows the user to experience T330284 (which needs a separate fix).

Change 881705 merged by jenkins-bot:

[VisualEditor/VisualEditor@master] Fix English Gboard backspace over aliens

https://gerrit.wikimedia.org/r/881705

Change 981374 had a related patch set uploaded (by Esanders; author: Esanders):

[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (402570007)

https://gerrit.wikimedia.org/r/981374

Change 981374 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (402570007)

https://gerrit.wikimedia.org/r/981374

Change 983848 had a related patch set uploaded (by Esanders; author: Esanders):

[VisualEditor/VisualEditor@master] Revert "Fix English Gboard backspace over aliens"

https://gerrit.wikimedia.org/r/983848

Change 983848 merged by jenkins-bot:

[VisualEditor/VisualEditor@master] Revert "Fix English Gboard backspace over aliens"

https://gerrit.wikimedia.org/r/983848

Change 983894 had a related patch set uploaded (by Esanders; author: Esanders):

[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (4b3fa495f)

https://gerrit.wikimedia.org/r/983894

Change 983745 had a related patch set uploaded (by DLynch; author: Esanders):

[VisualEditor/VisualEditor@wmf/1.42.0-wmf.9] Revert "Fix English Gboard backspace over aliens"

https://gerrit.wikimedia.org/r/983745

Change 983894 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (4b3fa495f)

https://gerrit.wikimedia.org/r/983894

Change 983745 merged by jenkins-bot:

[VisualEditor/VisualEditor@wmf/1.42.0-wmf.9] Revert "Fix English Gboard backspace over aliens"

https://gerrit.wikimedia.org/r/983745

Change 983937 had a related patch set uploaded (by DLynch; author: DLynch):

[mediawiki/extensions/VisualEditor@master] Update VE core submodule to wmf.9 (6bada65)

https://gerrit.wikimedia.org/r/983937

Change 983911 had a related patch set uploaded (by DLynch; author: Esanders):

[mediawiki/extensions/VisualEditor@wmf/1.42.0-wmf.9] Update VE core submodule to wmf.9 (6bada65)

https://gerrit.wikimedia.org/r/983911

Change 983937 abandoned by DLynch:

[mediawiki/extensions/VisualEditor@master] Update VE core submodule to wmf.9 (6bada65)

Reason:

Replaced by 983911

https://gerrit.wikimedia.org/r/983937

Change 983911 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@wmf/1.42.0-wmf.9] Update VE core submodule to wmf.9 (6bada65)

https://gerrit.wikimedia.org/r/983911

Mentioned in SAL (#wikimedia-operations) [2023-12-18T21:54:05Z] <dancy@deploy2002> Started scap: Backport for [[gerrit:983745|Revert "Fix English Gboard backspace over aliens" (T353578 T325129)]], [[gerrit:983906|Revert "Put zero-width space after inline focusable nodes" (T353578 T330284)]], [[gerrit:983911|Update VE core submodule to wmf.9 (6bada65) (T353578 T330284 T325129)]]

Mentioned in SAL (#wikimedia-operations) [2023-12-18T21:56:07Z] <dancy@deploy2002> dancy and kemayo: Backport for [[gerrit:983745|Revert "Fix English Gboard backspace over aliens" (T353578 T325129)]], [[gerrit:983906|Revert "Put zero-width space after inline focusable nodes" (T353578 T330284)]], [[gerrit:983911|Update VE core submodule to wmf.9 (6bada65) (T353578 T330284 T325129)]] synced to the testservers (https://wikitech.wikimedia.org/wiki/Mwdebug)

Mentioned in SAL (#wikimedia-operations) [2023-12-18T22:07:40Z] <dancy@deploy2002> Finished scap: Backport for [[gerrit:983745|Revert "Fix English Gboard backspace over aliens" (T353578 T325129)]], [[gerrit:983906|Revert "Put zero-width space after inline focusable nodes" (T353578 T330284)]], [[gerrit:983911|Update VE core submodule to wmf.9 (6bada65) (T353578 T330284 T325129)]] (duration: 13m 34s)

Change 984256 had a related patch set uploaded (by Esanders; author: Divec):

[VisualEditor/VisualEditor@master] Fix English Gboard backspace over aliens

https://gerrit.wikimedia.org/r/984256