Skip to content

Commit bb0502b

Browse files
committed
🚸(frontend) set cursor after create comments
We have some issues with mobiles and the formatting toolbar reopening after adding a comment, so we restore the cursor position. By restoring the cursor position at the head of the selection, it will automatically close the formatting toolbar.
1 parent 9893558 commit bb0502b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-comments.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ test.describe('Doc Comments mobile', () => {
394394
await thread.getByRole('paragraph').first().fill('This is a comment');
395395
await thread.locator('[data-test="save"]').click();
396396
await expect(thread.getByText('This is a comment').first()).toBeHidden();
397+
// Check toolbar is closed after adding a comment
398+
await expect(page.getByRole('button', { name: 'Paragraph' })).toBeHidden();
397399

398400
await editor.first().click();
399401
await editor.getByText('Hello').click();

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ export class DocsThreadStore extends ThreadStore {
212212
.setMark?.('comment', { orphan: false, threadId })
213213
.run?.();
214214

215+
/**
216+
* We have some issues with mobiles and the formatting toolbar reopening
217+
* after adding a comment, so we restore the cursor position here.
218+
* By restoring the cursor position at the head of the selection,
219+
* it will automatically close the formatting toolbar.
220+
*/
221+
const cursorPos = editor._tiptapEditor?.state.selection.head;
222+
if (cursorPos !== undefined) {
223+
editor._tiptapEditor?.commands.setTextSelection(cursorPos);
224+
}
225+
215226
return Promise.resolve();
216227
};
217228

@@ -241,6 +252,7 @@ export class DocsThreadStore extends ThreadStore {
241252
this.upsertClientThreadData(threadData);
242253
this.notifySubscribers();
243254
this.ping(threadData.id);
255+
244256
return threadData;
245257
};
246258

0 commit comments

Comments
 (0)