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
fix(code): stop Safari clipping the completion popup
Elian Doran3b4779511661
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex ee172dffd8..7f0f83e78a 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -646,6 +646,17 @@ body.mobile .dropdown-menu .dropdown-submenu {}}+/* CodeMirror renders its tooltips into this element rather than into `.cm-editor`, which clips them+ (see `getTooltipHost()` in `packages/codemirror`). The stacking context has to clear the dialogs an+ editor can sit in, up to 1101, and stay under the context menu at 2500. */+.cm-tooltip-host {+ position: absolute;+ top: 0;+ left: 0;+ z-index: 2000;+ font-size: var(--monospace-font-size);+}+#sql-console-query {height: 150px;width: 100%;diff --git a/packages/codemirror/src/index.spec.ts b/packages/codemirror/src/index.spec.tsindex 60c4a321ea..e05f32def0 100644--- a/packages/codemirror/src/index.spec.ts+++ b/packages/codemirror/src/index.spec.ts@@ -106,6 +106,21 @@ describe("CodeMirror", () => {expect(editor.contentDOM.getAttribute("autocorrect")).toBe("on");expect(editor.contentDOM.getAttribute("autocapitalize")).toBe("sentences");});++ it("hosts tooltips in one body-level element, outside the editor that would clip them", () => {+ editor = build();+ const host = document.body.querySelector(".cm-tooltip-host");+ expect(host).not.toBeNull();+ expect(editor.dom.contains(host)).toBe(false);++ // A second editor shares the host rather than adding one of its own.+ const second = build();+ try {+ expect(document.body.querySelectorAll(".cm-tooltip-host")).toHaveLength(1);+ } finally {+ second.destroy();+ }+ });});describe("text access", () => {diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.tsindex 0c4e000879..2a4a202f1c 100644--- a/packages/codemirror/src/index.ts+++ b/packages/codemirror/src/index.ts@@ -1,5 +1,5 @@import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";-import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, ViewPlugin, ViewUpdate, type EditorViewConfig, KeyBinding } from "@codemirror/view";+import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, tooltips, ViewPlugin, ViewUpdate, type EditorViewConfig, KeyBinding } from "@codemirror/view";import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching, foldGutter, codeFolding } from "@codemirror/language";import { Compartment, EditorSelection, EditorState, StateEffect, type Extension } from "@codemirror/state";import { highlightSelectionMatches } from "@codemirror/search";@@ -131,6 +131,7 @@ export default class CodeMirror extends EditorView {keyboardSuggestionsCompartment.of(config.allowKeyboardSuggestions ? proseKeyboardAttributes : noKeyboardSuggestions),searchMatchHighlightTheme,lintTooltipTheme,+ tooltips({ parent: getTooltipHost() }),searchHighlightCompartment.of([]),typeCompletionCompartment.of([]),completionSourceCompartment.of([]),@@ -475,3 +476,23 @@ 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.+ */+function getTooltipHost() {+ const existing = document.body.querySelector(".cm-tooltip-host");+ if (existing instanceof HTMLElement) {+ return existing;+ }++ const host = document.createElement("div");+ host.className = "cm-tooltip-host";+ document.body.appendChild(host);+ return host;+}