mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Escape quotes when editing strings
This commit is contained in:
@@ -111,12 +111,12 @@ function StringHead({ type, optional, node, makeEdit, ctx }: Props<StringType>)
|
|||||||
if ((newValue.length === 0 && optional) || (isSelect && newValue === SPECIAL_UNSET)) {
|
if ((newValue.length === 0 && optional) || (isSelect && newValue === SPECIAL_UNSET)) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
const valueMap = [{ inner: core.Range.create(0), outer: core.Range.create(range.start) }]
|
||||||
|
const source = new core.Source(JSON.stringify(newValue), valueMap)
|
||||||
|
const string = core.string(json.parser.JsonStringOptions)(source, ctx)
|
||||||
return {
|
return {
|
||||||
|
...string,
|
||||||
type: 'json:string',
|
type: 'json:string',
|
||||||
range,
|
|
||||||
options: json.parser.JsonStringOptions,
|
|
||||||
value: newValue,
|
|
||||||
valueMap: [{ inner: core.Range.create(0), outer: core.Range.create(range.start) }],
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, [optional, node, makeEdit, isSelect])
|
}, [optional, node, makeEdit, isSelect])
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type { McmetaSummary } from '@spyglassmc/java-edition/lib/dependency/inde
|
|||||||
import { Fluids, ReleaseVersion, symbolRegistrar } from '@spyglassmc/java-edition/lib/dependency/index.js'
|
import { Fluids, ReleaseVersion, symbolRegistrar } from '@spyglassmc/java-edition/lib/dependency/index.js'
|
||||||
import * as jeJson from '@spyglassmc/java-edition/lib/json/index.js'
|
import * as jeJson from '@spyglassmc/java-edition/lib/json/index.js'
|
||||||
import * as jeMcf from '@spyglassmc/java-edition/lib/mcfunction/index.js'
|
import * as jeMcf from '@spyglassmc/java-edition/lib/mcfunction/index.js'
|
||||||
import type { JsonFileNode } from '@spyglassmc/json'
|
import type { JsonFileNode, JsonStringNode } from '@spyglassmc/json'
|
||||||
import * as json from '@spyglassmc/json'
|
import * as json from '@spyglassmc/json'
|
||||||
import { localize } from '@spyglassmc/locales'
|
import { localize } from '@spyglassmc/locales'
|
||||||
import * as mcdoc from '@spyglassmc/mcdoc'
|
import * as mcdoc from '@spyglassmc/mcdoc'
|
||||||
@@ -322,9 +322,13 @@ const initialize: core.ProjectInitializer = async (ctx) => {
|
|||||||
jeMcf.initialize(ctx, summary.commands, release)
|
jeMcf.initialize(ctx, summary.commands, release)
|
||||||
nbt.initialize(ctx)
|
nbt.initialize(ctx)
|
||||||
|
|
||||||
|
// Until spyglass registers these correctly
|
||||||
meta.registerFormatter<JsonFileNode>('json:file', (node, ctx) => {
|
meta.registerFormatter<JsonFileNode>('json:file', (node, ctx) => {
|
||||||
return ctx.meta.getFormatter(node.children[0].type)(node.children[0], ctx)
|
return ctx.meta.getFormatter(node.children[0].type)(node.children[0], ctx)
|
||||||
})
|
})
|
||||||
|
meta.registerFormatter<JsonStringNode>('json:string', (node) => {
|
||||||
|
return JSON.stringify(node.value)
|
||||||
|
})
|
||||||
|
|
||||||
return { loadedVersion: release }
|
return { loadedVersion: release }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user