mirror of https://github.com/fantasticit/think.git
tiptap: fix lock node
This commit is contained in:
parent
c65a519945
commit
a9eefd3c37
|
@ -6,11 +6,11 @@ type CollaborationCursorStorage = {
|
|||
users: { clientId: number; [key: string]: any }[];
|
||||
};
|
||||
|
||||
export function findNodeAt(state: EditorState, from, to) {
|
||||
export function findNodeAt(editor, state: EditorState, from, to) {
|
||||
let target = null;
|
||||
let pos = -1;
|
||||
|
||||
if (state && state.doc) {
|
||||
if (editor && !editor.isDestroyed) {
|
||||
state.doc.nodesBetween(from, to, (node, p) => {
|
||||
target = node;
|
||||
pos = p;
|
||||
|
@ -61,6 +61,10 @@ const awarenessStatesToArray = (states: Map<number, Record<string, any>>) => {
|
|||
const lockCollaborationUserEditingNodes = (extensionThis, users) => {
|
||||
const { editor, options } = extensionThis;
|
||||
|
||||
if (!editor || editor.isDestroyed) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (options.lockedDOMNodes.length) {
|
||||
const dom = options.lockedDOMNodes.shift();
|
||||
dom && dom.classList && dom.classList.remove(options.lockClassName);
|
||||
|
@ -82,9 +86,10 @@ const lockCollaborationUserEditingNodes = (extensionThis, users) => {
|
|||
users.forEach((user) => {
|
||||
if (user.name === options.user.name) return;
|
||||
|
||||
try {
|
||||
const cursor = user.cursor;
|
||||
if (cursor) {
|
||||
const { node, pos } = findNodeAt(editor.state, cursor.originAnchor, cursor.originHead);
|
||||
const { node, pos } = findNodeAt(editor, editor.state, cursor.originAnchor, cursor.originHead);
|
||||
|
||||
if (node && node.isAtom) {
|
||||
const dom = editor.view.nodeDOM(pos) as HTMLElement;
|
||||
|
@ -96,6 +101,7 @@ const lockCollaborationUserEditingNodes = (extensionThis, users) => {
|
|||
options.collaborationUserCursorCache.set(user.clientId, { user, cursor });
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue