Allow newlines in strings by special casing "\n"

This commit is contained in:
Misode
2024-11-25 18:07:20 +01:00
parent ac37928557
commit ef03fe6058

View File

@@ -135,7 +135,7 @@ const SPECIAL_UNSET = '__unset__'
function StringHead({ type, optional, node, ctx }: Props<StringType>) {
const { locale } = useLocale()
const value = JsonStringNode.is(node) ? node.value : undefined
const value = (JsonStringNode.is(node) ? node.value : undefined)?.replaceAll('\n', '\\n')
const idAttribute = type.attributes?.find(a => a.name === 'id')?.value
const idRegistry = idAttribute?.kind === 'literal' && idAttribute.value.kind === 'string'
@@ -149,6 +149,7 @@ function StringHead({ type, optional, node, ctx }: Props<StringType>) {
const isSelect = idRegistry && isSelectRegistry(idRegistry)
const onChangeValue = useCallback((newValue: string) => {
newValue = newValue.replaceAll('\\n', '\n')
if (value === newValue) {
return
}