This repository was archived by the owner on Jul 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 375
feature: Made copying manifest url to clipboard better #6698
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c06c813
Made copying to clipboard better
GeoffCoxMSFT c9395d8
Merge branch 'main' into gcox/improve6597
GeoffCoxMSFT c0dd9b0
PR fixes
GeoffCoxMSFT 44e4c78
Merge branch 'main' into gcox/improve6597
GeoffCoxMSFT 6b099c0
Merge branch 'gcox/improve6597' of https://github.com/microsoft/BotFr…
GeoffCoxMSFT ad79a84
CI fix
GeoffCoxMSFT 1d5d450
Merge branch 'main' into gcox/improve6597
GeoffCoxMSFT dd466c0
Fix ref usage
GeoffCoxMSFT e60a282
Merge branch 'gcox/improve6597' of https://github.com/microsoft/BotFr…
GeoffCoxMSFT 7c88470
Merge branch 'main' into gcox/improve6597
hatpick 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| export * from './useCopyToClipboard'; |
55 changes: 55 additions & 0 deletions
55
Composer/packages/lib/ui-shared/src/hooks/useCopyToClipboard.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,55 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import * as React from 'react'; | ||
|
|
||
| /** | ||
| * Creates a textarea at then end of the document body then | ||
| * uses that to copy the specified text to the cliboard. | ||
| */ | ||
|
|
||
| export const copyToClipboard = (text: string) => { | ||
| // Remember the current selection | ||
| const rangeCount = document?.getSelection()?.rangeCount || 0; | ||
| const selected = rangeCount > 0 ? document?.getSelection()?.getRangeAt(0) : false; | ||
|
GeoffCoxMSFT marked this conversation as resolved.
Outdated
|
||
|
|
||
| // Create an offscreen textarea and copy the text | ||
| const element = document.createElement('textarea'); | ||
| element.value = text; | ||
| element.setAttribute('readonly', ''); | ||
| element.style.position = 'absolute'; | ||
| element.style.left = '-9999px'; | ||
| document.body.appendChild(element); | ||
| element.select(); | ||
| const success = document.execCommand('copy'); | ||
| document.body.removeChild(element); | ||
|
|
||
| // Restore the previous selection | ||
| if (document?.getSelection() && selected) { | ||
|
GeoffCoxMSFT marked this conversation as resolved.
Outdated
|
||
| document?.getSelection()?.removeAllRanges(); | ||
|
GeoffCoxMSFT marked this conversation as resolved.
Outdated
|
||
| document?.getSelection()?.addRange(selected); | ||
| } | ||
|
|
||
| if (!success) { | ||
| throw new Error('There was a problem copying to the clipboard.'); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Hook to copy text to the clipboard. | ||
| */ | ||
| export const useCopyToClipboard = (text: string) => { | ||
| const [isCopiedToClipboard, setIsCopiedToClipboard] = React.useState(false); | ||
|
|
||
| const copyTextToClipboard = React.useCallback(() => { | ||
| copyToClipboard(text); | ||
| setIsCopiedToClipboard(true); | ||
| }, [text]); | ||
|
|
||
| const resetIsCopiedToClipboard = () => setIsCopiedToClipboard(false); | ||
|
GeoffCoxMSFT marked this conversation as resolved.
Outdated
|
||
|
|
||
| // When the text changes, reset copied. | ||
| React.useEffect(() => () => resetIsCopiedToClipboard(), [text]); | ||
|
|
||
| return { isCopiedToClipboard, copyTextToClipboard, resetIsCopiedToClipboard }; | ||
| }; | ||
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
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.