-
Notifications
You must be signed in to change notification settings - Fork 132
fix: allow paste from context menu #1910
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ee04e06
fix: allow paste from context menu
VladaHarbour 07ef1be
fix: additional check
VladaHarbour 5738287
Merge branch 'main' into sd-1302_paste-menu-item
harbournick 94ecfc6
fix: optimise clipboard utils
VladaHarbour af22b10
Merge branch 'main' into sd-1302_paste-menu-item
harbournick 84ea1ff
fix(super-editor): preserve native paste pipeline and add clipboard r…
harbournick 04dfb78
Merge branch 'main' into sd-1302_paste-menu-item
harbournick 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
devtools/visual-testing/tests/interactions/stories/basic-commands/slash-menu-paste.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,83 @@ | ||
| import { defineStory } from '@superdoc-testing/helpers'; | ||
| import { clickOnLine } from '../../helpers/index.js'; | ||
|
|
||
| const WAIT_MS = 300; | ||
| const WAIT_LONG_MS = 600; | ||
|
|
||
| export default defineStory({ | ||
| name: 'slash-menu-paste', | ||
| description: 'Verify the slash menu shows a Paste action and that pasting formatted HTML preserves formatting.', | ||
| tickets: ['SD-1302'], | ||
| startDocument: null, | ||
| hideCaret: true, | ||
|
|
||
| async run(page, helpers): Promise<void> { | ||
| const { step, type, newLine, press, waitForStable, milestone } = helpers; | ||
|
|
||
| await step('Type a normal line', async () => { | ||
| await type('Normal line'); | ||
| await newLine(); | ||
| await waitForStable(WAIT_MS); | ||
| await milestone('before-paste', 'One line typed, cursor on second line.'); | ||
| }); | ||
|
|
||
| await step('Open slash menu via right-click to show Paste option', async () => { | ||
| const lines = page.locator('.superdoc-line'); | ||
| const lastLine = lines.last(); | ||
| const box = await lastLine.boundingBox(); | ||
| if (!box) throw new Error('Last line not visible'); | ||
|
|
||
| await page.mouse.click(box.x + 20, box.y + box.height / 2, { button: 'right' }); | ||
| await waitForStable(WAIT_MS); | ||
|
|
||
| const menu = page.locator('.slash-menu'); | ||
| await menu.waitFor({ state: 'visible', timeout: 5000 }); | ||
| await waitForStable(WAIT_MS); | ||
|
|
||
| await milestone('slash-menu-open', 'Slash menu visible with Paste action.'); | ||
| }); | ||
|
|
||
| await step('Dismiss menu and paste bold HTML via editor API', async () => { | ||
| await press('Escape'); | ||
| await waitForStable(WAIT_MS); | ||
|
|
||
| // Reposition cursor on line 2 (lost when slash menu closed) | ||
| await clickOnLine(page, 1); | ||
| await waitForStable(WAIT_MS); | ||
|
|
||
| // Paste formatted HTML directly via ProseMirror's pasteHTML API. | ||
| // This exercises the same rendering path as the slash menu paste action | ||
| // without depending on browser clipboard permissions. | ||
| // A clipboard event shim is required — pasteHTML internally accesses | ||
| // event.clipboardData.getData(). | ||
| await page.evaluate( | ||
| `(function() { | ||
| var view = window.editor && window.editor.view; | ||
| if (!view) return; | ||
| var html = '<b>Bold pasted text</b>'; | ||
| var text = 'Bold pasted text'; | ||
| var fakeEvent = { | ||
| type: 'paste', | ||
| preventDefault: function() {}, | ||
| stopPropagation: function() {}, | ||
| clipboardData: { | ||
| getData: function(type) { | ||
| if (type === 'text/html') return html; | ||
| if (type === 'text/plain') return text; | ||
| return ''; | ||
| } | ||
| } | ||
| }; | ||
| if (typeof view.pasteHTML === 'function') { | ||
| view.pasteHTML(html, fakeEvent); | ||
| } else if (window.editor.commands && window.editor.commands.insertContent) { | ||
| window.editor.commands.insertContent(html); | ||
| } | ||
| })()`, | ||
| ); | ||
|
|
||
| await waitForStable(WAIT_LONG_MS); | ||
| await milestone('after-paste', 'Bold text pasted on line 2 — formatting should be preserved.'); | ||
| }); | ||
| }, | ||
| }); |
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
Oops, something went wrong.
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.