Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions demo/collab/SelectionPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,11 @@ const getStateForNewUserSelection = (
)
);

const newClientIDs = oldState.clientIDs.add(selectionChange.clientID);

if (selectionChange.selection) {
const decorations = getDecosForSelection(
selectionChange.userName,
selectionChange.clientID,
selectionChange.selection,
newClientIDs
selectionChange.selection
);
newDecSet = newDecSet.add(doc, decorations);
}
Expand All @@ -148,25 +145,18 @@ const getStateForNewUserSelection = (
...oldState,
decorations: newDecSet,
selections: newSels,
clientIDs: newClientIDs,
};
};

const getDecosForSelection = (
userName: string,
clientID: ClientID,
{ head, from, to, empty }: Selection,
clientIDs: Set<ClientID>
{ head, from, to, empty }: Selection
): Decoration[] => {
const clientIDIndex = Array.from(clientIDs).indexOf(clientID);
if (clientIDIndex === -1) {
return [];
}

const cursorColor = selectColor(clientIDIndex);
const cursorColor = selectColor(parseInt(clientID));
const cursorDeco = getCursorDeco(head, clientID, userName, cursorColor);

const selectionColor = selectColor(clientIDIndex, true);
const selectionColor = selectColor(parseInt(clientID), true);
const selectionDeco = empty
? undefined
: getSelectionDeco(from, to, clientID, selectionColor);
Expand Down Expand Up @@ -220,7 +210,7 @@ const notEmpty = <TValue>(
return value !== null && value !== undefined;
};

const selectColor = (index: number, isBackground = false) => {
export const selectColor = (index: number, isBackground = false) => {
const hue = index * 137.508; // Use golden angle approximation
return `hsl(${hue},50%,${isBackground ? 90 : 50}%)`;
};
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</head>

<body>
<div id="content-container">
<div id="app">
<div id="button-container"><button id="content-data-toggle">Toggle data view</button></div>
<div id="content">
<div id="editor-container"></div>
Expand Down
Loading