# 添加提及/表情/标签时会产生尾随空格但不会移动光标

**URL:** https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201
**Category:** UX
**Created:** [2020年十一月15日 16:43 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201 "2020-11-15T16:43:44Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [2020年十一月15日 16:43 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/1 "2020-11-15T16:43:44Z")

</div>

当你通过输入 `@` 或 `:` 并跟随所需内容后按 Enter 添加提及或表情符号时，系统会自动补全用户名/表情符号名称，并在其后添加一个空格。我推测添加这个空格是为了让你能继续输入，但光标并没有相应地向后移动以避开这个新添加的空格。因此，目前你必须_无论如何_都再按一次空格键，从而导致末尾出现多余的空格。

考虑到你可能在添加提及或表情符号后还想完成句子（或结束发帖），我倾向于直接去掉这个末尾空格，让用户在需要空格时自行按下空格键。第二个选项是将光标向后移动一个字符，使其位于空格之后（这是否原本就是预期行为？），但我不确定这样做有多少价值。比起删除自动添加的多余空格，我更希望在需要空格时手动按下空格键。

（我知道这有点接近 bug 的范畴，如果这更适合 #Contribute > UX 或 #Contribute > Feature 标签，请随意移动。另外，在我写完上一句时，我突然意识到标签 / `#` 也会出现同样的情况。）

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2020年十一月16日 03:53 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/2 "2020-11-16T03:53:14Z")

</div>

它确实有些古怪，也 mildly 令人烦恼，比如 GitHub 会移动光标，这更有道理。

我支持移动光标。

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [2021年一月13日 10:32 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/3 "2021-01-13T10:32:12Z")

</div>

最近两周左右，这方面有什么变化吗？🤔

我在所有表情符号的末尾添加了很多 `:t2` 值，并且一直使用键盘输入。

例如，要获取白色版本的竖起大拇指表情，我会输入：

`:+`

然后按 `Tab` 键完成黄色的竖起大拇指表情，接着继续输入 `:t`，此时会弹出一个简短的颜色列表：

 ![image](https://global.discourse-cdn.com/meta/original/3X/1/f/1fcc073dfc03d6cff9f2ecbfde017e0320752c77.png)

这时我只需再次按 `Tab` 键，即可自动补全我想要的 `:t2` 变体。

然而，在看似最近的更新之后，每当我按 `Tab` 键完成第一个 `:+1:` 时，末尾会自动添加一个空格。这意味着我现在需要先按退格键，_然后_才能继续输入我的 `:t` 变体？

---

<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: [2021年一月21日 06:29 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/4 "2021-01-21T06:29:00Z")

</div>

几乎可以肯定是一个新的回归问题，也许 @sam 回来后可以查看一下。

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2021年一月29日 04:01 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/10 "2021-01-29T04:01:41Z")

</div>

我完全理解这里的不便，但之前我们是在插入空格并将光标向后移动，这造成了混淆，并引发了许多细微的问题。

我们当然喜欢插入空格，但我很犹豫让 `:heart:` 插入空格而 `:+1:` 却不插入。

我认为最好的方案是在浏览器的本地设置中引入一个“后台设置”。只需让客户端“记住”您上次选择的肤色，然后默认添加它即可。

那么这里的修复就很简单了，您只需在此处进行一次更改：

 ![image](https://global.discourse-cdn.com/meta/original/3X/a/b/aba0c87d8b21a684f5dba58783e272435068f5e8.png)

之后您插入的后续表情符号将自动附加肤色，例如 `:+1:t3:`。我更喜欢这个方案，因为我们更加尊重用户。您很可能希望保持使用刚刚选择的肤色。

@codinghorror 您觉得这个方案如何？

---

<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: [2021年一月29日 04:36 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/11 "2021-01-29T04:36:29Z")

</div>

我觉得不错！👍🏿

---

<div class="post-metadata">

### Author: ![Osama](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osama/32/98013_2.png) [@Osama](https://meta.discourse.org/u/Osama)
#### Post date: [2021年二月1日 16:07 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/14 "2021-02-01T16:07:25Z")

</div>

这个 PR 应该能解决问题：

> <https://github.com/discourse/discourse/pull/11917>
>
> This PR makes our emoji autocomplete in the composer respect the skin tone you s…elect in the emoji picker.
> 
> Before:
> 
> !\[image\](https://user-images.githubusercontent.com/17474474/106482458-86057300-64be-11eb-9c4c-916720add2fd.png)
> 
> After:
> 
> !\[image\](https://user-images.githubusercontent.com/17474474/106482225-4e96c680-64be-11eb-862c-9068a2bb9a43.png)
> 
> Context: https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/10?u=osama

客户端应用已经会记住用户选择的肤色（表情选择器也已尊重所选肤色），但目前我们的表情自动补全功能并未尊重所选肤色，始终建议黄色肤色。该 PR 将使表情自动补全默认使用用户选择的肤色。

修改前 / 修改后：

 ![image](https://global.discourse-cdn.com/meta/original/3X/0/b/0bd7cb86a02003a51cbcab2ebbc9e63536357ff6.png) ![image](https://global.discourse-cdn.com/meta/original/3X/6/5/6560dae8a2c05bfa4a0af120ef074d30b3d88a85.png)

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [2021年二月1日 19:51 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/15 "2021-02-01T19:51:16Z")

</div>

太棒了！

非常感谢大家，正是这些小事让这里成为一个如此出色的平台 🙇🏻‍♂️

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2021年二月2日 00:25 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/16 "2021-02-02T00:25:32Z")

</div>

@seanblue 你对新功能满意吗？明天将自动关闭此议题。

---

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [2021年二月2日 17:57 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/17 "2021-02-02T17:57:22Z")

</div>

关于我最初的投诉/建议，是的，我对这次更改感到满意。现在光标已移至插入空格之后，我认为这样很好。感谢处理此事。

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2021年二月3日 01:07 UTC](https://meta.discourse.org/t/adding-mention-emoji-tag-adds-trailing-space-but-doesnt-move-cursor/170201/18 "2021-02-03T01:07:53Z")

</div>


