Skip to content

Commit

Permalink
поправил курсоры
Browse files Browse the repository at this point in the history
  • Loading branch information
veglem committed May 17, 2024
1 parent 73e7863 commit db6c85d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions public/src/components/Editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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")
Expand Down Expand Up @@ -184,7 +184,7 @@ export class Editor {
subtree: true
});



// Заметка открыта с пк и с телефона. Редачится с телефона. С пк курсор начинает скакать
// Возможное решение: сохранять в дата атрибуты помимо username еще и socket_id чтобы различать девайс с которого редачится заметка
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions public/src/components/Editor/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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}`]));
})
Expand Down

0 comments on commit db6c85d

Please sign in to comment.