-
Notifications
You must be signed in to change notification settings - Fork 209
[UI] Fix copy button layout shift and add checkmark confirmation #1144
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
Rajesh-Nagarajan-11
merged 12 commits into
layer5io:master
from
akshatsinghai6682-sketch:fix-copy-button-shift
Jul 14, 2026
+97
−0
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
046b97b
[UI] Fix copy button shift on click and add checkmark confirmation
akshatsinghai6682-sketch 444b0c1
Update click-to-copy.js
akshatsinghai6682-sketch fc14ad0
Update click-to-copy.js
akshatsinghai6682-sketch b110093
Update click-to-copy.js
akshatsinghai6682-sketch e7ed890
Update click-to-copy.js
akshatsinghai6682-sketch d49368c
Update assets/js/click-to-copy.js
akshatsinghai6682-sketch 886cb3c
Update click-to-copy.js
akshatsinghai6682-sketch 7253432
Update click-to-copy.js
akshatsinghai6682-sketch 99fbf9a
Update click-to-copy.js
akshatsinghai6682-sketch d9057f8
UI: replace FontAwesome icons with Sistent copy and check icons
akshatsinghai6682-sketch 5266680
fix: revert copy button icons to FontAwesome, keep position-shift and…
akshatsinghai6682-sketch e76543a
Merge branch 'master' into fix-copy-button-shift
Rajesh-Nagarajan-11 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| const codeListings = document.querySelectorAll('.highlight > pre'); | ||
| for (let index = 0; index < codeListings.length; index++) { | ||
| const codeSample = codeListings[index].querySelector('code'); | ||
|
|
||
| const copyButton = document.createElement('button'); | ||
| const buttonAttributes = { | ||
| type: 'button', | ||
| title: 'Copy to clipboard', | ||
| 'data-bs-toggle': 'tooltip', | ||
| 'data-bs-placement': 'top', | ||
| 'data-bs-container': 'body', | ||
| }; | ||
| Object.keys(buttonAttributes).forEach((key) => { | ||
| copyButton.setAttribute(key, buttonAttributes[key]); | ||
| }); | ||
| copyButton.classList.add( | ||
| 'fas', | ||
| 'fa-copy', | ||
| 'btn', | ||
| 'btn-sm', | ||
| 'td-click-to-copy' | ||
| ); | ||
| const tooltip = new bootstrap.Tooltip(copyButton); | ||
| let revertTimeout; | ||
| copyButton.onclick = () => { | ||
| copyCode(codeSample) | ||
| .then(() => { | ||
| copyButton.setAttribute('data-bs-original-title', 'Copied!'); | ||
| tooltip.show(); | ||
| copyButton.classList.remove('fa-copy'); | ||
| copyButton.classList.add('fa-check', 'td-click-to-copy--copied'); | ||
| clearTimeout(revertTimeout); | ||
| revertTimeout = setTimeout(() => { | ||
| copyButton.classList.remove('fa-check', 'td-click-to-copy--copied'); | ||
| copyButton.classList.add('fa-copy'); | ||
| copyButton.setAttribute('data-bs-original-title', 'Copy to clipboard'); | ||
| tooltip.hide(); | ||
| }, 2500); | ||
| }) | ||
| .catch((err) => { | ||
| console.warn('Failed to copy code to clipboard:', err); | ||
| copyButton.setAttribute('data-bs-original-title', 'Failed to copy'); | ||
| tooltip.show(); | ||
| clearTimeout(revertTimeout); | ||
| revertTimeout = setTimeout(() => { | ||
| copyButton.setAttribute('data-bs-original-title', 'Copy to clipboard'); | ||
| tooltip.hide(); | ||
| }, 2500); | ||
| }); | ||
| }; | ||
| const buttonDiv = document.createElement('div'); | ||
| buttonDiv.classList.add('click-to-copy'); | ||
| buttonDiv.append(copyButton); | ||
| codeListings[index].insertBefore(buttonDiv, codeSample); | ||
| } | ||
|
|
||
| const copyCode = (codeSample) => { | ||
| const isConsoleBlock = codeSample.matches( | ||
| "code[data-lang='console'], code.language-console" | ||
| ); | ||
| let text; | ||
| if (isConsoleBlock) { | ||
| const clone = codeSample.cloneNode(true); | ||
| pruneUnselectableElements(codeSample, clone); | ||
| text = clone.textContent; | ||
| text = text.replace(/^ /gm, ''); | ||
| } else { | ||
| text = codeSample.textContent; | ||
| } | ||
| text = text ? text.trim() : ''; | ||
| return navigator.clipboard.writeText(text + '\n'); | ||
| }; | ||
|
|
||
| const pruneUnselectableElements = (sourceNode, cloneNode) => { | ||
| const sourceChildren = sourceNode.children; | ||
| const cloneChildren = cloneNode.children; | ||
| for (let i = sourceChildren.length - 1; i >= 0; i--) { | ||
| const sourceChild = sourceChildren[i]; | ||
| const cloneChild = cloneChildren[i]; | ||
| const style = window.getComputedStyle(sourceChild); | ||
| const unselectable = | ||
| style.userSelect === 'none' || style.webkitUserSelect === 'none'; | ||
| if (unselectable) { | ||
| cloneChild.remove(); | ||
| continue; | ||
| } | ||
| pruneUnselectableElements(sourceChild, cloneChild); | ||
| } | ||
| }; | ||
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.