Skip to content

Commit

Permalink
chore: fix saving text to clipboard for input, show button in markdow…
Browse files Browse the repository at this point in the history
…n codeblocks #2025
  • Loading branch information
marek-mihok authored and mturoci committed Sep 6, 2023
1 parent 15cdfe8 commit 798057f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ui/src/copyable_text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export const ClipboardCopyButton = ({ value, anchorElement, showOnHoverOnly = fa
onClick = async () => {
if (!anchorElement) return
try {
if (document.queryCommandSupported('copy') && anchorElement.tagName === 'input') {
(anchorElement as HTMLInputElement).select()
if (document.queryCommandSupported('copy')) {
anchorElement.select()
document.execCommand('copy')
window.getSelection()?.removeAllRanges()
}
Expand All @@ -91,7 +91,7 @@ export const ClipboardCopyButton = ({ value, anchorElement, showOnHoverOnly = fa
setVisible(false)
})
}
}, [value, anchorElement])
}, [anchorElement])

React.useEffect(() => () => window.clearTimeout(timeoutRef.current), [])

Expand All @@ -111,7 +111,7 @@ export const XCopyableText = ({ model }: { model: CopyableText }) => {
heightStyle = multiline && height === '1' ? fullHeightStyle : undefined,
[inputEl, setInputEl] = React.useState(),
domRef = React.useCallback(node => {
const inputEl = node?.children[0]?.children[1]
const inputEl = node?.children[0]?.children[1]?.children[0]
if (inputEl) setInputEl(inputEl)
}, [])

Expand All @@ -137,7 +137,8 @@ export const XCopyableText = ({ model }: { model: CopyableText }) => {
/>
<ClipboardCopyButton
anchorElement={inputEl}
showOnHoverOnly={!!multiline} value={value}
showOnHoverOnly={!!multiline}
value={value}
/>
</>
)
Expand Down

0 comments on commit 798057f

Please sign in to comment.