# 允许在颜色文本输入框中粘贴带有前导#的十六进制颜色字符串（主题定制）」}

**URL:** <https://meta.discourse.org/t/allow-pasting-a-hex-color-string-with-a-leading-in-a-color-text-input-theme-customization/134715>\
**Category:** UX\
**Created:** [2019年十一月29日 17:40 UTC](https://meta.discourse.org/t/allow-pasting-a-hex-color-string-with-a-leading-in-a-color-text-input-theme-customization/134715 "2019-11-29T17:40:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
**Post date:** [2019年十一月29日 17:40 UTC](https://meta.discourse.org/t/allow-pasting-a-hex-color-string-with-a-leading-in-a-color-text-input-theme-customization/134715/1 "2019-11-29T17:40:13Z")

</div>

（不确定这应被视为 bug 还是用户体验问题）

您好，

在电脑上操作十六进制颜色值时，您经常从剪贴板复制带有前导 `#` 的十六进制值并粘贴。  
例如，将 `#1a2331` 粘贴到颜色文本输入框时，会出现一个小问题：  
首先，由于输入框限制为六个字符，而 `#1a2331` 因包含 `#` 共有七个字符，因此字符串的最后一个字符会被移除。  
随后，`#` 会从字符串中自动剥离。  
因此，粘贴后输入框中的最终值变为：`1a233`，缺少了最后一个字符 `1`，导致颜色值错误。

一种解决方案是：在检查字符串字符数之前，先移除 `#`。

要复现此问题，请在 Discourse 颜色主题自定义的任何颜色文本输入框中粘贴字符串 `#1a2331`。

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

我使用的是 Windows 10 和 Chrome 浏览器，Discourse 版本为 2.4.0.beta7。

---

<div class="post-metadata">

**Author:** ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)\
**Post date:** [2019年十一月29日 17:50 UTC](https://meta.discourse.org/t/allow-pasting-a-hex-color-string-with-a-leading-in-a-color-text-input-theme-customization/134715/2 "2019-11-29T17:50:26Z")

</div>

据我所知，在 Discourse 调色板中插入十六进制代码的方式一直如您所描述的那样。您只需手动输入十六进制数值，并省略 `#` 符号。

许多颜色选择器都提供选项，允许您预先设定代码格式，从而复制十六进制代码。

 ![image](https://global.discourse-cdn.com/meta/original/3X/3/4/342a6b35aa79b48daabb43f7ca5192681dcbe882.png)

---

<div class="post-metadata">

**Author:** ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
**Post date:** [2019年十一月29日 17:53 UTC](https://meta.discourse.org/t/allow-pasting-a-hex-color-string-with-a-leading-in-a-color-text-input-theme-customization/134715/3 "2019-11-29T17:53:52Z")

</div>

我明白，只是这个行为有点奇怪。我不得不检查了几次我复制粘贴的值，才注意到输入中字符串的最后一个数字缺失了。起初我不明白为什么值无效，我想这种特定的复制粘贴行为可以在没有任何缺点的情况下得到改进。

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [2023年九月5日 05:52 UTC](https://meta.discourse.org/t/allow-pasting-a-hex-color-string-with-a-leading-in-a-color-text-input-theme-customization/134715/4 "2023-09-05T05:52:18Z")

</div>



---

<div class="post-metadata">

**Author:** ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)\
**Post date:** [2024年七月29日 21:45 UTC](https://meta.discourse.org/t/allow-pasting-a-hex-color-string-with-a-leading-in-a-color-text-input-theme-customization/134715/5 "2024-07-29T21:45:31Z")

</div>

这仍然是个问题。

> [@dax](#):
>
> 许多颜色选择器会让你选择复制十六进制代码，但前提是你必须先决定代码格式

但很多都没有！

如果 Discourse 在将颜色粘贴到各种设置时自动处理前面的 `#`，那将是一种非常好的润色。
