WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.3k stars 4.1k forks source link

RichText: empty anchor is removed (also in classic editor) #13331

Open greatislander opened 5 years ago

greatislander commented 5 years ago

Describe the bug When editing a paragraph containing an anchor (e.g. ) in Firefox (64.0.2, macOS 10.14.2), pressing the delete key to delete any text in the paragraph removes the anchor, regardless of the position of the cursor in relation to the anchor within the paragraph. This affects both classic blocks and paragraph blocks.

To Reproduce Steps to reproduce the behavior:

  1. In HTML mode, add an anchor to a paragraph in a classic block or paragraph block.
  2. Switch to visual mode.
  3. Position the cursor anywhere within the paragraph, and press the delete key to delete text.
  4. Observe that the anchor disappears.

Expected behavior The anchor should be unaffected unless the cursor directly follows the anchor icon when the delete key is pressed.

Screenshots https://cl.ly/24307cf3c26c

Desktop (please complete the following information):

Additional context

ellatrix commented 5 years ago

This works for me if the anchor has content. What's a good use case of adding on empty anchor?

noisysocks commented 4 years ago

Confirmed that this happens in latest development version of Gutenberg, so removing Needs Testing.

I'm not 100% sure that it's a bug, though, as it's generally not expected that one can insert arbitrary HTML (including an empty <a> tag) into any block. The only use-case for an empty anchor that I can think of is inserting a page jump e.g. <a name="you-can-link-to-here"></a>. Using an HTML block is workaround for this.