From e72ff9cde15d90585605f976912ba974c0ef306d Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 28 Mar 2025 00:03:27 +0100 Subject: [PATCH] create long hash --- frontend/src/lib/components/copilot/chat/AIChat.svelte | 6 +++--- frontend/src/lib/components/copilot/shared.ts | 3 ++- frontend/src/lib/editorUtils.ts | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/components/copilot/chat/AIChat.svelte b/frontend/src/lib/components/copilot/chat/AIChat.svelte index 5030dfb547..d27077d989 100644 --- a/frontend/src/lib/components/copilot/chat/AIChat.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChat.svelte @@ -16,7 +16,7 @@ import { sendUserToast } from '$lib/toast' import { openDB, type DBSchema as IDBSchema, type IDBPDatabase } from 'idb' import { isInitialCode } from '$lib/script_helpers' - import { langToExt } from '$lib/editorUtils' + import { createLongHash, langToExt } from '$lib/editorUtils' import { scriptLangToEditorLang } from '$lib/scripts' export let lang: ScriptLang | 'bunnative' @@ -159,7 +159,7 @@ } }) - let currentChatId: string = crypto.randomUUID() + let currentChatId: string = createLongHash() let savedChats: Record< string, { @@ -292,7 +292,7 @@ async function saveAndClear() { await saveChat() - currentChatId = crypto.randomUUID() + currentChatId = createLongHash() displayMessages = [] messages = [prepareSystemMessage()] } diff --git a/frontend/src/lib/components/copilot/shared.ts b/frontend/src/lib/components/copilot/shared.ts index e25464e929..9b7e2391f0 100644 --- a/frontend/src/lib/components/copilot/shared.ts +++ b/frontend/src/lib/components/copilot/shared.ts @@ -1,3 +1,4 @@ +import { createLongHash } from '$lib/editorUtils' import { type editor as meditor } from 'monaco-editor' export type VisualChange = @@ -71,7 +72,7 @@ export function setGlobalCSS(id: string, cssCode: string) { } function addInlineGhostText(change: Extract) { - const cssId = crypto.randomUUID() + const cssId = createLongHash() const decoration = { range: { startLineNumber: change.position.line, diff --git a/frontend/src/lib/editorUtils.ts b/frontend/src/lib/editorUtils.ts index 2b8ddb6ba4..1eddb31ae0 100644 --- a/frontend/src/lib/editorUtils.ts +++ b/frontend/src/lib/editorUtils.ts @@ -44,6 +44,10 @@ export function createHash() { return (Math.random() + 1).toString(36).substring(2) } +export function createLongHash() { + return Math.random().toString(36).substring(2) + Math.random().toString(36).substring(2) +} + export function langToExt(lang: string): string { switch (lang) { case 'javascript':