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 f676ce7 commit f449263
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 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 @@ -81,7 +83,7 @@ export class Editor {

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

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()}`] = `${getCaretPosition(elem)}`;

// TODO: отоброажать курсоры пользователей при редактировании одной заметки
// const fakeCaret = document.createElement("div")
Expand Down Expand Up @@ -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()}` 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()}` in node.parentElement.dataset) {
lastChosenElement.node = node;
this.dropdownCallbacks.open(node as HTMLElement)
}
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 f449263

Please sign in to comment.