Skip to content

Commit 2a5aa4d

Browse files
committed
(fix): embedding fold preview with inline values, vectorsdb sample data label
1 parent 8c29b65 commit 2a5aa4d

2 files changed

Lines changed: 45 additions & 14 deletions

File tree

  • src/routes/(console)/project-[region]-[project]/databases/database-[database]

src/routes/(console)/project-[region]-[project]/databases/database-[database]/(suggestions)/input.svelte

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
const record = terminology.record.lower;
3636
const entity = terminology.entity.lower.singular;
3737
38+
const isSchemaless = type === 'documentsdb' || type === 'vectorsdb';
39+
3840
const title = $derived.by(() => {
3941
switch (type) {
4042
default:
@@ -45,20 +47,19 @@
4547
: `Smart ${field.singular} suggestions available on Cloud`;
4648
4749
case 'documentsdb':
50+
case 'vectorsdb':
4851
return featureActive ? `Sample Data` : `Sample Data available on Cloud`;
4952
}
5053
});
5154
5255
const subtitle = $derived.by(() => {
53-
const isDocs = type === 'documentsdb';
54-
5556
if (featureActive) {
56-
return isDocs
57+
return isSchemaless
5758
? `Generate sample ${record.plural} based on your ${entity} name`
5859
: `Enable AI to suggest useful ${field.plural} based on your ${entity} name`;
5960
}
6061
61-
return isDocs
62+
return isSchemaless
6263
? `Sign up for Cloud to generate sample documents based on your ${entity} name`
6364
: `Sign up for Cloud to generate ${field.plural} based on your ${entity} name`;
6465
});

src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/(components)/editor/view.svelte

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<script lang="ts">
1616
import {
1717
EditorView,
18+
ViewPlugin,
1819
keymap,
1920
lineNumbers,
2021
highlightActiveLine,
@@ -1030,6 +1031,9 @@
10301031
* Fold the embeddings array so it doesn't dominate the editor.
10311032
* Uses manual bracket matching — no syntax tree dependency.
10321033
*/
1034+
const EMBEDDING_PREVIEW_COUNT = 2;
1035+
let embeddingPreviewText = $state<string | null>(null);
1036+
10331037
function foldEmbeddings(view: EditorView) {
10341038
const doc = view.state.doc;
10351039
@@ -1039,11 +1043,22 @@
10391043
if (!match) continue;
10401044
10411045
const bracketPos = line.from + match[1].length;
1046+
1047+
// Extract preview values before folding
1048+
const values: string[] = [];
1049+
for (
1050+
let nextLn = ln + 1;
1051+
nextLn <= doc.lines && values.length < EMBEDDING_PREVIEW_COUNT;
1052+
nextLn++
1053+
) {
1054+
const text = doc.line(nextLn).text.trim().replace(/,$/, '');
1055+
if (text === ']' || text === '') break;
1056+
if (/^-?[\d.]+(?:e[+-]?\d+)?$/i.test(text)) values.push(text);
1057+
}
1058+
embeddingPreviewText = values.length ? values.join(', ') + ', …' : null;
1059+
10421060
let depth = 0;
10431061
let closePos = -1;
1044-
let commaCount = 0;
1045-
let foldFrom = -1;
1046-
const PREVIEW_COUNT = 2;
10471062
10481063
for (let pos = bracketPos; pos < doc.length; pos++) {
10491064
const ch = doc.sliceString(pos, pos + 1);
@@ -1054,17 +1069,12 @@
10541069
closePos = pos;
10551070
break;
10561071
}
1057-
} else if (ch === ',' && depth === 1) {
1058-
commaCount++;
1059-
if (commaCount === PREVIEW_COUNT && foldFrom === -1) {
1060-
foldFrom = pos + 1;
1061-
}
10621072
}
10631073
}
10641074
1065-
if (closePos > bracketPos + 1 && foldFrom > -1) {
1075+
if (closePos > bracketPos + 1) {
10661076
view.dispatch({
1067-
effects: [foldEffect.of({ from: foldFrom, to: closePos })],
1077+
effects: [foldEffect.of({ from: bracketPos + 1, to: closePos })],
10681078
annotations: [Transaction.addToHistory.of(false)]
10691079
});
10701080
}
@@ -1082,6 +1092,26 @@
10821092
lineNumbers(),
10831093
highlightActiveLine(),
10841094
highlightActiveLineGutter(),
1095+
// Update embedding fold placeholder with preview values
1096+
ViewPlugin.fromClass(
1097+
class {
1098+
update(update: ViewUpdate) {
1099+
if (
1100+
!update.transactions.some((tr) =>
1101+
tr.effects.some((e) => e.is(foldEffect))
1102+
)
1103+
)
1104+
return;
1105+
setTimeout(() => {
1106+
const placeholder =
1107+
update.view.dom.querySelector('.cm-foldPlaceholder');
1108+
if (placeholder && embeddingPreviewText) {
1109+
placeholder.textContent = embeddingPreviewText;
1110+
}
1111+
}, 10);
1112+
}
1113+
}
1114+
),
10851115
// Use fold gutter, hide default glyphs (we style via CSS)
10861116
foldGutter({ openText: ' ', closedText: ' ' }),
10871117
indentUnit.of(' '), // Use 2 spaces for indentation

0 commit comments

Comments
 (0)