Fix extra spaces a user selects when adding a link

Here’s a small detail I keep bumping into: When adding a link to text in Post edit, if the selection includes the leading space that space will be swallowed in the process.

Testingthe leading space on Meta. Yep, it does the same. I try to be more careful but it keeps happening and might be a quick thing to fix…

Here’s how it looks in my instance:

3 Likes

It does not add a space automatically? Does it look normal if you manually add a space in-between what is circled?

In your example you select the leading space when creating the link. That’s not typical behavior. Try selecting the word without the space and the issue won’t occur.

It’s hard to call this a bug as the toolbar button is trimming white space from the selection because whitespace within anchors looks messy.

The latter is only happening because you’re selecting the leading space, don’t do that and the link presentation cleanup won’t hit you.

3 Likes

You are correct but a nice user convenience feature would be to detect this and fix it up for the user, if a single leading or trailing space is selected, put them back in the replacement.

8 Likes

Exactly… and it can be put back outside the anchor to avoid the messy anchor whitespace issue…

3 Likes

https://github.com/discourse/discourse/commit/580b28986192cb659ea4232c3a22c865125e9197

The above commit should resolve this issue.

4 Likes

This topic was automatically closed after 2 days. New replies are no longer allowed.