为什么可编辑文档的 Opera 中换行符会变成空格或消失?

发布于 2024-11-25 18:24:44 字数 873 浏览 2 评论 0 原文

为什么对于内容可编辑的文档,换行符在 Opera 中显示为空格或在 Enter/Return 键上消失?

试试这个演示:

<!DOCTYPE html>
<html>
<head>
<title>contentEditable demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body contenteditable="true" spellcheck="true" dir="ltr">
<h1>Welcome to the contentEditable demo!</h1><p><span style="font-size: xx-large">
Try<span style="font-size: small">to type some text before the word "Try". You will see that random spaces are inserted before the word. Press Enter; you will see that the newline on the top disappears.</span></span></p></body>
</html>

Windows Vista 上的 Opera 11.50 Build 1074

这是 Opera 错误吗?我在 Windows Internet Explorer 8、Safari、Google Chrome 或 Firefox 5 中没有遇到此错误。

Why do newlines appear as spaces or disappear on Enter/Return key in Opera for contentEditable documents?

Try out this demo:

<!DOCTYPE html>
<html>
<head>
<title>contentEditable demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body contenteditable="true" spellcheck="true" dir="ltr">
<h1>Welcome to the contentEditable demo!</h1><p><span style="font-size: xx-large">
Try<span style="font-size: small">to type some text before the word "Try". You will see that random spaces are inserted before the word. Press Enter; you will see that the newline on the top disappears.</span></span></p></body>
</html>

Opera 11.50 Build 1074 on Windows Vista

Is this an Opera bug? I did not experience this bug with Windows Internet Explorer 8, Safari, Google Chrome, or Firefox 5.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

皓月长歌 2024-12-02 18:24:44

我想我可能已经从这些链接中发现了原因:

[whatwg]处理内容编辑中折叠的空白:

http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-June/032187.html

  • 行尾的 nbsp 会使最后一个单词变长,因此当您按空格时,该行的最后一个单词可能会跳转到下一行。然后
    当您键入字母时,nbsp 会转换为常规空格,并且
    这个词跳回上一行。
    (我在 Opera 中观察到了这一点。
    IE 和 Gecko 似乎有一些特殊情况可以避免这种情况;网络工具包
    通过更通用的 hack 来避免它,我稍后会注意到。)
  • 紧接在单词之前的 nbsp如果碰巧开始一行,将导致该单词缩进。壁虎好像很
    小心避免这种情况,但所有其他引擎有时都会这样做。
  • 一长串空格(其中一些是空格,一些是 nbsp's)可能会导致 nbsp's 出现在行的开头。因此,如果您输入
    在某些情况下,无论出于何种原因,两个单词之间有三个空格
    第二个单词可以缩进。这可能不是用户所希望的
    想要。

Bug 13011 - [编辑] 鼓励作者对 contenteditable="" 和 .designMode=true 使用“white-space: pre-wrap”:

https://www.w3.org/Bugs/Public/show_bug.cgi?id=13011

没有预包装的潜在问题示例:如果用户键入
“foo bar”,中间有两个空格,将成为
“foo 酒吧”或“foo 酒吧”。在第一种情况下,“foo ”
可能会换行到下一行,即使“foo”本身就可以适合
当前行。在第二种情况下,如果“ bar”开始一行,
将明显缩进

页内编辑器的最佳实践:

http://developers .whatwg.org/editing.html#best-practices-for-in-page-editors

在前一种情况下,“yellow⍽”可能会换行到下一行(“⍽”是
此处用于表示不间断空格)即使“黄色”
单独可能适合该行的末尾;在后一种情况下,“⍽球”,
如果换行到行首,将有可见的缩进
从不间断空格开始

I think that I may have discovered why from these links:

[whatwg] Handling of collapsed whitespace in contenteditable:

http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-June/032187.html

  • An nbsp at the end of a line makes the last word longer, so when you hit space, the last word on the line might jump to the next line. Then
    when you type a letter, the nbsp gets converted to a regular space and
    the word jumps back to the previous line.
    (I observed this in Opera.
    IE and Gecko seem to have some special-case to avoid this; WebKit
    avoids it with a more general hack that I'll note later.)
  • An nbsp that winds up immediately before a word will cause the word to be indented if it happens to start a line. Gecko seems to be very
    careful to avoid this case, but all other engines do it sometimes.
  • A long run of spaces of which some are spaces and some are nbsp's can result in nbsp's at the beginning of a line. Thus if you type
    three spaces in between two words for whatever reason, in some cases
    the second word can be indented. This is probably not what users
    want.

Bug 13011 - [editing] Encourage authors to use "white-space: pre-wrap" for contenteditable="" and .designMode=true:

https://www.w3.org/Bugs/Public/show_bug.cgi?id=13011

Example of a potential problem without pre-wrap: if the user types
"foo bar", with two spaces in between, that will become either
"foo  bar" or "foo  bar". In the first case, "foo "
might wrap to the next line even though "foo" alone could fit on the
current line. In the second case, if " bar" starts a line, it
will be visibly indented
.

Best practices for in-page editors:

http://developers.whatwg.org/editing.html#best-practices-for-in-page-editors

In the former case, "yellow⍽" might wrap to the next line ("⍽" being
used here to represent a non-breaking space) even though "yellow"
alone might fit at the end of the line; in the latter case, "⍽ball",
if wrapped to the start of the line, would have visible indentation
from the non-breaking space
.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文