Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(code): open a tooltip into the host and check its theme classes
Claude29932c45f97f
diff --git a/packages/codemirror/src/index.spec.ts b/packages/codemirror/src/index.spec.tsindex e05f32def0..41f044fec1 100644--- a/packages/codemirror/src/index.spec.ts+++ b/packages/codemirror/src/index.spec.ts@@ -1,6 +1,6 @@import { indentUnit } from "@codemirror/language";-import { EditorSelection, EditorState } from "@codemirror/state";-import { EditorView, type ViewUpdate } from "@codemirror/view";+import { EditorSelection, EditorState, StateEffect } from "@codemirror/state";+import { EditorView, showTooltip, type ViewUpdate } from "@codemirror/view";import { afterEach, describe, expect, it, vi } from "vitest";import CodeMirror, { type EditorConfig, getThemeById } from "./index.js";@@ -121,6 +121,28 @@ describe("CodeMirror", () => {second.destroy();}});++ it("renders a tooltip into the host, under the editor's theme classes", () => {+ editor = build();+ const dom = document.createElement("div");+ dom.className = "cm-tooltip-lint";+ editor.dispatch({+ effects: StateEffect.appendConfig.of(showTooltip.of({ pos: 0, create: () => ({ dom }) }))+ });++ const host = document.body.querySelector(".cm-tooltip-host");+ expect(host?.contains(dom)).toBe(true);+ expect(editor.dom.contains(dom)).toBe(false);+ // The editor's scoped base themes, such as the lint tooltip's width cap, match through+ // these classes on the container.+ const container = dom.closest(".cm-tooltip-host > *");+ expect(container).not.toBeNull();+ const themeClasses = editor.themeClasses.split(" ").filter(Boolean);+ expect(themeClasses.length).toBeGreaterThan(0);+ for (const cls of themeClasses) {+ expect(container?.classList.contains(cls)).toBe(true);+ }+ });});describe("text access", () => {diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.tsindex 2a4a202f1c..a20873eff5 100644--- a/packages/codemirror/src/index.ts+++ b/packages/codemirror/src/index.ts@@ -478,12 +478,8 @@ export default class CodeMirror extends EditorView {}/**- * The body-level element CodeMirror renders its tooltips into, created on first use.- *- * Tooltips otherwise live inside `.cm-editor`, which is `overflow: hidden`, and CodeMirror falls- * back to absolute positioning on Safari and iOS — clipping the completion popup to the editor's- * box, which for a one- or two-line note leaves only a sliver of it. The host also gives the app one- * class to size the tooltips by and to lift them over the dialogs an editor can sit in.+ * Returns the body-level element CodeMirror renders tooltips into, outside `.cm-editor`, whose+ * `overflow: hidden` clips an absolutely positioned tooltip (Safari, iOS).*/function getTooltipHost() {const existing = document.body.querySelector(".cm-tooltip-host");