# 多行选择不包含硬换行时使用的内联“预格式化文本”格式

**URL:** https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049
**Category:** Bug
**Tags:** composer
**Created:** [2025年十月29日 12:01 UTC](https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049 "2025-10-29T12:01:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![per1234](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/per1234/32/569645_2.png) [@per1234](https://meta.discourse.org/u/per1234)
#### Post date: [2025年十月29日 12:01 UTC](https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049/1 "2025-10-29T12:01:29Z")

</div>

### 优先级/严重性：

中

### 平台

#### 操作系统

Windows 11

#### 浏览器

Google Chrome 141.0.7390.123

#### Discourse

`ad36231adab58a8a249bfe8139aade2bde2134d3`

### 描述：

“预格式化文本”格式有两种样式：

- 行内：用于在文本段落中使用非文本内容（例如，“调用 `foo` 函数”），或单行非文本内容。
- 块：用于多行非文本内容。

用户在作曲家中使用格式时，可以选择以下两种方法之一：

- 主动：在添加要格式化的内容之前切换格式模式。
- 被动：以未格式化的形式添加内容，然后选择该内容并应用格式。

🐛 在以下条件下，将“预格式化文本”格式应用于多行选择会使用不当的“行内”样式：

- 作曲家处于“富文本编辑器”模式。
- 格式被动应用。
- 所选内容中不存在硬换行符。

这导致帖子难以阅读，并且非文本内容难以复制（这是共享代码的常见要求）。

### 可复现步骤：

1. 打开作曲家。
2. 将编辑器模式开关置于“富文本编辑器”位置。
3. 在作曲家中键入 `foo`。
4. 按下 **Shift** + **Enter** 键盘快捷键添加“软换行”。
5. 在作曲家中键入 `bar`。  
❗ 不要添加换行符。
6. 按下 **Ctrl** + **Shift** + **Home** 键盘快捷键，从第二行的末尾到帖子的开头选择所有内容。
7. 点击作曲家工具栏上的 **\</\>** 按钮。

🐛 所选的每一行都以行内样式单独格式化：

`foo`  
`bar`

正确的行为是将内容放入单个代码块中：

```plaintext
foo
bar

```

### 其他上下文

我选择手动输入内容进行演示，以避免引入不必要的复杂性，即考虑从何处复制的内容可能存在的格式。但是，粘贴内容也会出现此错误，并且内容不包含硬换行符的条件更有可能与此类内容一起出现（因为用户在键入时很可能会使用 **Enter** ，即使他们实际上不想要硬换行符）。

* * *

如果使用“全选”/ **Ctrl** + **A** 选择内容，则不会出现此错误。

* * *

Markdown 编辑器在被动地将多行选择应用于“预格式化文本”格式时，始终将所选内容放入代码块中，这具有正确的行为。

* * *

我可以在 [try.discourse.org](http://try.discourse.org) 的“[安全模式](https://meta.discourse.org/t/how-to-use-discourse-safe-mode/53504)”中复现此错误。

* * *

最初报告于 [Why did the Forum functions change? - #37 by sterretje - Website and Forum - Arduino Forum](https://forum.arduino.cc/t/why-did-the-forum-functions-change/1400777/37)

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [2025年十月29日 12:50 UTC](https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049/2 "2025-10-29T12:50:36Z")

</div>

手动选择时似乎也不会发生这种情况。

---

<div class="post-metadata">

### Author: ![per1234](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/per1234/32/569645_2.png) [@per1234](https://meta.discourse.org/u/per1234)
#### Post date: [2025年十月29日 13:46 UTC](https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049/3 "2025-10-29T13:46:58Z")

</div>

你好 @NateDhaliwal。你说的“手动选择”是什么意思？

你是指用鼠标刮擦进行选择吗？如果是这样，该故障在使用该选择方法时仍然存在：

![manual-select](https://global.discourse-cdn.com/meta/original/4X/2/5/b/25bb544ae357665bcb3f90281189c22980aec28a.gif)

或者使用 **Shift** 箭头键？如果是这样，该故障在使用该选择方法时仍然存在：

![manual-select2](https://global.discourse-cdn.com/meta/original/4X/0/e/2/0e2d0696acdee911724da562b7e189856a2fcf33.gif)

---

<div class="post-metadata">

### Author: ![renato](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renato/32/383632_2.png) [@renato](https://meta.discourse.org/u/renato)
#### Post date: [2025年十月29日 14:35 UTC](https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049/4 "2025-10-29T14:35:07Z")

</div>

> [@per1234](#):
>
> 正确的做法是将内容放在一个代码块中：
> 
> ```plaintext
> foo
> bar
> 
> ```

我不确定这一点，这是一个故意的例外，因为在这种情况下，你仍然有一个带有换行的单个段落，并且在这种情况下应该可以添加内联代码标记。

我们甚至可以考虑更改此行为，但这并不是一个真正的错误。/cc @lindsey

---

<div class="post-metadata">

### Author: ![lindsey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lindsey/32/318210_2.png) [@lindsey](https://meta.discourse.org/u/lindsey)
#### Post date: [2025年十月29日 16:48 UTC](https://meta.discourse.org/t/inline-preformatted-text-formatting-used-when-multi-line-selection-doesnt-contain-hard-break/387049/5 "2025-10-29T16:48:27Z")

</div>

是的，在富文本和 Markdown 模式之间保持一致对我来说很有意义。
