diff --git a/src/dashboardWebView/components/SnippetsView/Item.tsx b/src/dashboardWebView/components/SnippetsView/Item.tsx index f6bbb2bc..db964fc5 100644 --- a/src/dashboardWebView/components/SnippetsView/Item.tsx +++ b/src/dashboardWebView/components/SnippetsView/Item.tsx @@ -43,7 +43,7 @@ export const Item: React.FunctionComponent = ({ title, snippet }: Re const onOpenEdit = useCallback(() => { setSnippetTitle(title); setSnippetDescription(snippet.description); - setSnippetOriginalBody(snippet.body.join(`\n`)); + setSnippetOriginalBody(typeof snippet.body === "string" ? snippet.body : snippet.body.join(`\n`)); setShowEditDialog(true); }, [snippet]); @@ -54,9 +54,10 @@ export const Item: React.FunctionComponent = ({ title, snippet }: Re } const snippets = Object.assign({}, settings?.snippets || {}); + const snippetLines = snippetOriginalBody.split("\n"); const snippetContents = { description: snippetDescription || '', - body: snippetOriginalBody.split("\n") + body: snippetLines.length === 1 ? snippetLines[0] : snippetLines }; if (title === snippetTitle) { diff --git a/src/dashboardWebView/components/SnippetsView/SnippetForm.tsx b/src/dashboardWebView/components/SnippetsView/SnippetForm.tsx index 1114c985..9e673565 100644 --- a/src/dashboardWebView/components/SnippetsView/SnippetForm.tsx +++ b/src/dashboardWebView/components/SnippetsView/SnippetForm.tsx @@ -42,7 +42,7 @@ const SnippetForm: React.ForwardRefRenderFunction { - let body = snippet.body.join(`\n`); + let body = typeof snippet.body === "string" ? snippet.body : snippet.body.join(`\n`); for (const field of fields) { body = body.replace(field.tmString, field.value); @@ -51,6 +51,14 @@ const SnippetForm: React.ForwardRefRenderFunction { + const crntField = allFields.findIndex(f => f.name === fieldName); + if (crntField < idx) { + return false; + } + return true; + } + useImperativeHandle(ref, () => ({ onSave() { if (!snippetBody) { @@ -66,7 +74,7 @@ const SnippetForm: React.ForwardRefRenderFunction { const snippetParser = new SnippetParser(); - const body = snippet.body.join(`\n`); + const body = typeof snippet.body === "string" ? snippet.body : snippet.body.join(`\n`); const parsed = snippetParser.parse(body); const placeholders = parsed.placeholderInfo.all; @@ -76,6 +84,8 @@ const SnippetForm: React.ForwardRefRenderFunction { - fields.map((field: SnippetField, index: number) => ( -
- -
- { - field.type === 'select' ? ( -
- + fields.map((field: SnippetField, index: number, allFields: SnippetField[]) => ( + shouldShowField(field.name, index, allFields) && ( +
+ +
+ { + field.type === 'select' ? ( +
+ - -
- ) : ( -