# 修复用户在添加链接时选择的多余空格

**URL:** <https://meta.discourse.org/t/fix-extra-spaces-a-user-selects-when-adding-a-link/133568>\
**Category:** Feature\
**Created:** [2019年十一月16日 16:55 UTC](https://meta.discourse.org/t/fix-extra-spaces-a-user-selects-when-adding-a-link/133568 "2019-11-16T16:55:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cardinalflyer](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Cardinalflyer](https://meta.discourse.org/u/Cardinalflyer)\
**Post date:** [2019年十一月16日 16:55 UTC](https://meta.discourse.org/t/fix-extra-spaces-a-user-selects-when-adding-a-link/133568/1 "2019-11-16T16:55:15Z")

</div>

这里有个小细节我老是遇到：在帖子编辑中添加链接时，如果选中的文本包含前导空格，该空格在操作过程中会被吞掉。

我在 Meta 上测试了[前导空格](https://www.cardinalflyers.com)。是的，确实如此。我尽量更小心些，但它还是会发生，或许可以很快修复……

在我的实例中，效果如下：

 ![link%20space](https://global.discourse-cdn.com/meta/original/3X/d/2/d2c4b0d6e3a1fba1cee10467e8a4824216f697a2.gif)

---

<div class="post-metadata">

**Author:** ![ondrej](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ondrej/32/198804_2.png) [@ondrej](https://meta.discourse.org/u/ondrej)\
**Post date:** [2019年十一月16日 17:25 UTC](https://meta.discourse.org/t/fix-extra-spaces-a-user-selects-when-adding-a-link/133568/2 "2019-11-16T17:25:08Z")

</div>

它不会自动添加空格吗？如果在圈出的内容之间手动添加一个空格，看起来正常吗？

 ![sketch-1573925021708](https://global.discourse-cdn.com/meta/original/3X/3/7/37cc307f17e9ffa0d806e9c1f5cd66f7bd8f5605.png)

---

<div class="post-metadata">

**Author:** ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)\
**Post date:** [2019年十一月17日 04:42 UTC](https://meta.discourse.org/t/fix-extra-spaces-a-user-selects-when-adding-a-link/133568/4 "2019-11-17T04:42:34Z")

</div>

在您的示例中，创建链接时选中了前导空格。这不是典型行为。尝试选中不带空格的单词，问题就不会出现。

这很难被称为一个错误，因为工具栏按钮会从选区中修剪空白字符，因为锚点内的空白字符看起来杂乱无章。

后一种情况的发生仅仅是因为您选中了前导空格。不要这样做，链接呈现的清理功能就不会对您造成影响。

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2019年十一月17日 05:39 UTC](https://meta.discourse.org/t/fix-extra-spaces-a-user-selects-when-adding-a-link/133568/5 "2019-11-17T05:39:36Z")

</div>

你说得对，但如果用户选中了单个前导或尾随空格，一个贴心的功能就是自动检测并修复，在替换时将这些空格保留回去。

---

<div class="post-metadata">

**Author:** ![Cardinalflyer](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Cardinalflyer](https://meta.discourse.org/u/Cardinalflyer)\
**Post date:** [2019年十一月17日 15:20 UTC](https://meta.discourse.org/t/fix-extra-spaces-a-user-selects-when-adding-a-link/133568/6 "2019-11-17T15:20:46Z")

</div>

> [@codinghorror](#):
>
> 把它们放回替换内容中。

没错……而且可以将其放在锚点_之外_，以避免锚点内出现杂乱的空白问题……

---

<div class="post-metadata">

**Author:** ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)\
**Post date:** [2019年十一月30日 14:46 UTC](https://meta.discourse.org/t/fix-extra-spaces-a-user-selects-when-adding-a-link/133568/10 "2019-11-30T14:46:24Z")

</div>

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

上述提交应能解决此问题。

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2019年十二月3日 02:00 UTC](https://meta.discourse.org/t/fix-extra-spaces-a-user-selects-when-adding-a-link/133568/11 "2019-12-03T02:00:07Z")

</div>

此主题已在 2 天后自动关闭。不再允许新的回复。
