Skip to content

Commit fc2f14b

Browse files
committed
🐛(frontend) link not clickable and flickering firefox
The link in the read mode was not clickable anymore, it was due to a attempt to not display the cursor of anonymous users. We changes the way to do it by rendering our own cursor, when a user is anonymous we don't render the cursor. By rendering our own cursor we fixed another problem, the cursor was flickering when the user was typing at the end of the line on the firefox browser.
1 parent 6dd1697 commit fc2f14b

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to
99

1010
## [Unreleased]
1111

12+
## Fixed
13+
14+
🐛(frontend) link not clickable and flickering firefox #457
15+
1216

1317
## [1.8.0] - 2024-11-25
1418

src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,8 @@ const cssEditor = (readonly: boolean) => `
2424
};
2525
& .bn-editor {
2626
padding-right: 30px;
27-
${
28-
readonly &&
29-
`
30-
padding-left: 30px;
31-
pointer-events: none;
32-
`
33-
}
27+
${readonly && `padding-left: 30px;`}
3428
};
35-
& .collaboration-cursor__caret.ProseMirror-widget{
36-
word-wrap: initial;
37-
}
3829
& .bn-inline-content code {
3930
background-color: gainsboro;
4031
padding: 2px;
@@ -94,20 +85,50 @@ export const BlockNoteEditor = ({
9485

9586
const { uploadFile, errorAttachment } = useUploadFile(doc.id);
9687

88+
const collabName =
89+
userData?.full_name ||
90+
userData?.email ||
91+
(readOnly ? 'Reader' : t('Anonymous'));
92+
9793
const editor = useCreateBlockNote(
9894
{
9995
collaboration: {
10096
provider,
10197
fragment: provider.document.getXmlFragment('document-store'),
10298
user: {
103-
name: userData?.full_name || userData?.email || t('Anonymous'),
99+
name: collabName,
104100
color: randomColor(),
105101
},
102+
/**
103+
* We re-use the blocknote code to render the cursor but we:
104+
* - fix rendering issue with Firefox
105+
* - We don't want to show the cursor when anonymous users
106+
*/
107+
renderCursor: (user: { color: string; name: string }) => {
108+
const cursor = document.createElement('span');
109+
110+
if (user.name === 'Reader') {
111+
return cursor;
112+
}
113+
114+
cursor.classList.add('collaboration-cursor__caret');
115+
cursor.setAttribute('style', `border-color: ${user.color}`);
116+
117+
const label = document.createElement('span');
118+
119+
label.classList.add('collaboration-cursor__label');
120+
label.setAttribute('style', `background-color: ${user.color}`);
121+
label.insertBefore(document.createTextNode(user.name), null);
122+
123+
cursor.insertBefore(label, null);
124+
125+
return cursor;
126+
},
106127
},
107128
dictionary: locales[lang as keyof typeof locales] as Dictionary,
108129
uploadFile,
109130
},
110-
[lang, provider, uploadFile, userData?.email, userData?.full_name],
131+
[collabName, lang, provider, uploadFile],
111132
);
112133

113134
useEffect(() => {

0 commit comments

Comments
 (0)