-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat: add copy button to action step header, improve other copy buttons #37744
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 5 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
1a2fc5f
feat(actions): add copy button to action step header
silverwind 2bdfde1
revert markdown indented code-block wrapper
silverwind 2892fe1
fix(actions): skip endgroup lines when copying collapsed step
silverwind f1276ae
Merge branch 'main' into copy-step-output
silverwind e1d5634
Merge branch 'main' into copy-step-output
silverwind 8ac230a
refactor: polish step copy button and clipboard helper
silverwind 14d5e47
refactor(actions): restore original cursor and timestamp comments
silverwind 82709c2
refactor(clipboard): consolidate copy helpers into modules/clipboard.ts
silverwind d3a3a9f
Apply suggestion from @silverwind
silverwind 1fee2c5
refactor(clipboard): move initCopyContent back to features/copyconten…
silverwind 7f37d14
fix(clipboard): drop empty-content check, always copy and show feedback
silverwind a5a1250
fix(time): truncate fractional seconds instead of rounding
silverwind 2cf17f8
fix(clipboard): restore tooltip feedback for icon-less copy triggers
silverwind 4d296b3
clarify
wxiaoguang 50c04bf
use async sleep
wxiaoguang 66eaedc
add more comment for "cursor" type
wxiaoguang b150b3f
remove useless null check
wxiaoguang 6404d38
remove unnecessary data-clipboard-text-type="url"
wxiaoguang 90de798
copyContentToClipboard
wxiaoguang 7888702
avoid duplicate querySelector('.octicon-copy')
wxiaoguang 0324cdc
Merge branch 'main' into copy-step-output
bircni a9211be
formatDatetime: resolve hourCycle like relative-time
silverwind 4e4306b
rename copy functions so feedback is explicit in the name
silverwind e0f6086
Merge branch 'main' into copy-step-output
silverwind 9803db1
Merge remote-tracking branch 'origin/main' into copy-step-output
silverwind 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,25 @@ | ||
| import {clippie} from 'clippie'; | ||
| import {showTemporaryTooltip} from '../modules/tippy.ts'; | ||
| import {copyToClipboard} from './clipboard.ts'; | ||
| import {convertImage} from '../utils.ts'; | ||
| import {GET} from '../modules/fetch.ts'; | ||
| import {registerGlobalEventFunc} from '../modules/observer.ts'; | ||
|
|
||
| const {i18n} = window.config; | ||
|
|
||
| export function initCopyContent() { | ||
| registerGlobalEventFunc('click', 'onCopyContentButtonClick', async (btn: HTMLElement) => { | ||
| if (btn.classList.contains('disabled') || btn.classList.contains('is-loading')) return; | ||
| const rawFileLink = btn.getAttribute('data-raw-file-link'); | ||
|
|
||
| let content, isRasterImage = false; | ||
|
|
||
| // when "data-raw-link" is present, we perform a fetch. this is either because | ||
| // the text to copy is not in the DOM, or it is an image that should be | ||
| // fetched to copy in full resolution | ||
| if (rawFileLink) { | ||
| btn.classList.add('is-loading', 'loading-icon-2px'); | ||
| try { | ||
| const res = await GET(rawFileLink, {credentials: 'include', redirect: 'follow'}); | ||
| const contentType = res.headers.get('content-type')!; | ||
|
|
||
| if (contentType.startsWith('image/') && !contentType.startsWith('image/svg')) { | ||
| isRasterImage = true; | ||
| content = await res.blob(); | ||
| } else { | ||
| content = await res.text(); | ||
| } | ||
| } catch { | ||
| return showTemporaryTooltip(btn, i18n.copy_error); | ||
| } finally { | ||
| btn.classList.remove('is-loading', 'loading-icon-2px'); | ||
| await copyToClipboard(btn, async () => { | ||
| const rawFileLink = btn.getAttribute('data-raw-file-link'); | ||
| if (!rawFileLink) { | ||
| const lineEls = document.querySelectorAll('.file-view .lines-code'); | ||
| return Array.from(lineEls, (el) => el.textContent).join(''); | ||
| } | ||
| } else { // text, read from DOM | ||
| const lineEls = document.querySelectorAll('.file-view .lines-code'); | ||
| content = Array.from(lineEls, (el) => el.textContent).join(''); | ||
| } | ||
|
|
||
| // try copy original first, if that fails, and it's an image, convert it to png | ||
| const success = await clippie(content); | ||
| if (success) { | ||
| showTemporaryTooltip(btn, i18n.copy_success); | ||
| } else { | ||
| if (isRasterImage) { | ||
| const success = await clippie(await convertImage(content as Blob, 'image/png')); | ||
| showTemporaryTooltip(btn, success ? i18n.copy_success : i18n.copy_error); | ||
| } else { | ||
| showTemporaryTooltip(btn, i18n.copy_error); | ||
| const res = await GET(rawFileLink, {credentials: 'include', redirect: 'follow'}); | ||
| const contentType = res.headers.get('content-type')!; | ||
| if (contentType.startsWith('image/') && !contentType.startsWith('image/svg')) { | ||
| // browsers only accept image/png in the clipboard, convert other raster formats | ||
| const blob = await res.blob(); | ||
| return contentType === 'image/png' ? blob : convertImage(blob, 'image/png'); | ||
| } | ||
| } | ||
| return await res.text(); | ||
| }); | ||
| }); | ||
| } |
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.
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.