Skip to content

Commit

Permalink
fix: Selection in collaboration
Browse files Browse the repository at this point in the history
  • Loading branch information
areknawo committed Oct 16, 2023
1 parent 0246b13 commit 6aa8a40
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions apps/web/src/lib/editor/extensions/collab-cursor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const CollabCursor = (provider: HocuspocusProvider): Extension => {
h: number;
w: number;
top: number;
display: string;
}>(null);

onMount(() => {
Expand All @@ -75,6 +76,7 @@ const CollabCursor = (provider: HocuspocusProvider): Extension => {
container.parentElement?.tagName === "BLOCKQUOTE"
) {
const rect = container.previousElementSibling?.getBoundingClientRect();
const isElement = container.previousElementSibling?.getAttribute("data-element");

let parentPos = document.getElementById("pm-container")?.getBoundingClientRect();

Expand All @@ -87,7 +89,11 @@ const CollabCursor = (provider: HocuspocusProvider): Extension => {
setBlockSelection({
h: rect.height,
w: rect.width,
top: rect.top - parentPos.top
display: isElement ? "none" : "block",
top:
rect.top -
parentPos.top -
parseFloat(window.getComputedStyle(container.previousElementSibling!).marginTop)
});
}
});
Expand Down Expand Up @@ -127,10 +133,11 @@ const CollabCursor = (provider: HocuspocusProvider): Extension => {
style={{
height: `${blockSelection.h}px`,
width: `${blockSelection.w}px`,
top: `${blockSelection.top}px`
top: `${blockSelection.top}px`,
display: blockSelection.display
}}
class={clsx(
"absolute border-2 rounded-2xl pointer-events-none",
"absolute border-2 rounded-[18px] pointer-events-none",
selectionClasses[color].outline
)}
>
Expand Down

0 comments on commit 6aa8a40

Please sign in to comment.