From 1fb8b58087d847a08090f2d52f5abcb40a22e719 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Fri, 18 Aug 2023 13:45:33 +0100 Subject: [PATCH] fix code padding --- src/lib/commandCenter/panels/ai.svelte | 15 +++++++++++---- src/lib/commandCenter/panels/template.svelte | 6 ++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lib/commandCenter/panels/ai.svelte b/src/lib/commandCenter/panels/ai.svelte index 02a51a078..bed645ccc 100644 --- a/src/lib/commandCenter/panels/ai.svelte +++ b/src/lib/commandCenter/panels/ai.svelte @@ -39,6 +39,7 @@ // get all code matches const codeMatches = Array.from(c.matchAll(/```([a-z]*)(.*?)(```|$)/gs)); + console.log(codeMatches); let i = 0; let codeIdx = 0; @@ -56,7 +57,9 @@ answer.push({ type: 'code', - value: nextCodeMatch[2], + value: nextCodeMatch[2].startsWith('\n') + ? nextCodeMatch[2].slice(1) + : nextCodeMatch[2], language: isLanguage(language) ? language : 'js' }); @@ -79,7 +82,7 @@ function getInitials(name: string) { const [first, last] = name.split(' '); - return `${first[0]}${last[0]}`; + return `${first?.[0] ?? ''}${last?.[0] ?? ''}`; } @@ -127,10 +130,14 @@ {:else} {#each answer as part} {#if part.type === 'text'} -

{part.value}

+

{part.value.trimStart()}

{:else if part.type === 'code'} {#key part.value} - +
+ +
{/key} {/if} {/each} diff --git a/src/lib/commandCenter/panels/template.svelte b/src/lib/commandCenter/panels/template.svelte index 86f29a53b..3b69a80aa 100644 --- a/src/lib/commandCenter/panels/template.svelte +++ b/src/lib/commandCenter/panels/template.svelte @@ -106,10 +106,8 @@ } } - $: if (selected > options.length - 1) { - selected = options.length - 1; - } else if (selected < 0) { - selected = 0; + $: if (selected > options?.length - 1) { + selected = options?.length - 1; } const commandCenterCtx = getCommandCenterCtx();