Closed Bug 1273655 Opened 8 years ago Closed 3 years ago

Link in paragraph gets extended/repeated onto new line when hitting Enter


(Core :: DOM: Editor, defect, P3)






(Reporter: jorgk-bmo, Unassigned)


(Blocks 2 open bugs)


(Whiteboard: [h2review-noted])


(1 file)

Link in paragraph gets extended/repeated onto new line when hitting enter.

Try the attached test case. It says more than 1000 words.

Maybe related to bug 1250805.
It is not just pressing enter,  continuing typing after inserting a link continues the link as well.  I would expect the link to end with the existing text,  but it does not.
Only happens because of the <p>.  Without the <p>, it doesn't follow the newline.  (Sigh.  <br> for newline is a bad choice.)

Chrome and Edge both match the behavior suggested in comment 2.  For bold, clicking at the end of the line and typing will insert bold text.  But for a link, it doesn't.  We should probably change to match this behavior.
I did some testing with the following text in a contenteditable div:

  foo<a href=a>bar</a>baz<br>foo<b>bar</b>baz

I tried to position the cursor at the start and end of the word "bar" on both lines, then typed "x" to see if the letter went inside or outside the tag.  In Blink, Edge, and LibreOffice, no matter how I try to position the cursor (keyboard and mouse from either side), the "x" always goes outside the link, and for the <b>, it goes outside at the beginning and inside at the end.  This seems reasonable.

In Firefox, for both link and bold, it depends on the side you come from.  If you navigate with the keyboard from inside the tag, it will be inside.  If from outside, it will be outside.  If you click on the outer edge of "bar", it will be inside.  If from the end of "foo" or beginning of "baz", it will be outside.  I can see the logic in this, but in practice it doesn't match other implementations, and the mouse part especially is confusing (it depends on the exact pixel you click on).

So I think we should change to match other UAs here.  I don't know offhand where the relevant code lives, though.  I suspect it will have to be made smarter.
Masayuki, do you know where the code is that decides where to place the cursor when you click somewhere, navigate with arrow keys, etc.?  Or know who would know?
Flags: needinfo?(masayuki)
I worked in that code a bit, see changes to layout/generic/nsFrame.cpp in
Aryeh, when you return at the end of October, do you think there is a chance to get this fixed in mozilla52 before the next branch date, 7th of Nov. 2016. I know, it's a bad question since some bugs take longer and then miss the branch date by a few hours.
I think I'm not going to work on bugs like this anymore unless they affect major real-world sites.  Real-world editors on sites normally handle user input themselves, so this type of change is of extremely little benefit to Firefox users and is very prone to breaking things.
Priority: -- → P3
Simple fix:

          Format --> Discontinue Link (Ctrl+Shift+K)

Whiteboard: [h2review-noted]
See Also: → 1357365

Testcase of attachment 8753532 [details] is now working correctly (link discontinued when pressing Enter after the link).
This was fixed in Bug 1422234 - Pressing Enter after an anchor link causes the content in new line to associate with the link.

Unfortunately, for most Thunderbird bugs which were generously duped here, the problem remains for typing anything else but Enter after a trailing link, which is seriously annoying because it makes any such link "sticky" with no easy way to discontinue it (Ctrl+Shift+K or other workarounds aren't easy). The remaining case (and the key problem for Thunderbird) is Bug 1357365:

Bug 1357365 - Can't exit links in contenteditable elements

I will reshuffle duplicates accordingly.

(In reply to Masayuki Nakano [:masayuki] from Bug 1357365 comment #2)

After landing bug 1422234, pressing Enter at end of link stops creating
another <a> element in new paragraph. However, we still don't have a way to
put caret outside the <a> element.

(In reply to Masayuki Nakano [:masayuki] from Bug 1357365 comment #3)

After landing bug 1496320, if caret is moved from outside of <a href>, typing new character at edge of the element is treated as typing outside it. I guess that the remaining issue is, the case when there is no content before or after <a href> in the block or line.

Closed: 3 years ago
Resolution: --- → DUPLICATE
Summary: Link in paragraph gets extended/repeated onto new line when hitting enter → Link in paragraph gets extended/repeated onto new line when hitting Enter
You need to log in before you can comment on or make changes to this bug.