From 2c1e1c666ae589016c4acd994ba23c36bfb2cff6 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Mon, 9 Jun 2025 17:14:20 +0200 Subject: [PATCH] fix: Prioritize diff contexts in script mode for ai chat (#5888) * fix: prioritize diff contexts and replace underscores with spaces in AI context badges - Sort context list to show diff contexts first in AvailableContextList.svelte - Replace underscores with spaces in display names for both AvailableContextList.svelte and ContextElementBadge.svelte - Improves UX by making diff context names more readable (e.g., "diff with last saved draft" instead of "diff_with_last_saved_draft") Fixes #5884 Co-authored-by: centdix * fix * fix --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: centdix Co-authored-by: centdix --- .../copilot/chat/AvailableContextList.svelte | 19 ++++++++++++++++--- .../copilot/chat/ContextElementBadge.svelte | 4 +++- .../copilot/chat/ContextManager.svelte.ts | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/components/copilot/chat/AvailableContextList.svelte b/frontend/src/lib/components/copilot/chat/AvailableContextList.svelte index e521a31679..468e5ceafc 100644 --- a/frontend/src/lib/components/copilot/chat/AvailableContextList.svelte +++ b/frontend/src/lib/components/copilot/chat/AvailableContextList.svelte @@ -8,11 +8,24 @@ export let stringSearch = '' export let selectedIndex = 0 + // Define priority map for context types + const typePriority = { + code: 1, + diff: 2, + default: 3 + } + + $: sortedAvailableContext = availableContext.sort((a, b) => { + const priorityA = typePriority[a.type] || typePriority.default + const priorityB = typePriority[b.type] || typePriority.default + return priorityA - priorityB + }) + $: actualAvailableContext = showAllAvailable - ? availableContext.filter( + ? sortedAvailableContext.filter( (c) => !stringSearch || c.title.toLowerCase().includes(stringSearch.toLowerCase()) ) - : availableContext.filter( + : sortedAvailableContext.filter( (c) => !selectedContext.find((sc) => sc.type === c.type && sc.title === c.title) && (!stringSearch || c.title.toLowerCase().includes(stringSearch.toLowerCase())) @@ -32,7 +45,7 @@ on:click={() => onSelect(element)} > - {element.title} + {element.type === 'diff' ? element.title.replace(/_/g, ' ') : element.title} {/each} {/if} diff --git a/frontend/src/lib/components/copilot/chat/ContextElementBadge.svelte b/frontend/src/lib/components/copilot/chat/ContextElementBadge.svelte index 25baf11ae0..bfb0b10f03 100644 --- a/frontend/src/lib/components/copilot/chat/ContextElementBadge.svelte +++ b/frontend/src/lib/components/copilot/chat/ContextElementBadge.svelte @@ -42,7 +42,9 @@ {/if} - {contextElement.title} + {contextElement.type === 'diff' + ? contextElement.title.replace(/_/g, ' ') + : contextElement.title} diff --git a/frontend/src/lib/components/copilot/chat/ContextManager.svelte.ts b/frontend/src/lib/components/copilot/chat/ContextManager.svelte.ts index e05e6fd622..ad89b9b672 100644 --- a/frontend/src/lib/components/copilot/chat/ContextManager.svelte.ts +++ b/frontend/src/lib/components/copilot/chat/ContextManager.svelte.ts @@ -93,7 +93,7 @@ export default class ContextManager { if (scriptOptions.lastSavedCode && scriptOptions.lastSavedCode !== scriptOptions.code) { newAvailableContext.push({ type: 'diff', - title: 'diff_with_last_saved_draft', + title: 'diff_with_last_saved_draft', // can't use spaces in the title, because it will break the word match in the context text area hightlighting logic content: scriptOptions.lastSavedCode ?? '', diff: diffLines(scriptOptions.lastSavedCode ?? '', scriptOptions.code), lang: scriptOptions.lang