Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions playwright/e2e/footnotes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ test('inserts footnote via keyboard shortcut', async ({ editor, open }) => {
await expect(editor.getFootnote('1')).toContainText('footnote')
})

test('inserts footnote via [^label] input rule', async ({ editor, open }) => {
test('inserts footnote via [^] input rule', async ({ editor, open }) => {
await open()
await editor.type('hello[^bar]')
await expect(editor.getFootnoteReference('bar')).toBeVisible()
await expect(editor.getFootnote('bar')).toBeVisible()
await editor.type('hello[^]')
await expect(editor.getFootnoteReference('1')).toBeVisible()
await expect(editor.getFootnote('1')).toBeVisible()
})
2 changes: 1 addition & 1 deletion src/components/HelpModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
<tr>
<td>{{ t('text', 'Footnote') }}</td>
<td>
<code>[^{{ t('text', 'label') }}]</code>
<code>[^]</code>
</td>
<td v-if="!isMobileCached">
<kbd>{{ ctrlOrModKey }}</kbd>
Expand Down
8 changes: 3 additions & 5 deletions src/nodes/FootnoteReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,15 @@ const FootnoteReference = Node.create({
addInputRules() {
return [
new InputRule({
find: /\[\^([^\]\s]+)\]$/,
handler: ({ state, range, match, chain }) => {
const referenceId = match[1] ?? ''

find: /\[\^\]$/,
handler: ({ state, range, chain }) => {
if (isInsideFootnote(state)) {
return null
}

chain()
.deleteRange({ from: range.from, to: range.to })
.insertFootnote({ referenceId })
.insertFootnote()
.run()
},
}),
Expand Down
11 changes: 11 additions & 0 deletions src/nodes/Footnotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ const Footnotes = Node.create({
return null
}

let hasFootnotes = false
for (let i = 0; i < newState.doc.childCount; i++) {
if (newState.doc.child(i).type.name === 'footnotes') {
hasFootnotes = true
break
}
}
if (!hasFootnotes) {
return null
}

const referencedLabels = new Set<string>()
newState.doc.descendants((node) => {
if (node.type.name === 'footnoteReference') {
Expand Down
Loading