From deac4e467999250a6451fa302a3ce64123a23747 Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 1 Feb 2024 12:54:02 +0900 Subject: [PATCH 1/3] Add presence `watched` event filtering --- frontend/src/components/headers/DocumentHeader.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/headers/DocumentHeader.tsx b/frontend/src/components/headers/DocumentHeader.tsx index 1cd81722..24a4924b 100644 --- a/frontend/src/components/headers/DocumentHeader.tsx +++ b/frontend/src/components/headers/DocumentHeader.tsx @@ -54,7 +54,10 @@ function DocumentHeader() { setPresenceList(editorState.doc.getPresences()); const unsubscribe = editorState.doc.subscribe("others", (event) => { - if (event.type === "watched") { + if ( + event.type === "watched" && + presenceList.every((presence) => presence.clientID !== event.value.clientID) + ) { pushToPresenceList(event.value); } From 8d79cebd0cc13fc8c0a373c945f75ca35df9d473 Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 1 Feb 2024 12:59:03 +0900 Subject: [PATCH 2/3] Change remote selection change logic --- frontend/package-lock.json | 13 +++++++++++++ frontend/package.json | 2 ++ frontend/src/utils/yorkie/remoteSelection.ts | 10 +++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 7f0dd7a6..22771ef8 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -32,6 +32,7 @@ "codemirror-toolbar": "^0.0.3", "color": "^4.2.3", "lib0": "^0.2.88", + "lodash": "^4.17.21", "moment": "^2.30.1", "notistack": "^2.0.8", "randomcolor": "^0.6.2", @@ -50,6 +51,7 @@ }, "devDependencies": { "@types/color": "^3.0.6", + "@types/lodash": "^4.14.202", "@types/randomcolor": "^0.5.9", "@types/react": "^18.2.43", "@types/react-dom": "^18.2.17", @@ -2122,6 +2124,12 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true }, + "node_modules/@types/lodash": { + "version": "4.14.202", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.202.tgz", + "integrity": "sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==", + "dev": true + }, "node_modules/@types/long": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz", @@ -4572,6 +4580,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", diff --git a/frontend/package.json b/frontend/package.json index c7a9668b..85b002c1 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -36,6 +36,7 @@ "codemirror-toolbar": "^0.0.3", "color": "^4.2.3", "lib0": "^0.2.88", + "lodash": "^4.17.21", "moment": "^2.30.1", "notistack": "^2.0.8", "randomcolor": "^0.6.2", @@ -54,6 +55,7 @@ }, "devDependencies": { "@types/color": "^3.0.6", + "@types/lodash": "^4.14.202", "@types/randomcolor": "^0.5.9", "@types/react": "^18.2.43", "@types/react-dom": "^18.2.17", diff --git a/frontend/src/utils/yorkie/remoteSelection.ts b/frontend/src/utils/yorkie/remoteSelection.ts index 553c0b78..b4e62cbd 100644 --- a/frontend/src/utils/yorkie/remoteSelection.ts +++ b/frontend/src/utils/yorkie/remoteSelection.ts @@ -11,6 +11,7 @@ import { YorkieCodeMirrorPresenceType, yorkieSyncFacet, } from "./yorkieSync.js"; +import _ from "lodash"; export const yorkieRemoteSelectionsTheme = cmView.EditorView.baseTheme({ ".cm-ySelection": {}, @@ -150,9 +151,12 @@ export class YorkieRemoteSelectionsPluginValue { if (sel && root.content) { const selection = root.content.indexRangeToPosRange([sel.anchor, sel.head]); - presence.set({ - selection, - }); + + if (!_.isEqual(selection, presence.get("selection"))) { + presence.set({ + selection, + }); + } } else if (presence.get("selection")) { presence.set({ selection: null, From 70c1e8e986b304e41c86b68ca29cb0d0888f5730 Mon Sep 17 00:00:00 2001 From: devleejb Date: Thu, 1 Feb 2024 13:02:37 +0900 Subject: [PATCH 3/3] Fix Lint --- frontend/src/components/headers/DocumentHeader.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frontend/src/components/headers/DocumentHeader.tsx b/frontend/src/components/headers/DocumentHeader.tsx index 24a4924b..1cd81722 100644 --- a/frontend/src/components/headers/DocumentHeader.tsx +++ b/frontend/src/components/headers/DocumentHeader.tsx @@ -54,10 +54,7 @@ function DocumentHeader() { setPresenceList(editorState.doc.getPresences()); const unsubscribe = editorState.doc.subscribe("others", (event) => { - if ( - event.type === "watched" && - presenceList.every((presence) => presence.clientID !== event.value.clientID) - ) { + if (event.type === "watched") { pushToPresenceList(event.value); }