Skip to content

Build your personal knowledge base with Trilium Notes

fix(codemirror/autocomplete): interfering with snippets

Elian Doran9faa7507aa70
diff --git a/apps/client/src/widgets/type_widgets/code/Code.tsx b/apps/client/src/widgets/type_widgets/code/Code.tsx
index 74427f81c9..3daab634db 100644
--- a/apps/client/src/widgets/type_widgets/code/Code.tsx
+++ b/apps/client/src/widgets/type_widgets/code/Code.tsx
@@ -1,6 +1,6 @@
import "./code.css";
-import { default as VanillaCodeMirror, getThemeById } from "@triliumnext/codemirror";
+import { default as VanillaCodeMirror, getThemeById, isScriptMime } from "@triliumnext/codemirror";
import { NoteType } from "@triliumnext/commons";
import { Ref } from "preact";
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
@@ -130,12 +130,14 @@ export function EditableCode({ note, ntxId, noteContext, debounceUpdate, parentC
useKeyboardShortcuts("code-detail", containerRef, parentComponent, ntxId);
// Code snippets (#snippet notes with a matching MIME) as `/snippet:<name>` slash commands.
- // Disabled for Markdown notes, whose editor provides its own combined slash-command menu.
+ // Disabled for Markdown notes, whose editor provides its own combined slash-command menu, and
+ // for backend/frontend script notes, where the TypeScript language service owns the editor's
+ // single autocompletion (CodeMirror allows only one `override` completion config per editor).
useSnippetSlashCommands(
editorView,
(candidate) => candidate.type === "code" && (candidate.mime === note.mime || candidate.mime === "text/plain"),
note.mime,
- !note.isMarkdown(),
+ !note.isMarkdown() && !isScriptMime(note.mime),
note.noteId
);
diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.ts
index 0d84218c20..d222e23c4b 100644
--- a/packages/codemirror/src/index.ts
+++ b/packages/codemirror/src/index.ts
@@ -12,6 +12,7 @@ import { createSearchHighlighter, SearchHighlighter, searchMatchHighlightTheme }
import { buildTypeCompletion } from "./type_completion/index.js";
export { default as ColorThemes, type ThemeDefinition, type ThemeVariant, getThemeById } from "./color_themes.js";
+export { isScriptMime, SCRIPT_MIME_BACKEND, SCRIPT_MIME_FRONTEND } from "./type_completion/index.js";
// Custom keymap to prevent Ctrl+Enter from inserting a newline
// This allows the parent application to handle the shortcut (e.g., for "Run Active Note")