🚸(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.
This commit is contained in:
Anthony LC
2026-01-06 10:26:56 +01:00
parent 9893558c74
commit bb0502b49b
2 changed files with 14 additions and 0 deletions

View File

@@ -394,6 +394,8 @@ test.describe('Doc Comments mobile', () => {
await thread.getByRole('paragraph').first().fill('This is a comment');
await thread.locator('[data-test="save"]').click();
await expect(thread.getByText('This is a comment').first()).toBeHidden();
// Check toolbar is closed after adding a comment
await expect(page.getByRole('button', { name: 'Paragraph' })).toBeHidden();
await editor.first().click();
await editor.getByText('Hello').click();

View File

@@ -212,6 +212,17 @@ export class DocsThreadStore extends ThreadStore {
.setMark?.('comment', { orphan: false, threadId })
.run?.();
/**
* We have some issues with mobiles and the formatting toolbar reopening
* after adding a comment, so we restore the cursor position here.
* By restoring the cursor position at the head of the selection,
* it will automatically close the formatting toolbar.
*/
const cursorPos = editor._tiptapEditor?.state.selection.head;
if (cursorPos !== undefined) {
editor._tiptapEditor?.commands.setTextSelection(cursorPos);
}
return Promise.resolve();
};
@@ -241,6 +252,7 @@ export class DocsThreadStore extends ThreadStore {
this.upsertClientThreadData(threadData);
this.notifySubscribers();
this.ping(threadData.id);
return threadData;
};