Skip to content

Commit

Permalink
hotfix(core): Fix input rules not working if at last position of a bl…
Browse files Browse the repository at this point in the history
…ock (#4337)

* chore(core): remove log

* fix(core): fix inputRules breaking if last item in hierarchy

* fix(core): use default doc node if no parent default node is found

* chore: update .eslintrc

* chore: fix linting

* chore: fix linting
  • Loading branch information
bdbch committed Aug 16, 2023
1 parent b0eecc8 commit 0d7daed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion demos/src/Experiments/OnUpdateRerender/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default () => {
const [index, setIndex] = React.useState(0)

const handleUpdate = ({ editor: currentEditor }) => {
console.log(index, 'onUpdate', currentEditor.getHTML())
console.log(index, 'onUpdate', currentEditor.getHTML()) // eslint-disable-line no-console
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default {
</p>
`,
onUpdate: ({ editor: currentEditor }) => {
console.log(this.count, 'onUpdate', currentEditor.getHTML())
console.log(this.count, 'onUpdate', currentEditor.getHTML()) // eslint-disable-line no-console
},
})
},
Expand Down
15 changes: 7 additions & 8 deletions packages/core/src/inputRules/nodeInputRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,23 @@ export function nodeInputRule(config: {
}

if (config.blockReplace && config.addExtraNewline) {
const posAfter = $to.end()

if ($to.nodeAfter) {
console.log($to.node().type.name)
if ($to.nodeAfter.isTextblock) {
tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1))
} else if ($to.nodeAfter.isBlock) {
tr.setSelection(NodeSelection.create(tr.doc, $to.pos))
} else {
tr.setSelection(TextSelection.create(tr.doc, $to.pos))
tr.setSelection(TextSelection.create(tr.doc, $to.pos - 1))
}
} else {
// add node after horizontal rule if it’s the end of the document
const node = $to.parent.type.contentMatch.defaultType?.create()
const defaultNode = $to.parent.type.contentMatch.defaultType?.create() || state.doc.type.contentMatch.defaultType?.create()

if (defaultNode) {
const newPos = start + newNode.nodeSize

if (node) {
tr.insert(posAfter, node)
tr.setSelection(TextSelection.create(tr.doc, posAfter + 1))
tr.insert(newPos, defaultNode)
tr.setSelection(TextSelection.create(tr.doc, newPos))
}
}

Expand Down

0 comments on commit 0d7daed

Please sign in to comment.