From 7c39e8ad8628641a3e02ef03a14180e97089df19 Mon Sep 17 00:00:00 2001 From: Albin Falsen Lindqvist Date: Wed, 19 Aug 2026 13:52:28 +0200 Subject: [PATCH] fix: copy string values without JSON quotes Copying a string node put its JSON representation on the clipboard, so `my value` was pasted as `"my value"`. Values that are already text are now copied verbatim; objects, arrays, numbers and booleans keep their JSON representation. Co-Authored-By: Claude Opus 5 --- src/js/components/CopyToClipboard.js | 12 +++- .../js/components/CopyToClipboard-test.js | 67 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/js/components/CopyToClipboard.js b/src/js/components/CopyToClipboard.js index 2608e38..75951b5 100644 --- a/src/js/components/CopyToClipboard.js +++ b/src/js/components/CopyToClipboard.js @@ -37,7 +37,7 @@ export default class extends React.PureComponent { handleCopy = () => { const { clickCallback, src, namespace } = this.props - const textToCopy = JSON.stringify(this.clipboardValue(src), null, ' ') + const textToCopy = this.clipboardText(src) if (navigator.clipboard) { navigator.clipboard.writeText(textToCopy).catch(() => { @@ -94,6 +94,16 @@ export default class extends React.PureComponent { } } + clipboardText = value => { + const clipboardValue = this.clipboardValue(value) + + if (typeof clipboardValue === 'string') { + return clipboardValue + } + + return JSON.stringify(clipboardValue, null, ' ') + } + render () { const { theme, hidden, rowHovered } = this.props const style = Theme(theme, 'copy-to-clipboard').style diff --git a/test/tests/js/components/CopyToClipboard-test.js b/test/tests/js/components/CopyToClipboard-test.js index 5e1f125..2332fb1 100644 --- a/test/tests/js/components/CopyToClipboard-test.js +++ b/test/tests/js/components/CopyToClipboard-test.js @@ -4,6 +4,36 @@ import { expect } from 'chai' import CopyToClipboard from './../../../../src/js/components/CopyToClipboard' +function copyToClipboard (src) { + const copied = [] + const { clipboard } = global.navigator + + global.navigator.clipboard = { + writeText: textToCopy => { + copied.push(textToCopy) + return Promise.resolve() + } + } + + const wrapper = shallow( +