🚸(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:
@@ -394,6 +394,8 @@ test.describe('Doc Comments mobile', () => {
|
|||||||
await thread.getByRole('paragraph').first().fill('This is a comment');
|
await thread.getByRole('paragraph').first().fill('This is a comment');
|
||||||
await thread.locator('[data-test="save"]').click();
|
await thread.locator('[data-test="save"]').click();
|
||||||
await expect(thread.getByText('This is a comment').first()).toBeHidden();
|
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.first().click();
|
||||||
await editor.getByText('Hello').click();
|
await editor.getByText('Hello').click();
|
||||||
|
|||||||
@@ -212,6 +212,17 @@ export class DocsThreadStore extends ThreadStore {
|
|||||||
.setMark?.('comment', { orphan: false, threadId })
|
.setMark?.('comment', { orphan: false, threadId })
|
||||||
.run?.();
|
.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();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -241,6 +252,7 @@ export class DocsThreadStore extends ThreadStore {
|
|||||||
this.upsertClientThreadData(threadData);
|
this.upsertClientThreadData(threadData);
|
||||||
this.notifySubscribers();
|
this.notifySubscribers();
|
||||||
this.ping(threadData.id);
|
this.ping(threadData.id);
|
||||||
|
|
||||||
return threadData;
|
return threadData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user