Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#28305 closed defect (bug) (worksforme)

Visual Editor Anchor Button Behavior

Reported by: josh401 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9
Component: TinyMCE Keywords: close
Focuses: Cc:
PR Number:



The "anchor" button in the TinyMCE editor is acting a bit strange.

From Andrew Ozz's explanation here (http://wordpress.org/support/topic/anchors-using-button-dont-stay-when-updated?replies=5#post-5594599).

The anchor button is removing any highlighted text just prior to inserting the anchor.

Here are the steps to replicate:

  1. Create some text in visual view; This is a test link.
  2. Highlight the word test and click the anchor button.
  3. Add myTest as the anchor name.
  4. Switch to 'text' view.

You will see the editor has removed the word test and replaced it with <a id="myTest"></a>.

The original word test (or whatever you highlight just prior to clicking the anchor button) gets removed completely.

I think we just need to add back in the 'editor selection' when the link is created; and push it back to the WordPress editor.

Change History (6)

#1 @azaozz
5 years ago

This is the "standard" behavior in all editors. When something is selected and you start typing or insert another element (like image), the selection is replaced.

For anchors it would probably be better to collapse the selection to the front, I'll make a small patch and see if the TinyMCE Devs would change it.

#2 @josh401
5 years ago

Ah, I understand. But, what if you wanted to link textual elements using anchors; such as when creating a TOC at the top of a long page.

I can see this reasoning though. You could place an anchor directly directly before the heading (or whatever you use to separate the page elements).

It's just been my experience to use textual elements when using anchors (rarely ever use them). And it seems the way it is designed now; when creating an anchor, it should ONLY be used without wrapping any content first?

I'll add a voice to the TinyMCE thread if think it will help :)

Thanks Andrew.

Last edited 5 years ago by josh401 (previous) (diff)

#3 @azaozz
5 years ago

You could place an anchor directly before the heading (or whatever you use to separate the page elements).

Right. It doesn't make any difference if any text is wrapped in the link or not. The browsers don't render it as a link as there's no href attribute. The "original" HTML anchors were always empty, they only mark the spot the page is scrolled to. Then from HTML 4 any element with an ID can be used as anchor.

#4 @iseulde
5 years ago

I think this is normal behaviour. If you insert something when text is selected, the text will disappear.

#5 @iseulde
5 years ago

  • Keywords close added
  • Version changed from 3.9.1 to 3.9

#6 @azaozz
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Collapsing the selection could be an idea for enhancement for the TinyMCE "anchor" plugin. Replacing the selection is the standard behavior though, not sure if changing it would be better.

Note: See TracTickets for help on using tickets.