fix(richtext-lexical): reset indent on node transforms (#12183)
### What? Resets the indentation on editor updates for nodes for which indentation is disabled. ### Why? If a node gets transformed, e.g. from a list to a paragraph node, it remains the indent property by default. If indentation for this node is disabled, it would remain indented although it shouldn't. ### How? Adds a listener which resets the indent status on updates for non-indentable nodes.
This commit is contained in:
@@ -26,7 +26,8 @@ export const IndentPlugin: PluginComponent<IndentFeatureProps> = ({ clientProps
|
||||
if (!editor || !disabledNodes?.length) {
|
||||
return
|
||||
}
|
||||
return editor.registerCommand(
|
||||
return mergeRegister(
|
||||
editor.registerCommand(
|
||||
INDENT_CONTENT_COMMAND,
|
||||
() => {
|
||||
return $handleIndentAndOutdent((block) => {
|
||||
@@ -37,6 +38,23 @@ export const IndentPlugin: PluginComponent<IndentFeatureProps> = ({ clientProps
|
||||
})
|
||||
},
|
||||
COMMAND_PRIORITY_LOW,
|
||||
),
|
||||
// If we disable indenting for certain nodes, we need to ensure that these are not indented,
|
||||
// if they get transformed from an indented state (e.g. an indented list node gets transformed into a
|
||||
// paragraph node for which indenting is disabled).
|
||||
editor.registerUpdateListener(({ dirtyElements, editorState }) => {
|
||||
editor.update(() => {
|
||||
for (const [nodeKey] of dirtyElements) {
|
||||
const node = editorState._nodeMap.get(nodeKey)
|
||||
if ($isElementNode(node) && disabledNodes.includes(node.getType())) {
|
||||
const currentIndent = node.getIndent()
|
||||
if (currentIndent > 0) {
|
||||
node.setIndent(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}),
|
||||
)
|
||||
}, [editor, disabledNodes])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user