Skip to content

Commit 3b398be

Browse files
committed
Fix problems with mismatched transactions
1 parent 03012cd commit 3b398be

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

django_prose_editor/static/django_prose_editor/editor.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

django_prose_editor/static/django_prose_editor/editor.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodeClass.js

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ export const NodeClass = Extension.create({
113113
return false
114114
} else {
115115
// Handle mark: extend mark range and update attributes
116-
return commands
117-
.chain()
118-
.extendMarkRange(type)
119-
.updateAttributes(type, { class: className })
116+
commands.extendMarkRange(type)
117+
return commands.updateAttributes(type, { class: className })
120118
}
121119
},
122120

@@ -127,30 +125,26 @@ export const NodeClass = Extension.create({
127125
const cssClasses = this.options.cssClasses
128126

129127
if (!type) {
130-
// Clear all classes from all types
128+
// Clear all classes from all types - execute each clear operation
131129
const applicableNodes = getApplicableNodes(state, cssClasses)
132130
const applicableMarks = getApplicableMarks(state, cssClasses)
133131

134-
let chain = commands.chain()
135-
136-
// Reset node classes
137-
if (applicableNodes.length > 0) {
138-
chain = chain.command(({ tr }) => {
139-
for (const { pos } of applicableNodes) {
140-
tr.setNodeAttribute(pos, "class", null)
141-
}
142-
return true
143-
})
144-
}
145-
146-
// Reset mark classes
147-
for (const { markType } of applicableMarks) {
148-
chain = chain
149-
.extendMarkRange(markType)
150-
.updateAttributes(markType, { class: null })
151-
}
152-
153-
return chain.run()
132+
// Collect all unique types to clear
133+
const typesToClear = new Set()
134+
applicableNodes.forEach(({ nodeType }) => {
135+
typesToClear.add(nodeType)
136+
})
137+
applicableMarks.forEach(({ markType }) => {
138+
typesToClear.add(markType.name)
139+
})
140+
141+
// Clear each type using this same command recursively
142+
let success = true
143+
typesToClear.forEach((typeName) => {
144+
success = success && commands.unsetNodeClass(typeName)
145+
})
146+
147+
return success
154148
}
155149

156150
// Clear classes from specific type
@@ -175,10 +169,8 @@ export const NodeClass = Extension.create({
175169
return false
176170
} else {
177171
// Handle mark
178-
return commands
179-
.chain()
180-
.extendMarkRange(type)
181-
.updateAttributes(type, { class: null })
172+
commands.extendMarkRange(type)
173+
return commands.updateAttributes(type, { class: null })
182174
}
183175
},
184176
}

0 commit comments

Comments
 (0)