Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/vls-65' into vls-65
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikMix committed May 17, 2024
2 parents d7a5f8b + 0e1d45a commit f1a99d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions public/src/components/Editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import {AppUserStore} from "../../modules/stores/UserStore";
import {getCaretPosition} from "../../modules/utils";
import {debounce} from "../../utils/debauncer";
import {AppNotesStore} from "../../modules/stores/NotesStore";
import {AppNoteStore} from "../../modules/stores/NoteStore";

export class Editor {
private readonly editable: HTMLElement;
Expand Down Expand Up @@ -80,8 +82,8 @@ export class Editor {
}

const scanTree = (node: HTMLElement) => {
if (`cursor${AppUserStore.state.username}` in node.dataset) {
delete node.dataset[`cursor${AppUserStore.state.username}`];
if (`cursor${AppUserStore.state.username}${AppNotesStore.socket_id?.toString().replace('-','')}` in node.dataset) {
delete node.dataset[`cursor${AppUserStore.state.username}${AppNotesStore.socket_id?.toString().replace('-','')}`];
}

node.childNodes.forEach(child => {
Expand All @@ -106,7 +108,7 @@ export class Editor {

scanTree(this.editable);

elem.dataset[`cursor${AppUserStore.state.username}`] = `${getCaretPosition(elem)}`;
elem.dataset[`cursor${AppUserStore.state.username}${AppNotesStore.socket_id?.toString().replace('-','')}`] = `${getCaretPosition(elem)}`;

// TODO: отоброажать курсоры пользователей при редактировании одной заметки
// const fakeCaret = document.createElement("div")
Expand Down Expand Up @@ -182,7 +184,7 @@ export class Editor {
subtree: true
});



// Заметка открыта с пк и с телефона. Редачится с телефона. С пк курсор начинает скакать
// Возможное решение: сохранять в дата атрибуты помимо username еще и socket_id чтобы различать девайс с которого редачится заметка
Expand All @@ -208,7 +210,9 @@ export class Editor {
const parentPlugin = defaultPlugins.find(plug => {
return plug.checkPlugin(node.parentElement);
});
if ((parentPlugin.pluginName === 'div' || parentPlugin.pluginName === 'li' || parentPlugin.pluginName === 'li-todo') && node.textContent.startsWith('/') && `cursor${AppUserStore.state.username}` in node.parentElement.dataset) {
if ((parentPlugin.pluginName === 'div' || parentPlugin.pluginName === 'li' || parentPlugin.pluginName === 'li-todo') &&
node.textContent.startsWith('/') &&
`cursor${AppUserStore.state.username}${AppNotesStore.socket_id?.toString().replace('-','')}` in node.parentElement.dataset) {
lastChosenElement.node = node;
this.dropdownCallbacks.open(node.parentElement)
} else {
Expand All @@ -220,7 +224,7 @@ export class Editor {
return plugin.pluginName === 'div';
}));
defaultPlugins[divIndex].onInsert = (node: Node) => {
if (node.textContent.startsWith('/') && `cursor${AppUserStore.state.username}` in node.parentElement.dataset) {
if (node.textContent.startsWith('/') && `cursor${AppUserStore.state.username}${AppNotesStore.socket_id?.toString().replace('-','')}` 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}` in props) {
if (`cursor${AppUserStore.state.username}${AppNotesStore.socket_id?.toString().replace('-','')}` in props) {
// const regex = /([a-zA]+)-([\d]+)/;
// const matches = regex.exec(props.cursor as string);


if (props[`cursor${AppUserStore.state.username}`] === '0') {
if (props[`cursor${AppUserStore.state.username}${AppNotesStore.socket_id?.toString().replace('-','')}`] === '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}`]));
setCursorAtNodePosition(node, Number(props[`cursor${AppUserStore.state.username}${AppNotesStore.socket_id?.toString().replace('-','')}`]));
// (node as HTMLElement).click();
// document.getSelection().setPosition(node.firstChild, Number(props[`cursor${AppUserStore.state.username}`]));
})
Expand Down
2 changes: 1 addition & 1 deletion public/src/modules/stores/NotesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NotesStore extends BaseStore<NotesStoreState> {
};

private ws
private socket_id
public socket_id

constructor() {
super();
Expand Down

0 comments on commit f1a99d0

Please sign in to comment.