Skip to content

Commit f972ed4

Browse files
committed
fix: the tooltip of TableOfContent
1 parent 9d3c3a8 commit f972ed4

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

src/extensions/TableOfContent/TableOfContent.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import { findNode, isTitleNode } from '@/utils/node';
99
declare module '@tiptap/core' {
1010
interface Commands<ReturnType> {
1111
tableOfContents: {
12-
setTableOfContents: () => ReturnType
13-
removeTableOfContents: () => ReturnType
14-
}
12+
setTableOfContents: () => ReturnType;
13+
removeTableOfContents: () => ReturnType;
14+
};
1515
}
1616
}
1717

1818
interface Options {
19-
onHasOneBeforeInsert?: () => void
19+
onHasOneBeforeInsert?: () => void;
2020
}
2121

2222
export const TableOfContents = /* @__PURE__ */ Node.create<Options>({
@@ -38,7 +38,7 @@ export const TableOfContents = /* @__PURE__ */ Node.create<Options>({
3838
componentProps: {
3939
disabled: false,
4040
icon: 'BookMarked',
41-
tooltip: t('editor.table.tooltip'),
41+
tooltip: t('editor.table_of_content'),
4242
editor,
4343
},
4444
}),
@@ -70,42 +70,45 @@ export const TableOfContents = /* @__PURE__ */ Node.create<Options>({
7070
const nodes = findNode(editor, this.name);
7171

7272
if (nodes.length > 0) {
73-
// @ts-expect-error
73+
// @ts-expect-error
7474
this.options.onHasOneBeforeInsert();
7575
return;
7676
}
7777

7878
const titleNode = view.props.state.doc.content.firstChild as any;
7979

8080
if (isTitleNode(titleNode)) {
81-
const pos = ((titleNode.firstChild && titleNode.firstChild.nodeSize) || 0) + 1;
81+
const pos =
82+
((titleNode.firstChild && titleNode.firstChild.nodeSize) || 0) +
83+
1;
8284
return commands.insertContentAt(pos, { type: this.name });
8385
}
8486

8587
return commands.insertContent({
8688
type: this.name,
8789
});
8890
},
89-
removeTableOfContents: () =>
90-
({ state, dispatch }: any) => {
91-
const { tr } = state;
92-
const nodeType = state.schema.nodes.tableOfContents;
93-
94-
state.doc.descendants((node: any, pos: any) => {
95-
if (node.type === nodeType) {
96-
const from = pos;
97-
const to = pos + node.nodeSize;
98-
tr.delete(from, to);
99-
}
100-
});
91+
removeTableOfContents:
92+
() =>
93+
({ state, dispatch }: any) => {
94+
const { tr } = state;
95+
const nodeType = state.schema.nodes.tableOfContents;
96+
97+
state.doc.descendants((node: any, pos: any) => {
98+
if (node.type === nodeType) {
99+
const from = pos;
100+
const to = pos + node.nodeSize;
101+
tr.delete(from, to);
102+
}
103+
});
101104

102-
if (tr.docChanged) {
103-
dispatch(tr);
104-
return true;
105-
}
105+
if (tr.docChanged) {
106+
dispatch(tr);
107+
return true;
108+
}
106109

107-
return false;
108-
},
110+
return false;
111+
},
109112
};
110113
},
111114

0 commit comments

Comments
 (0)