commit 19cda19b23183f8930b11734b39a00035847d43d
parent 78e97608128161803edac5f4ae85df03b5aa4191
Author: Masayuki Nakano <masayuki@d-toybox.com>
Date: Mon, 1 Dec 2025 02:27:49 +0000
Bug 2002574 - Make `WSScanResult::CreateEditorLineBreak()` return correct preformatted line break position if scanned backward r=m_kato
This is a mistake caused by my misunderstanding. `mOffset` is a +1 value
if the scan direction is backward. See
https://searchfox.org/firefox-main/rev/1c9d86edc5d91b67ba8c858a053de40e1b98dc95/editor/libeditor/WSRunScanner.h#219,226-229
Differential Revision: https://phabricator.services.mozilla.com/D274240
Diffstat:
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/editor/libeditor/WSRunScanner.h b/editor/libeditor/WSRunScanner.h
@@ -169,7 +169,11 @@ class MOZ_STACK_CLASS WSScanResult final {
return EditorLineBreakType(*BRElementPtr());
}
if (ReachedPreformattedLineBreak()) {
- return EditorLineBreakType(*TextPtr(), *mOffset);
+ MOZ_ASSERT_IF(mDirection == ScanDirection::Backward, *mOffset > 0);
+ return EditorLineBreakType(*TextPtr(),
+ mDirection == ScanDirection::Forward
+ ? mOffset.valueOr(0)
+ : std::max(mOffset.valueOr(1), 1u) - 1);
}
MOZ_CRASH("Didn't reach a line break");
return EditorLineBreakType(*BRElementPtr());
diff --git a/testing/web-platform/tests/editing/crashtests/join-first-li-containing-preformatted-linefeed-and-last-li.html b/testing/web-platform/tests/editing/crashtests/join-first-li-containing-preformatted-linefeed-and-last-li.html
@@ -0,0 +1,34 @@
+<!doctype html>
+<html>
+<head>
+<meta charset="utf-8">
+<style>
+*:last-child {
+ white-space: pre-line;
+}
+</style>
+<script>
+"use strict";
+
+addEventListener("load", () => {
+ document.designMode = "on";
+ getSelection().setBaseAndExtent(
+ document.querySelector("ol"),
+ 0,
+ document.querySelector("ol"),
+ document.querySelector("ol").childNodes.length
+ );
+ document.execCommand("insertHTML", false, "");
+}, {once: true});
+</script>
+</head>
+<!-- Do not change the white-spaces between <li> elements nor the line break in the first <li> -->
+<body>
+<ol><li>
+</li><li>
+<blockquote style="display:inline-flex">
+ <title contenteditable></title>
+</blockquote>
+</li><li></li></ol>
+</body>
+</html>