-
Notifications
You must be signed in to change notification settings - Fork 119
fix: allow caret placement inside commented text on click (SD-2442) #2708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
caio-pizzol
merged 5 commits into
main
from
luccas/sd-2442-bug-cursor-cannot-be-placed-in-text-associated-with-a
Apr 9, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
431b939
test: add regression coverage for caret placement inside commented text
luccas-harbour d15e048
fix: allow caret placement on direct comment highlight clicks
luccas-harbour d5ae180
refactor: simplify click coordinate math in test helpers
caio-pizzol 8bf0625
fix: use elementFromPoint fallback in comment click-outside handler
caio-pizzol 460c8cd
test: add coverage for comment activation and click-outside fallback
caio-pizzol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
tests/behavior/tests/comments/sd-2442-commented-text-caret.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { test, expect } from '../../fixtures/superdoc.js'; | ||
| import { addCommentViaUI } from '../../helpers/comments.js'; | ||
| import { clickAtDocPos } from '../../helpers/editor-interactions.js'; | ||
|
|
||
| test.use({ config: { toolbar: 'full', comments: 'on' } }); | ||
|
|
||
| test('SD-2442: clicking inside commented text places a caret and allows typing', async ({ superdoc }) => { | ||
| await superdoc.type('alpha beta gamma'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| await addCommentViaUI(superdoc, { | ||
| textToSelect: 'beta gamma', | ||
| commentText: 'outer comment', | ||
| }); | ||
|
|
||
| await superdoc.assertCommentHighlightExists({ text: 'beta gamma' }); | ||
|
|
||
| const betaStart = await superdoc.findTextPos('beta'); | ||
| const insertionPos = betaStart + 2; | ||
|
|
||
| await superdoc.clickOnLine(0, 5); | ||
| await superdoc.waitForStable(); | ||
| await expect((await superdoc.getSelection()).from).not.toBe(insertionPos); | ||
|
|
||
| await clickAtDocPos(superdoc.page, insertionPos); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| await superdoc.assertSelection(insertionPos); | ||
|
|
||
| await superdoc.page.keyboard.type('X'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| await expect.poll(() => superdoc.getTextContent()).toContain('alpha beXta gamma'); | ||
| }); | ||
|
|
||
| test('SD-2442: clicking inside commented text activates the comment bubble', async ({ superdoc }) => { | ||
| await superdoc.type('hello world'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| await addCommentViaUI(superdoc, { | ||
| textToSelect: 'world', | ||
| commentText: 'bubble test', | ||
| }); | ||
|
|
||
| await superdoc.assertCommentHighlightExists({ text: 'world' }); | ||
|
|
||
| // Click outside the comment to deselect it first | ||
| await superdoc.clickOnLine(0, 0); | ||
| await superdoc.waitForStable(); | ||
| await expect(superdoc.page.locator('.comments-dialog.is-active')).toHaveCount(0, { timeout: 3000 }); | ||
|
|
||
| // Click inside the commented text | ||
| const worldPos = await superdoc.findTextPos('world'); | ||
| await clickAtDocPos(superdoc.page, worldPos + 2); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| // The comment bubble should be active and stay active | ||
| await expect(superdoc.page.locator('.comments-dialog.is-active')).toBeVisible({ timeout: 5000 }); | ||
| await expect(superdoc.page.locator('.comments-dialog.is-active')).toContainText('bubble test'); | ||
| }); | ||
|
|
||
| test('SD-2442: double-clicking inside commented text selects a word', async ({ superdoc }) => { | ||
| await superdoc.type('select this word'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| await addCommentViaUI(superdoc, { | ||
| textToSelect: 'this word', | ||
| commentText: 'dblclick test', | ||
| }); | ||
|
|
||
| await superdoc.assertCommentHighlightExists({ text: 'this word' }); | ||
|
|
||
| // Click outside first | ||
| await superdoc.clickOnLine(0, 0); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| // Double-click on "word" inside the comment highlight | ||
| const wordPos = await superdoc.findTextPos('word'); | ||
| const coords = await superdoc.page.evaluate((pos) => { | ||
| const editor = (window as any).editor; | ||
| const rect = editor?.coordsAtPos?.(pos); | ||
| if (!rect) return null; | ||
| return { left: Number(rect.left), right: Number(rect.right), top: Number(rect.top), bottom: Number(rect.bottom) }; | ||
| }, wordPos); | ||
|
|
||
| if (coords) { | ||
| const x = coords.left + 5; | ||
| const y = (coords.top + coords.bottom) / 2; | ||
| await superdoc.page.mouse.dblclick(x, y); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| const sel = await superdoc.getSelection(); | ||
| const selectedText = await superdoc.page.evaluate( | ||
| ({ from, to }) => { | ||
| const editor = (window as any).editor; | ||
| return editor.state.doc.textBetween(from, to); | ||
| }, | ||
| { from: sel.from, to: sel.to }, | ||
| ); | ||
| expect(selectedText).toBe('word'); | ||
| } | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.