Skip to content

Commit 2771a7b

Browse files
committed
fix(sql-completion): merge latest terminal changes
2 parents 4d9d8be + e05fc71 commit 2771a7b

2 files changed

Lines changed: 52 additions & 31 deletions

File tree

ui/chen/components/SqlEditor.client.vue

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ const emit = defineEmits<{
3333
const colorMode = useColorMode();
3434
const container = ref<HTMLElement | null>(null);
3535
const themeSlot = new Compartment();
36+
const syntaxThemeSlot = new Compartment();
3637
const editableSlot = new Compartment();
3738
const sqlLanguageSlot = new Compartment();
3839
let editor: EditorView | null = null;
40+
let themeObserver: MutationObserver | null = null;
3941
let applyingExternalValue = false;
4042
4143
const editorExtensions: Extension[] = [
4244
basicSetup,
4345
sqlLanguageSlot.of(chenSqlExtensions(props.dbType, props.completionSource)),
44-
createCodeMirrorSyntaxTheme(),
46+
syntaxThemeSlot.of(createCodeMirrorSyntaxTheme()),
4547
EditorView.lineWrapping,
4648
EditorState.tabSize.of(2),
4749
Prec.highest(
@@ -109,6 +111,15 @@ function replaceDocument(value: string) {
109111
replaceChenSqlDocument(editor, value);
110112
}
111113
114+
function refreshTheme() {
115+
editor?.dispatch({
116+
effects: [
117+
themeSlot.reconfigure(createCodeMirrorTheme()),
118+
syntaxThemeSlot.reconfigure(createCodeMirrorSyntaxTheme())
119+
]
120+
});
121+
}
122+
112123
onMounted(() => {
113124
if (!container.value) return;
114125
editor = new EditorView({
@@ -122,6 +133,11 @@ onMounted(() => {
122133
]
123134
})
124135
});
136+
themeObserver = new MutationObserver(refreshTheme);
137+
themeObserver.observe(document.documentElement, {
138+
attributes: true,
139+
attributeFilter: ["class", "data-theme-preset", "style"]
140+
});
125141
});
126142
127143
watch(
@@ -148,15 +164,12 @@ watch(
148164
}
149165
);
150166
151-
watch(
152-
() => colorMode.value,
153-
async () => {
154-
await nextTick();
155-
editor?.dispatch({ effects: themeSlot.reconfigure(createCodeMirrorTheme()) });
156-
}
157-
);
167+
watch(() => colorMode.value, refreshTheme);
158168
159-
onBeforeUnmount(() => editor?.destroy());
169+
onBeforeUnmount(() => {
170+
themeObserver?.disconnect();
171+
editor?.destroy();
172+
});
160173
161174
defineExpose({
162175
focus,

ui/chen/composables/useChenQueryConsole.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -217,32 +217,41 @@ export function useChenQueryConsole(
217217
}
218218
}
219219

220-
function runQueryTab(tab: ChenQueryConsoleTab, selectedSql = "") {
221-
if (tab.state.loading || tab.state.inQuery) return;
222-
const sql = selectedSql || tab.statement;
223-
if (!sql.trim()) return;
224-
dismissQueryMessage(tab);
225-
220+
function sendSql(tab: ChenQueryLikeWorkspaceTab, sql: string) {
226221
if (sql.length <= SQL_CHUNK_SIZE) {
227-
sendConsoleAction(tab, "query_console_action", { action: "run_sql", data: sql });
228-
return;
222+
return sendConsoleAction(tab, "query_console_action", { action: "run_sql", data: sql }) !== false;
229223
}
230224

231225
const total = Math.ceil(sql.length / SQL_CHUNK_SIZE);
232226
for (let index = 0; index < total; index += 1) {
233-
sendConsoleAction(tab, "query_console_action", {
234-
action: "run_sql_chunk",
235-
data: {
236-
chunk: sql.slice(index * SQL_CHUNK_SIZE, (index + 1) * SQL_CHUNK_SIZE),
237-
index,
238-
total
239-
}
240-
});
227+
if (
228+
sendConsoleAction(tab, "query_console_action", {
229+
action: "run_sql_chunk",
230+
data: {
231+
chunk: sql.slice(index * SQL_CHUNK_SIZE, (index + 1) * SQL_CHUNK_SIZE),
232+
index,
233+
total
234+
}
235+
}) === false
236+
) {
237+
return false;
238+
}
241239
}
242-
sendConsoleAction(tab, "query_console_action", {
243-
action: "run_sql_complete",
244-
data: { total }
245-
});
240+
return (
241+
sendConsoleAction(tab, "query_console_action", {
242+
action: "run_sql_complete",
243+
data: { total }
244+
}) !== false
245+
);
246+
}
247+
248+
function runQueryTab(tab: ChenQueryConsoleTab, selectedSql = "") {
249+
if (tab.state.loading || tab.state.inQuery) return;
250+
const sql = selectedSql || tab.statement;
251+
if (!sql.trim()) return;
252+
dismissQueryMessage(tab);
253+
254+
sendSql(tab, sql);
246255
}
247256

248257
function runQueryFile(tab: ChenQueryConsoleTab, path: string) {
@@ -296,8 +305,7 @@ export function useChenQueryConsole(
296305
tab.timelineEntries.splice(0, tab.timelineEntries.length - MAX_CONSOLE_TIMELINE_ENTRIES);
297306
}
298307
tab.activeTimelineEntryId = entry.id;
299-
const sent = sendConsoleAction(tab, "query_console_action", { action: "run_sql", data: sql });
300-
if (sent === false) {
308+
if (!sendSql(tab, sql)) {
301309
entry.status = "error";
302310
entry.completedAt = Date.now();
303311
const message = tab.connectionError || "Console websocket is not connected";

0 commit comments

Comments
 (0)