Skip to content

Commit 2051756

Browse files
authored
fix: extra quotation marks will be added when execute edit-save action repeatly (#10)
1 parent 9e8de1b commit 2051756

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/components/json-node.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
isObject,
1010
isReactComponent,
1111
safeCall,
12-
stringifyForCopying
12+
stringifyForCopying,
13+
resolveEvalFailedNewValue
1314
} from '../utils'
1415
import ObjectNode from './object-node'
1516
import LongString from './long-string'
@@ -68,6 +69,7 @@ export default function JsonNode({ node, depth, deleteHandle: _deleteHandle, nam
6869
valueRef.current?.focus()
6970
})
7071
}
72+
7173
const done = () => {
7274
const newValue = valueRef.current!.innerText
7375

@@ -76,7 +78,8 @@ export default function JsonNode({ node, depth, deleteHandle: _deleteHandle, nam
7678

7779
if (editHandle) editHandle(name!, evalValue, node)
7880
} catch (e) {
79-
if (editHandle) editHandle(name!, newValue, node)
81+
const trimmedStringValue = resolveEvalFailedNewValue(type, newValue);
82+
if (editHandle) editHandle(name!, trimmedStringValue, node)
8083
}
8184

8285
setEditing(false)

src/utils.ts

+7
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,10 @@ export function customDelete(customOptions?: CustomizeOptions) {
9292
export function customCopy(customOptions?: CustomizeOptions) {
9393
return !customOptions || customOptions.enableClipboard === undefined || !!customOptions.enableClipboard
9494
}
95+
96+
export function resolveEvalFailedNewValue(type: string, value: string) {
97+
if (type === 'string') {
98+
return value.trim().replace(/^\"([\s\S]+?)\"$/, '$1');
99+
}
100+
return value;
101+
}

0 commit comments

Comments
 (0)