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 <centdix@users.noreply.github.com>

* fix

* fix

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: centdix <centdix@users.noreply.github.com>
Co-authored-by: centdix <farhadg110@gmail.com>
This commit is contained in:
claude[bot]
2025-06-09 15:14:20 +00:00
committed by GitHub
co-authored by centdix centdix
parent 556a4118e9
commit 2c1e1c666a
3 changed files with 20 additions and 5 deletions
@@ -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)}
>
<svelte:component this={ContextIconMap[element.type]} size={16} />
{element.title}
{element.type === 'diff' ? element.title.replace(/_/g, ' ') : element.title}
</button>
{/each}
{/if}
@@ -42,7 +42,9 @@
<svelte:component this={icon} size={16} />
{/if}
</button>
{contextElement.title}
{contextElement.type === 'diff'
? contextElement.title.replace(/_/g, ' ')
: contextElement.title}
</div>
</svelte:fragment>
<svelte:fragment slot="content">
@@ -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