From db6c85d60bdcad2f6837111713c343b5c85122e8 Mon Sep 17 00:00:00 2001 From: ZhurmilovVadim Date: Fri, 17 May 2024 12:49:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BA=D1=83=D1=80=D1=81=D0=BE=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/src/components/Editor/Editor.ts | 12 ++++++------ public/src/components/Editor/Plugin.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/public/src/components/Editor/Editor.ts b/public/src/components/Editor/Editor.ts index 1d4cf31f..65bb7372 100644 --- a/public/src/components/Editor/Editor.ts +++ b/public/src/components/Editor/Editor.ts @@ -82,8 +82,8 @@ export class Editor { } const scanTree = (node: HTMLElement) => { - if (`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id.toString()}` in node.dataset) { - delete node.dataset[`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id.toString()}`]; + if (`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id?.toString()}` in node.dataset) { + delete node.dataset[`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id?.toString()}`]; } node.childNodes.forEach(child => { @@ -108,7 +108,7 @@ export class Editor { scanTree(this.editable); - elem.dataset[`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id.toString()}`] = `${getCaretPosition(elem)}`; + elem.dataset[`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id?.toString()}`] = `${getCaretPosition(elem)}`; // TODO: отоброажать курсоры пользователей при редактировании одной заметки // const fakeCaret = document.createElement("div") @@ -184,7 +184,7 @@ export class Editor { subtree: true }); - + // Заметка открыта с пк и с телефона. Редачится с телефона. С пк курсор начинает скакать // Возможное решение: сохранять в дата атрибуты помимо username еще и socket_id чтобы различать девайс с которого редачится заметка @@ -212,7 +212,7 @@ export class Editor { }); if ((parentPlugin.pluginName === 'div' || parentPlugin.pluginName === 'li' || parentPlugin.pluginName === 'li-todo') && node.textContent.startsWith('/') && - `cursor${AppUserStore.state.username}-${AppNotesStore.socket_id.toString()}` in node.parentElement.dataset) { + `cursor${AppUserStore.state.username}-${AppNotesStore.socket_id?.toString()}` in node.parentElement.dataset) { lastChosenElement.node = node; this.dropdownCallbacks.open(node.parentElement) } else { @@ -224,7 +224,7 @@ export class Editor { return plugin.pluginName === 'div'; })); defaultPlugins[divIndex].onInsert = (node: Node) => { - if (node.textContent.startsWith('/') && `cursor${AppUserStore.state.username}-${AppNotesStore.socket_id.toString()}` in node.parentElement.dataset) { + if (node.textContent.startsWith('/') && `cursor${AppUserStore.state.username}-${AppNotesStore.socket_id?.toString()}` in node.parentElement.dataset) { lastChosenElement.node = node; this.dropdownCallbacks.open(node as HTMLElement) } diff --git a/public/src/components/Editor/Plugin.ts b/public/src/components/Editor/Plugin.ts index 1c2b607a..e9dd868e 100644 --- a/public/src/components/Editor/Plugin.ts +++ b/public/src/components/Editor/Plugin.ts @@ -846,12 +846,12 @@ export const fromJson = (props: PluginProps) => { } } - if (`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id.toString()}` in props) { + if (`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id?.toString()}` in props) { // const regex = /([a-zA]+)-([\d]+)/; // const matches = regex.exec(props.cursor as string); - if (props[`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id.toString()}`] === '0') { + if (props[`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id?.toString()}`] === '0') { setTimeout(() => { setCursorAtNodePosition(node, 0); // (node as HTMLElement).click(); @@ -860,7 +860,7 @@ export const fromJson = (props: PluginProps) => { } else { setTimeout(() => { - setCursorAtNodePosition(node, Number(props[`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id.toString()}`])); + setCursorAtNodePosition(node, Number(props[`cursor${AppUserStore.state.username}-${AppNotesStore.socket_id?.toString()}`])); // (node as HTMLElement).click(); // document.getSelection().setPosition(node.firstChild, Number(props[`cursor${AppUserStore.state.username}`])); })