@bangle.dev/core
Advanced tools
Comparing version 0.14.0 to 0.15.0
@@ -83,2 +83,77 @@ /** | ||
}); | ||
it('type --- above a paragraph', () => { | ||
const { view } = testEditor( | ||
<doc> | ||
<para>[]</para> | ||
<para>test</para> | ||
</doc>, | ||
); | ||
typeText(view, '---'); | ||
expect(view.state).toEqualDocAndSelection( | ||
<doc> | ||
<hr /> | ||
<para>[]test</para> | ||
</doc>, | ||
); | ||
}); | ||
it('type --- above a hr', () => { | ||
const { view } = testEditor( | ||
<doc> | ||
<para>[]</para> | ||
<hr /> | ||
</doc>, | ||
); | ||
typeText(view, '---'); | ||
expect(view.state).toEqualDocAndSelection( | ||
<doc> | ||
<hr /> | ||
<para>[]</para> | ||
<hr /> | ||
</doc>, | ||
); | ||
}); | ||
it('type --- inisde a nested blockquote', () => { | ||
const { view } = testEditor( | ||
<doc> | ||
<blockquote> | ||
<blockquote> | ||
<para>[]</para> | ||
</blockquote> | ||
</blockquote> | ||
</doc>, | ||
); | ||
typeText(view, '---'); | ||
expect(view.state).toEqualDocAndSelection( | ||
<doc> | ||
<blockquote> | ||
<blockquote> | ||
<hr /> | ||
<para>[]</para> | ||
</blockquote> | ||
</blockquote> | ||
</doc>, | ||
); | ||
}); | ||
it('type --- inisde a paragraph with more text', () => { | ||
const { view } = testEditor( | ||
<doc> | ||
<para>[]abc</para> | ||
</doc>, | ||
); | ||
typeText(view, '---'); | ||
expect(view.state).toEqualDocAndSelection( | ||
<doc> | ||
<hr /> | ||
<para>[]abc</para> | ||
</doc>, | ||
); | ||
}); | ||
}); |
@@ -43,6 +43,27 @@ import { safeInsert } from '../utils/pm-utils'; | ||
let tr = state.tr.replaceWith(start - 1, end, type.createChecked()); | ||
return safeInsert( | ||
state.schema.nodes.paragraph.createChecked(), | ||
tr.selection.end, | ||
)(tr); | ||
// Find the paragraph that contains the "---" shortcut text, we need | ||
// it below for deciding whether to insert a new paragraph after the | ||
// hr. | ||
const $para = state.doc.resolve(start); | ||
let insertParaAfter = false; | ||
if ($para.end() != end) { | ||
// if the paragraph has more characters, e.g. "---abc", then no | ||
// need to insert a new paragraph | ||
insertParaAfter = false; | ||
} else if ($para.after() == $para.end(-1)) { | ||
// if the paragraph is the last child of its parent, then insert a | ||
// new paragraph | ||
insertParaAfter = true; | ||
} else { | ||
const nextNode = state.doc.resolve($para.after()).nodeAfter; | ||
// if the next node is a hr, then insert a new paragraph | ||
insertParaAfter = nextNode.type === type; | ||
} | ||
return insertParaAfter | ||
? safeInsert( | ||
state.schema.nodes.paragraph.createChecked(), | ||
tr.mapping.map($para.after()), | ||
)(tr) | ||
: tr; | ||
}, | ||
@@ -49,0 +70,0 @@ ), |
{ | ||
"name": "@bangle.dev/core", | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"homepage": "https://bangle.dev", | ||
@@ -5,0 +5,0 @@ "authors": [ |
528552
19215