Skip to content

Commit 9a24f93

Browse files
committed
Fix the ordering calculation when cloning
1 parent 0e75b21 commit 9a24f93

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Change log
55
Next version
66
============
77

8+
- Fixed the ordering calculation when cloning content: The gap for the new
9+
cloned content already had the correct size, but the base ordering value was
10+
incorrect.
11+
812

913
8.0 (2025-08-25)
1014
================

content_editor/static/content_editor/content_editor.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,15 +1187,6 @@
11871187
value: ContentEditor.currentRegion,
11881188
}),
11891189
)
1190-
if (ContentEditor._insertBefore) {
1191-
dialog.append(
1192-
crel("input", {
1193-
type: "hidden",
1194-
name: "_clone_ordering",
1195-
value: ContentEditor._insertBefore.style.order,
1196-
}),
1197-
)
1198-
}
11991190

12001191
dialog.append(
12011192
crel("div", { className: "submit-row" }, [saveButton, cancelButton]),
@@ -1204,16 +1195,27 @@
12041195
const bumpOrdering = () => {
12051196
if (!ContentEditor._insertBefore) return
12061197

1207-
const gap = qsa("input[type=checkbox]:checked", dialog).length - 1
1198+
const checked = qsa("input[type=checkbox]:checked", dialog).length
12081199
const inlines = findInlinesInOrder()
1209-
let order = 0
1200+
let order = 10
12101201

12111202
for (const inline of inlines) {
12121203
if (inline === ContentEditor._insertBefore) {
1213-
order += gap
1204+
dialog.append(
1205+
crel("input", {
1206+
type: "hidden",
1207+
name: "_clone_ordering",
1208+
value: order,
1209+
}),
1210+
)
1211+
1212+
// Next order is checked-1 since we already have incremented by
1213+
// 10 after the last item
1214+
order += (checked - 1) * 10
12141215
}
12151216

1216-
qs(".order-machine-ordering", inline).value = 10 * ++order
1217+
qs(".order-machine-ordering", inline).value = order
1218+
order += 10
12171219
}
12181220
}
12191221

tests/testapp/test_playwright.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,13 +909,13 @@ def test_clone_insert_between_existing_content(page: Page, django_server, client
909909
text="<p>Main content 2</p>", region="main", ordering=20
910910
)
911911

912-
# Add existing content to sidebar region with gaps for insertion
913-
# Use ordering values that won't be normalized during save
912+
# Use ridiculous ordering values which, if not handled properly, will cause
913+
# the cloned content to be inserted in an incorrect place.
914914
article.testapp_richtext_set.create(
915-
text="<p>Sidebar BEFORE cloned content</p>", region="sidebar", ordering=10
915+
text="<p>Sidebar BEFORE cloned content</p>", region="sidebar", ordering=110
916916
)
917917
article.testapp_richtext_set.create(
918-
text="<p>Sidebar AFTER cloned content</p>", region="sidebar", ordering=20
918+
text="<p>Sidebar AFTER cloned content</p>", region="sidebar", ordering=120
919919
)
920920

921921
# Navigate to the admin change page

0 commit comments

Comments
 (0)