案例 ce-0003 · 场景 scenario-double-line-break

Pressing Enter inserts two line breaks in contenteditable

操作系统: macOS 14.0 设备: Laptop MacBook Pro 浏览器: Safari 17.0 键盘: US 草稿
enternewline

此页面尚未翻译

目前显示的是英文原文。欢迎您参与翻译工作。

Phenomenon

In a plain contenteditable element, pressing Enter inserts two visible line breaks instead of one. The resulting DOM contains nested <div> or <br> elements that render as an extra blank line.

Reproduction example

  1. Focus the editable area.
  2. Type a short word on the first line.
  3. Press Enter once.
  4. Type another word on what appears to be the second line.

Observed behavior

  • The visual gap between the lines is larger than a single line height.
  • Inspecting the DOM shows two consecutive block-level containers or a sequence of <br> elements that corresponds to two line breaks.

Expected behavior

  • Pressing Enter once inserts a single paragraph break.

Notes and possible direction for workarounds

  • Check whether the browser uses <div>, <p>, or <br> to represent paragraph breaks in this configuration.
  • Adjust CSS line-height and margins to verify whether the effect comes from DOM structure or styling.
  • For products that must normalize the markup, consider translating the native structure into a controlled model (for example, a single <p> per line) before storing or diffing the content.

此场景的变体

案例 操作系统 浏览器 状态
ce-0003 macOS 14.0 Safari 17.0 草稿
ce-0023 macOS Ubuntu 22.04 Chrome 120.0 草稿

Playground for this case

Use the reported environment as a reference and record what happens in your environment while interacting with the editable area.

Reported environment
OS: macOS 14.0
Device: Laptop MacBook Pro
Browser: Safari 17.0
Keyboard: US
Your environment

Use this editable area to reproduce the described case.

Event log
Use this log together with the case description when filing or updating an issue.
0 events
Interact with the editable area to see events here.