@marimo-team/islands 0.26.1-dev1 → 0.26.1-dev15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ConnectedDataExplorerComponent-DtwVgVpX.js → ConnectedDataExplorerComponent-CR9WyiEc.js} +11 -11
- package/dist/{ErrorBoundary-CnVR4XMW.js → ErrorBoundary-BQXI85CA.js} +7 -7
- package/dist/{abnfDiagram-VCTEODGH-BbZOIueZ.js → abnfDiagram-VCTEODGH-DGAbsdXT.js} +2 -2
- package/dist/{any-language-editor-yG-YmLaK.js → any-language-editor-DzGF1ll-.js} +5 -5
- package/dist/{architectureDiagram-5GKGNRK7-qjLjxapm.js → architectureDiagram-5GKGNRK7-D4DnIo7R.js} +1 -1
- package/dist/{assertNever-DywGMo-S.js → assertNever-CqwxSD_2.js} +3 -3
- package/dist/{button-qQhINE7z.js → button-Z2R2272J.js} +34 -31
- package/dist/{capabilities-DKqMqBzm.js → capabilities-ba3Dyv8n.js} +1 -1
- package/dist/{chat-ui-D5YPIONI.js → chat-ui-b1ERxzeA.js} +17 -17
- package/dist/{check-jchHMCfs.js → check-D9vf6LYF.js} +1 -1
- package/dist/{chunk-IMKFNOWR-BzDY1_I7.js → chunk-IMKFNOWR-Bc_i6jWx.js} +1 -1
- package/dist/{chunk-SHT3W25Y-DbHsMKdo.js → chunk-SHT3W25Y-CGML5pnF.js} +1 -1
- package/dist/{chunk-SVP7TREG-CtwnwAE6.js → chunk-SVP7TREG-ZpeFKfFT.js} +1 -1
- package/dist/{chunk-TICWLB2K-C5Z5QMbO.js → chunk-TICWLB2K-C6cLmcg8.js} +1 -1
- package/dist/{classDiagram-ZZMXUADV-B8E5Hn78.js → classDiagram-ZZMXUADV--q40NTXr.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-DeGsK9bT.js → classDiagram-v2-VYDZK3BY-Dt_Pp94L.js} +2 -2
- package/dist/{code-visibility-Cs-o5weM.js → code-visibility-B_n3GMdg.js} +6 -6
- package/dist/{common-C92_m-1k.js → common-BPgO2zo6.js} +41 -41
- package/dist/{config-qTaTHnpE.js → config-B8JCQMby.js} +4 -4
- package/dist/{copy-icon-BI7vZHEW.js → copy-icon-BLig0ZKb.js} +3 -3
- package/dist/{createReducer-DdSLRfBT.js → createReducer-BIUQ3TbG.js} +2 -2
- package/dist/{cynefinDiagram-5FMLGOSQ-NDedRwsw.js → cynefinDiagram-5FMLGOSQ-2FtF_-cc.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-De0sSZO7.js → dagre-GXQ25YYZ-Cymu2SPS.js} +1 -1
- package/dist/{data-grid-overlay-editor-D32Gn15n.js → data-grid-overlay-editor-B5aHiI2o.js} +5 -5
- package/dist/{data-grid-types-DIX_pCco.js → data-grid-types-DBNnjiYJ.js} +2 -2
- package/dist/{diagram-S7CK7UJ4-wBtVl61y.js → diagram-S7CK7UJ4-OwDa8kAa.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-CKWE3c1T.js → diagram-UQ7AKVKN-CzRDwZwd.js} +1 -1
- package/dist/{diagram-VX7I27RA-D2Ac5198.js → diagram-VX7I27RA-XRIcgMDs.js} +1 -1
- package/dist/{diagram-Z3DM3KII-CYaFOQcI.js → diagram-Z3DM3KII-DdRDYAs6.js} +1 -1
- package/dist/{dialog-Ic6dh09m.js → dialog-DGh2HNAO.js} +3 -3
- package/dist/{dist-BvZpdAuG.js → dist-6B1_Ttbh.js} +1 -1
- package/dist/{dist-D1D56-GS.js → dist-B28poF32.js} +2 -2
- package/dist/{dist-BozTF_gH.js → dist-BBZ7lnMw.js} +2 -2
- package/dist/{dist-BfrgytDR.js → dist-BD8ZKF5t.js} +3 -3
- package/dist/{dist-DNkrY12t.js → dist-BG-7Qpaj.js} +3 -3
- package/dist/{dist-D92tYjLc.js → dist-BIaGGUbU.js} +13 -11
- package/dist/{dist-BagHbFqG.js → dist-BR5PU2Ph.js} +3 -3
- package/dist/{dist-DpYpG8Yc.js → dist-BidYR5m4.js} +3 -3
- package/dist/{dist-D95Cd4xm.js → dist-BkGYCvFX.js} +3 -3
- package/dist/{dist-DneeBk3K.js → dist-BmEyXT7K.js} +2 -2
- package/dist/{dist-BdUitvVW.js → dist-Bt0Wt6m9.js} +2 -2
- package/dist/{dist-CEomphG1.js → dist-CG2Sl0D4.js} +2 -2
- package/dist/{dist-BMz__bo5.js → dist-CQfpgadU.js} +3 -3
- package/dist/{dist-BreKIQqQ.js → dist-CVOPvfzN.js} +3 -3
- package/dist/{dist-BEcpQbZa.js → dist-Cm0iCeQQ.js} +3 -3
- package/dist/{dist-CDVvitRS.js → dist-Cnc14jEq.js} +2 -2
- package/dist/{dist-ChcBm3jk.js → dist-D3KPC38e.js} +4 -4
- package/dist/{dist-B1qu3Bez.js → dist-D7BXk27E.js} +3 -3
- package/dist/{dist-BsE4gQHj.js → dist-D9Qhvxvg.js} +1 -1
- package/dist/{dist-OmeAz0fR.js → dist-DJKajXDB.js} +3 -3
- package/dist/{dist-ObeTgSmf.js → dist-DYbNRTYG.js} +4 -4
- package/dist/{dist-Cshl6jBw.js → dist-DhtDWnzK.js} +2 -2
- package/dist/{dist-BunZKA_9.js → dist-_x2Jks2R.js} +2 -2
- package/dist/{dist-MggMo7OR.js → dist-m0MWV-aw.js} +1 -1
- package/dist/{dist-TGSwzj8a.js → dist-pPbYNVjd.js} +4 -4
- package/dist/{dropdown-menu-Dhv4fcNl.js → dropdown-menu-ChH3oiqI.js} +6 -6
- package/dist/{ebnfDiagram-PWID7BFC-Ds7f42dj.js → ebnfDiagram-PWID7BFC-CZMNMGNP.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-b58Sz2Mc.js → erDiagram-RLTQ6QDP-ByxHAN4b.js} +1 -1
- package/dist/{error-banner-CJVLr5_a.js → error-banner-BvRaQnGH.js} +22 -22
- package/dist/{error-entries-BKlEsuk4.js → error-entries-Bl8fzLQc.js} +11 -11
- package/dist/{esm-B9n0caHs.js → esm-DY8dGAjJ.js} +23 -23
- package/dist/{esm-Bwp_FHP0.js → esm-Dw2ZydG_.js} +3 -3
- package/dist/{feedback-button-HXizISwe.js → feedback-button-C5zljLS1.js} +8 -8
- package/dist/{flowDiagram-HODETNUW-BH9U7VZK.js → flowDiagram-HODETNUW-BQpzWx5O.js} +2 -2
- package/dist/{formats-BLNFWWhV.js → formats-BxP8k8Un.js} +3 -3
- package/dist/{glide-data-editor-Cha2TqyF.js → glide-data-editor-Cy67HDvb.js} +59 -59
- package/dist/{glide-utils-Cn2_NadX.js → glide-utils-bKdvDwwo.js} +4 -4
- package/dist/{globals-C4qZtAQ0.js → globals-CXef1w1d.js} +3 -3
- package/dist/{html-to-image-CNM0ZSFD.js → html-to-image-D6A1lg0A.js} +3471 -3367
- package/dist/{infoDiagram-27XIBGKW-xbjwrcNi.js → infoDiagram-27XIBGKW-C9EWHkak.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-DKtukhGS.js → ishikawaDiagram-5VMMS53U-D67SGFvp.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-BEhlkZBb.js → kanban-definition-UXKFOSKX-CTMTiazR.js} +1 -1
- package/dist/{loader-Bin_dutt.js → loader-qPmiRXZd.js} +1 -1
- package/dist/main.js +5808 -5783
- package/dist/{mermaid-D1CZDNoB.js → mermaid-DE_tvTGF.js} +35 -35
- package/dist/{mindmap-definition-YA3MSWOX-DQcnJPcV.js → mindmap-definition-YA3MSWOX-LzNgDy8O.js} +1 -1
- package/dist/{number-overlay-editor-BVmdbAY7.js → number-overlay-editor-CxhKunPL.js} +3 -3
- package/dist/{pegDiagram-XKGWAZYB-BFQuPYfI.js → pegDiagram-XKGWAZYB-DFMS6feI.js} +2 -2
- package/dist/{pencil-DVYzq-iR.js → pencil-CHkdsX07.js} +1 -1
- package/dist/{pieDiagram-E7YTZNPT-l7aqNrem.js → pieDiagram-E7YTZNPT-C0MSBop-.js} +1 -1
- package/dist/{process-output-DthYR2Te.js → process-output-w5omHedc.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-6R3C1lwQ.js → railroadDiagram-O6MQD6OU-mbdav2pV.js} +2 -2
- package/dist/{requirementDiagram-BXWQKSXE-DdWYu8fn.js → requirementDiagram-BXWQKSXE-C1HNBBO6.js} +1 -1
- package/dist/{reveal-component-B8gTDFli.js → reveal-component-CWzW-8vE.js} +20 -20
- package/dist/{select-CDUxhHZg.js → select-CvorIE3l.js} +35 -35
- package/dist/{sequenceDiagram-WJ2MYXX4-Dzp0dgRc.js → sequenceDiagram-WJ2MYXX4-D6gBHifq.js} +1 -1
- package/dist/{spec-ZAt4P01J.js → spec-ayzaXGVq.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-BGnTUhFJ.js → stateDiagram-D77RDMKH-Bx-fTtRZ.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-DsJbmDf1.js → stateDiagram-v2-MP3YSRHH-Cec8T2yO.js} +2 -2
- package/dist/{static-state-C4bAlKTU.js → static-state-CqwW3B_X.js} +1 -1
- package/dist/{swimlanes-42K2YHIH-Bd4Bzh9r.js → swimlanes-42K2YHIH-C2bAgnov.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-BlY12Jf6.js → swimlanesDiagram-VR7AAH4N-CzeG-Mnb.js} +2 -2
- package/dist/{swiper-component-DTdNB9wg.js → swiper-component-B2O8hF7b.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-m0LanyCH.js → timeline-definition-24CTP7MA-DTJ0Rx8X.js} +1 -1
- package/dist/{toast-U3NpO2x3.js → toast-6V8Og7d5.js} +11 -11
- package/dist/{tooltip-UzJukb3F.js → tooltip-D0h-ZJ6j.js} +2 -2
- package/dist/{use-restore-focus-DaTVz6S6.js → use-restore-focus-BFvwj2Hj.js} +1884 -1861
- package/dist/{useDateFormatter-LQNtoXyh.js → useDateFormatter-D6o9PsWt.js} +2 -2
- package/dist/{useDeepCompareMemoize-CmNbQ9TT.js → useDeepCompareMemoize-D-Pbv7dN.js} +1 -1
- package/dist/{useIframeCapabilities-HTZiVlGV.js → useIframeCapabilities-_0KX0nu_.js} +1 -1
- package/dist/{useLifecycle-DTMczKkf.js → useLifecycle-CE0yGTMF.js} +2 -2
- package/dist/{vega-component-ZTdbCcwI.js → vega-component-DTf7GHQe.js} +8 -8
- package/dist/{vennDiagram-4TSXK5OY-BJ7vqDmn.js → vennDiagram-4TSXK5OY-lIM3SAjl.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-D5kWacsn.js → wardleyDiagram-VM6X3IG4-Bw_t7uvA.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-gr15Ws_z.js → xychartDiagram-S5SC5T6Z-BXwkLYKj.js} +1 -1
- package/package.json +3 -3
- package/src/components/editor/cell/CreateCellButton.tsx +69 -40
- package/src/components/editor/cell/__tests__/CreateCellButton.test.tsx +49 -0
- package/src/components/editor/cell/__tests__/cell-context-menu.test.tsx +126 -0
- package/src/components/editor/cell/cell-context-menu.tsx +202 -111
- package/src/components/editor/cell/code/cell-editor.tsx +5 -2
- package/src/components/editor/cell/code/code-placeholder.tsx +5 -3
- package/src/components/editor/output/console/ConsoleOutput.tsx +77 -50
- package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +28 -0
- package/src/components/editor/renderers/cells-renderer.tsx +3 -2
- package/src/components/ui/__tests__/button-shortcut.test.tsx +22 -0
- package/src/components/ui/__tests__/fullscreen.test.tsx +23 -1
- package/src/components/ui/button.tsx +5 -1
- package/src/components/ui/fullscreen.tsx +8 -39
- package/src/core/codemirror/__tests__/debounced-editor-update.test.ts +72 -0
- package/src/core/codemirror/__tests__/setup.test.ts +61 -1
- package/src/core/codemirror/cells/debugger-decorations.ts +22 -18
- package/src/core/codemirror/cells/line-timing-decorations.ts +13 -11
- package/src/core/codemirror/cells/traceback-decorations.ts +10 -11
- package/src/core/codemirror/code-lens/__tests__/extension.test.ts +31 -0
- package/src/core/codemirror/code-lens/extension.ts +21 -13
- package/src/core/codemirror/debounced-editor-update.ts +41 -0
- package/src/core/codemirror/go-to-definition/__tests__/underline.test.ts +58 -0
- package/src/core/codemirror/go-to-definition/extension.ts +9 -7
- package/src/core/codemirror/go-to-definition/underline.ts +39 -48
- package/src/core/codemirror/language/__tests__/sql.test.ts +36 -0
- package/src/core/codemirror/language/languages/sql/sql.ts +3 -0
- package/src/core/codemirror/placeholder/extensions.ts +26 -24
- package/src/core/codemirror/reactive-references/__tests__/extension.test.ts +60 -0
- package/src/core/codemirror/reactive-references/extension.ts +30 -21
- package/src/core/islands/__tests__/bridge.test.ts +1 -1
- package/src/core/islands/bootstrap.ts +0 -3
- package/src/core/notebook/replica/__tests__/replica.test.ts +7 -7
- package/src/core/session/__tests__/useNotebookReplica.hook.test.tsx +2 -2
- package/src/core/session/useNotebookSession.tsx +0 -8
- package/src/utils/__tests__/shared-resource.test.ts +107 -0
- package/src/utils/shared-resource.ts +59 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import { act, render, renderHook } from "@testing-library/react";
|
|
3
|
-
import { useRef } from "react";
|
|
3
|
+
import { StrictMode, useRef } from "react";
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
import {
|
|
@@ -104,6 +104,7 @@ describe("useFullScreenClass", () => {
|
|
|
104
104
|
const FullScreenFlag = ({ label }: { label: string }) => {
|
|
105
105
|
const ref = useRef<HTMLDivElement>(null);
|
|
106
106
|
const isFullScreen = useIsFullScreen(ref);
|
|
107
|
+
useFullScreenElement();
|
|
107
108
|
|
|
108
109
|
return (
|
|
109
110
|
<div ref={ref} data-testid={label}>
|
|
@@ -130,6 +131,27 @@ describe("useIsFullScreen", () => {
|
|
|
130
131
|
const countFullScreenListeners = (calls: unknown[][]) =>
|
|
131
132
|
calls.filter((call) => call[0] === "fullscreenchange").length;
|
|
132
133
|
|
|
134
|
+
it("balances shared listeners across StrictMode remounts", () => {
|
|
135
|
+
const add = vi.spyOn(document, "addEventListener");
|
|
136
|
+
const remove = vi.spyOn(document, "removeEventListener");
|
|
137
|
+
const mounted = render(
|
|
138
|
+
<StrictMode>
|
|
139
|
+
<FullScreenFlag label="strict" />
|
|
140
|
+
</StrictMode>,
|
|
141
|
+
);
|
|
142
|
+
expect(
|
|
143
|
+
countFullScreenListeners(add.mock.calls) -
|
|
144
|
+
countFullScreenListeners(remove.mock.calls),
|
|
145
|
+
).toBe(1);
|
|
146
|
+
mounted.unmount();
|
|
147
|
+
expect(
|
|
148
|
+
countFullScreenListeners(add.mock.calls) -
|
|
149
|
+
countFullScreenListeners(remove.mock.calls),
|
|
150
|
+
).toBe(0);
|
|
151
|
+
add.mockRestore();
|
|
152
|
+
remove.mockRestore();
|
|
153
|
+
});
|
|
154
|
+
|
|
133
155
|
it("adds one document listener for many subscribers", () => {
|
|
134
156
|
const addEventListener = vi.spyOn(document, "addEventListener");
|
|
135
157
|
|
|
@@ -128,7 +128,11 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
128
128
|
[keyboardShortcut],
|
|
129
129
|
);
|
|
130
130
|
|
|
131
|
-
useEventListener(
|
|
131
|
+
useEventListener(
|
|
132
|
+
keyboardShortcut ? document : null,
|
|
133
|
+
"keydown",
|
|
134
|
+
handleKeyPress,
|
|
135
|
+
);
|
|
132
136
|
|
|
133
137
|
const Comp = asChild ? SlotPrimitive.Slot : "button";
|
|
134
138
|
return (
|
|
@@ -7,11 +7,10 @@ type PopoverContentProps = Popover.PopoverContentProps;
|
|
|
7
7
|
import React, {
|
|
8
8
|
type RefObject,
|
|
9
9
|
useLayoutEffect,
|
|
10
|
-
useState,
|
|
11
10
|
useSyncExternalStore,
|
|
12
11
|
} from "react";
|
|
12
|
+
import { createSharedSubscription } from "@/utils/shared-resource";
|
|
13
13
|
import { isInVscodeExtension } from "@/core/vscode/is-in-vscode";
|
|
14
|
-
import { useEventListener } from "@/hooks/useEventListener";
|
|
15
14
|
|
|
16
15
|
const VSCODE_OUTPUT_CONTAINER_SELECTOR = "[data-vscode-output-container]";
|
|
17
16
|
|
|
@@ -30,9 +29,9 @@ export function useFullScreenClass() {
|
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
syncFullScreenClass();
|
|
33
|
-
|
|
32
|
+
const unsubscribe = subscribeToFullScreen(syncFullScreenClass);
|
|
34
33
|
return () => {
|
|
35
|
-
|
|
34
|
+
unsubscribe();
|
|
36
35
|
document.documentElement.classList.remove("marimo-fullscreen");
|
|
37
36
|
};
|
|
38
37
|
}, []);
|
|
@@ -58,43 +57,13 @@ export function getFullScreenElement(): Element | null {
|
|
|
58
57
|
* Get the full screen element if we are in full screen mode
|
|
59
58
|
*/
|
|
60
59
|
export function useFullScreenElement() {
|
|
61
|
-
|
|
62
|
-
getFullScreenElement,
|
|
63
|
-
);
|
|
64
|
-
useEventListener(document, "fullscreenchange", () => {
|
|
65
|
-
setFullScreenElement(getFullScreenElement());
|
|
66
|
-
});
|
|
67
|
-
return fullScreenElement;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const fullScreenSubscribers = new Set<() => void>();
|
|
71
|
-
|
|
72
|
-
function notifyFullScreenSubscribers() {
|
|
73
|
-
for (const subscriber of fullScreenSubscribers) {
|
|
74
|
-
subscriber();
|
|
75
|
-
}
|
|
60
|
+
return useSyncExternalStore(subscribeToFullScreen, getFullScreenElement);
|
|
76
61
|
}
|
|
77
62
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
function subscribeToFullScreen(onStoreChange: () => void) {
|
|
83
|
-
if (fullScreenSubscribers.size === 0) {
|
|
84
|
-
document.addEventListener("fullscreenchange", notifyFullScreenSubscribers);
|
|
85
|
-
}
|
|
86
|
-
fullScreenSubscribers.add(onStoreChange);
|
|
87
|
-
|
|
88
|
-
return () => {
|
|
89
|
-
fullScreenSubscribers.delete(onStoreChange);
|
|
90
|
-
if (fullScreenSubscribers.size === 0) {
|
|
91
|
-
document.removeEventListener(
|
|
92
|
-
"fullscreenchange",
|
|
93
|
-
notifyFullScreenSubscribers,
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
63
|
+
const subscribeToFullScreen = createSharedSubscription((notify) => {
|
|
64
|
+
document.addEventListener("fullscreenchange", notify);
|
|
65
|
+
return () => document.removeEventListener("fullscreenchange", notify);
|
|
66
|
+
});
|
|
98
67
|
|
|
99
68
|
/**
|
|
100
69
|
* Whether the given element is the full screen element.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { EditorView } from "@codemirror/view";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { createDebouncedEditorUpdate } from "../debounced-editor-update";
|
|
5
|
+
|
|
6
|
+
describe("debounced editor updates", () => {
|
|
7
|
+
let view: EditorView;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
vi.useFakeTimers();
|
|
10
|
+
view = new EditorView({ doc: "initial" });
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
view.destroy();
|
|
14
|
+
vi.useRealTimers();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("coalesces invalidations and reads the latest state at dispatch time", async () => {
|
|
18
|
+
const compute = vi.fn(() => ({
|
|
19
|
+
selection: { anchor: view.state.doc.length },
|
|
20
|
+
}));
|
|
21
|
+
const update = createDebouncedEditorUpdate(view, compute);
|
|
22
|
+
const dispatch = vi.spyOn(view, "dispatch");
|
|
23
|
+
for (let i = 0; i < 500; i++) {
|
|
24
|
+
update.schedule();
|
|
25
|
+
}
|
|
26
|
+
vi.advanceTimersByTime(300);
|
|
27
|
+
expect(compute).not.toHaveBeenCalled();
|
|
28
|
+
view.dispatch({
|
|
29
|
+
changes: { from: 0, to: view.state.doc.length, insert: "latest" },
|
|
30
|
+
});
|
|
31
|
+
dispatch.mockClear();
|
|
32
|
+
await Promise.resolve();
|
|
33
|
+
expect(compute).toHaveBeenCalledOnce();
|
|
34
|
+
expect(dispatch).toHaveBeenCalledOnce();
|
|
35
|
+
expect(view.state.selection.main.anchor).toBe(6);
|
|
36
|
+
update.destroy();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it.each([false, true])(
|
|
40
|
+
"cancels work on destroy (already queued: %s)",
|
|
41
|
+
async (queued) => {
|
|
42
|
+
const compute = vi.fn(() => ({}));
|
|
43
|
+
const update = createDebouncedEditorUpdate(view, compute);
|
|
44
|
+
update.schedule();
|
|
45
|
+
if (queued) {
|
|
46
|
+
vi.advanceTimersByTime(300);
|
|
47
|
+
}
|
|
48
|
+
update.destroy();
|
|
49
|
+
update.destroy();
|
|
50
|
+
update.schedule();
|
|
51
|
+
vi.advanceTimersByTime(300);
|
|
52
|
+
await Promise.resolve();
|
|
53
|
+
expect(compute).not.toHaveBeenCalled();
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
it("supersedes queued work when invalidated again", async () => {
|
|
58
|
+
const compute = vi.fn(() => undefined);
|
|
59
|
+
const update = createDebouncedEditorUpdate(view, compute);
|
|
60
|
+
const dispatch = vi.spyOn(view, "dispatch");
|
|
61
|
+
update.schedule();
|
|
62
|
+
vi.advanceTimersByTime(300);
|
|
63
|
+
update.schedule();
|
|
64
|
+
await Promise.resolve();
|
|
65
|
+
expect(compute).not.toHaveBeenCalled();
|
|
66
|
+
vi.advanceTimersByTime(300);
|
|
67
|
+
await Promise.resolve();
|
|
68
|
+
expect(compute).toHaveBeenCalledOnce();
|
|
69
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
70
|
+
update.destroy();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -4,9 +4,13 @@ import { defaultUserConfig } from "@/core/config/config-schema";
|
|
|
4
4
|
|
|
5
5
|
import { EditorState, type Extension } from "@codemirror/state";
|
|
6
6
|
import { EditorView, keymap } from "@codemirror/view";
|
|
7
|
-
import { describe, expect, test, vi } from "vitest";
|
|
7
|
+
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
8
8
|
import { cellId } from "@/__tests__/branded";
|
|
9
|
+
import { configOverridesAtom } from "@/core/config/config";
|
|
10
|
+
import type { ExperimentalFeatures } from "@/core/config/feature-flag";
|
|
9
11
|
import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
|
|
12
|
+
import { store } from "@/core/state/jotai";
|
|
13
|
+
import { invariant } from "@/utils/invariant";
|
|
10
14
|
import { Objects } from "@/utils/objects";
|
|
11
15
|
import type { CodemirrorCellActions } from "../cells/state";
|
|
12
16
|
import { type CodeMirrorSetupOpts, setupCodeMirror } from "../cm";
|
|
@@ -273,3 +277,59 @@ test("empty-cell AI action opens chat without invoking the local refactor prompt
|
|
|
273
277
|
view.destroy();
|
|
274
278
|
}
|
|
275
279
|
});
|
|
280
|
+
|
|
281
|
+
describe("editor styles are shared between cells", () => {
|
|
282
|
+
afterEach(() => {
|
|
283
|
+
store.set(configOverridesAtom, {});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test.each([
|
|
287
|
+
["default", {}, {}],
|
|
288
|
+
["clickable placeholder", { enableAIChat: true }, {}],
|
|
289
|
+
["debugger", {}, { debugger: true }],
|
|
290
|
+
["line timing", {}, { line_timing: true }],
|
|
291
|
+
] satisfies [
|
|
292
|
+
string,
|
|
293
|
+
Partial<CodeMirrorSetupOpts>,
|
|
294
|
+
Partial<ExperimentalFeatures>,
|
|
295
|
+
][])(
|
|
296
|
+
"no style module is built per editor (%s)",
|
|
297
|
+
(_name, config, experimental) => {
|
|
298
|
+
store.set(configOverridesAtom, { experimental });
|
|
299
|
+
const styleModules = () =>
|
|
300
|
+
EditorState.create({ extensions: setup(config) }).facet(
|
|
301
|
+
EditorView.styleModule,
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const first = styleModules();
|
|
305
|
+
const second = styleModules();
|
|
306
|
+
|
|
307
|
+
expect(second).toHaveLength(first.length);
|
|
308
|
+
const perEditor = second.filter((mod, i) => mod !== first[i]);
|
|
309
|
+
expect(perEditor.map((mod) => mod.getRules())).toEqual([]);
|
|
310
|
+
},
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
test("mounting another editor does not rewrite the stylesheet", () => {
|
|
314
|
+
const mount = () =>
|
|
315
|
+
new EditorView({
|
|
316
|
+
state: EditorState.create({ extensions: setup() }),
|
|
317
|
+
parent: document.body,
|
|
318
|
+
});
|
|
319
|
+
const first = mount();
|
|
320
|
+
const styleTag = document.head.querySelector("style");
|
|
321
|
+
invariant(styleTag, "CodeMirror did not mount a style tag");
|
|
322
|
+
const observer = new MutationObserver(() => undefined);
|
|
323
|
+
observer.observe(styleTag, { childList: true, characterData: true });
|
|
324
|
+
|
|
325
|
+
const second = mount();
|
|
326
|
+
|
|
327
|
+
try {
|
|
328
|
+
expect(observer.takeRecords()).toEqual([]);
|
|
329
|
+
} finally {
|
|
330
|
+
observer.disconnect();
|
|
331
|
+
first.destroy();
|
|
332
|
+
second.destroy();
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
});
|
|
@@ -71,6 +71,12 @@ class CurrentLineHighlighter implements PluginValue {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
const debuggerLineTheme = EditorView.theme({
|
|
75
|
+
".cm-debugger-current-line": {
|
|
76
|
+
backgroundColor: "color-mix(in srgb, var(--amber-4) 50%, transparent)",
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
74
80
|
/** Highlight the line a cell's frame watcher is currently executing. */
|
|
75
81
|
export function debuggerLineHighlighter(
|
|
76
82
|
lineObservable: Observable<number | null>,
|
|
@@ -80,11 +86,7 @@ export function debuggerLineHighlighter(
|
|
|
80
86
|
(view) => new CurrentLineHighlighter(view, lineObservable),
|
|
81
87
|
{ decorations: (plugin) => plugin.decorations },
|
|
82
88
|
),
|
|
83
|
-
|
|
84
|
-
".cm-debugger-current-line": {
|
|
85
|
-
backgroundColor: "color-mix(in srgb, var(--amber-4) 50%, transparent)",
|
|
86
|
-
},
|
|
87
|
-
}),
|
|
89
|
+
debuggerLineTheme,
|
|
88
90
|
];
|
|
89
91
|
}
|
|
90
92
|
|
|
@@ -155,6 +157,20 @@ class BreakpointSync implements PluginValue {
|
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
|
|
160
|
+
const breakpointGutterTheme = EditorView.theme({
|
|
161
|
+
".cm-breakpoint-gutter": {
|
|
162
|
+
width: "14px",
|
|
163
|
+
cursor: "pointer",
|
|
164
|
+
},
|
|
165
|
+
".cm-breakpoint-marker": {
|
|
166
|
+
width: "8px",
|
|
167
|
+
height: "8px",
|
|
168
|
+
borderRadius: "50%",
|
|
169
|
+
backgroundColor: "var(--red-9)",
|
|
170
|
+
margin: "4px auto",
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
158
174
|
/** A clickable gutter for toggling breakpoints on a cell's lines. */
|
|
159
175
|
export function breakpointGutter(
|
|
160
176
|
cellId: CellId,
|
|
@@ -177,18 +193,6 @@ export function breakpointGutter(
|
|
|
177
193
|
},
|
|
178
194
|
},
|
|
179
195
|
}),
|
|
180
|
-
|
|
181
|
-
".cm-breakpoint-gutter": {
|
|
182
|
-
width: "14px",
|
|
183
|
-
cursor: "pointer",
|
|
184
|
-
},
|
|
185
|
-
".cm-breakpoint-marker": {
|
|
186
|
-
width: "8px",
|
|
187
|
-
height: "8px",
|
|
188
|
-
borderRadius: "50%",
|
|
189
|
-
backgroundColor: "var(--red-9)",
|
|
190
|
-
margin: "4px auto",
|
|
191
|
-
},
|
|
192
|
-
}),
|
|
196
|
+
breakpointGutterTheme,
|
|
193
197
|
];
|
|
194
198
|
}
|
|
@@ -138,6 +138,18 @@ class ActiveLineTimer implements PluginValue {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
const lineTimingTheme = EditorView.theme({
|
|
142
|
+
".cm-timing-current-line": {
|
|
143
|
+
backgroundColor: "color-mix(in srgb, var(--grass-4) 50%, transparent)",
|
|
144
|
+
},
|
|
145
|
+
".cm-line-timer": {
|
|
146
|
+
color: "var(--grass-11)",
|
|
147
|
+
fontSize: "0.85em",
|
|
148
|
+
marginLeft: "1.5ch",
|
|
149
|
+
pointerEvents: "none",
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
141
153
|
/**
|
|
142
154
|
* Highlight the line a cell's frame watcher is currently executing in green,
|
|
143
155
|
* with a dim elapsed-time pill at the end of the line once it has been busy
|
|
@@ -150,16 +162,6 @@ export function activeLineTimer(
|
|
|
150
162
|
ViewPlugin.define((view) => new ActiveLineTimer(view, infoObservable), {
|
|
151
163
|
decorations: (plugin) => plugin.decorations,
|
|
152
164
|
}),
|
|
153
|
-
|
|
154
|
-
".cm-timing-current-line": {
|
|
155
|
-
backgroundColor: "color-mix(in srgb, var(--grass-4) 50%, transparent)",
|
|
156
|
-
},
|
|
157
|
-
".cm-line-timer": {
|
|
158
|
-
color: "var(--grass-11)",
|
|
159
|
-
fontSize: "0.85em",
|
|
160
|
-
marginLeft: "1.5ch",
|
|
161
|
-
pointerEvents: "none",
|
|
162
|
-
},
|
|
163
|
-
}),
|
|
165
|
+
lineTimingTheme,
|
|
164
166
|
];
|
|
165
167
|
}
|
|
@@ -137,21 +137,20 @@ function createErrorHighlighter(errorsObservable: Observable<TracebackInfos>) {
|
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
const errorLineTheme = EditorView.theme({
|
|
141
|
+
".cm-error-line": {
|
|
142
|
+
backgroundColor: "color-mix(in srgb, var(--red-4) 40%, transparent)",
|
|
143
|
+
},
|
|
144
|
+
"&.cm-focused .cm-error-line.cm-activeLine": {
|
|
145
|
+
backgroundColor: "color-mix(in srgb, var(--red-5) 40%, transparent)",
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
140
149
|
/**
|
|
141
150
|
* Create an extension that highlights error lines in the editor.
|
|
142
151
|
*/
|
|
143
152
|
export function errorLineHighlighter(
|
|
144
153
|
errorsObservable: Observable<TracebackInfos>,
|
|
145
154
|
): Extension {
|
|
146
|
-
return [
|
|
147
|
-
createErrorHighlighter(errorsObservable),
|
|
148
|
-
EditorView.theme({
|
|
149
|
-
".cm-error-line": {
|
|
150
|
-
backgroundColor: "color-mix(in srgb, var(--red-4) 40%, transparent)",
|
|
151
|
-
},
|
|
152
|
-
"&.cm-focused .cm-error-line.cm-activeLine": {
|
|
153
|
-
backgroundColor: "color-mix(in srgb, var(--red-5) 40%, transparent)",
|
|
154
|
-
},
|
|
155
|
-
}),
|
|
156
|
-
];
|
|
155
|
+
return [createErrorHighlighter(errorsObservable), errorLineTheme];
|
|
157
156
|
}
|
|
@@ -149,6 +149,37 @@ describe("codeLensBundle", () => {
|
|
|
149
149
|
expect(codeLensBundle(cellId("cell1"), false)).toEqual([]);
|
|
150
150
|
});
|
|
151
151
|
|
|
152
|
+
it.each([false, true])(
|
|
153
|
+
"skips unchanged lenses (with lens: %s)",
|
|
154
|
+
async (withLens) => {
|
|
155
|
+
seedStore({ tables: withLens ? [DF_TABLE] : [] });
|
|
156
|
+
const v = await mount("df = load()");
|
|
157
|
+
const dispatch = vi.spyOn(v, "dispatch");
|
|
158
|
+
store.set(variablesAtom, {});
|
|
159
|
+
vi.advanceTimersByTime(300);
|
|
160
|
+
await Promise.resolve();
|
|
161
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
it("refreshes widget positions after edits and clears removed entities", async () => {
|
|
166
|
+
seedStore({ tables: [DF_TABLE] });
|
|
167
|
+
const v = await mount("df = load()");
|
|
168
|
+
v.dispatch({ changes: { from: 0, insert: "\n" } });
|
|
169
|
+
vi.advanceTimersByTime(300);
|
|
170
|
+
await Promise.resolve();
|
|
171
|
+
lenses(v)[0].dispatchEvent(new MouseEvent("mouseenter"));
|
|
172
|
+
vi.advanceTimersByTime(CODE_LENS_HOVER_DELAY_MS);
|
|
173
|
+
expect(mountLensPopover).toHaveBeenLastCalledWith(
|
|
174
|
+
expect.any(HTMLElement),
|
|
175
|
+
expect.objectContaining({ pos: 3 }),
|
|
176
|
+
);
|
|
177
|
+
seedStore({});
|
|
178
|
+
vi.advanceTimersByTime(300);
|
|
179
|
+
await Promise.resolve();
|
|
180
|
+
expect(lenses(v)).toEqual([]);
|
|
181
|
+
});
|
|
182
|
+
|
|
152
183
|
it("renders a lens at a dataframe declaration", async () => {
|
|
153
184
|
seedStore({ tables: [DF_TABLE] });
|
|
154
185
|
const v = await mount("df = load()\nx = 1");
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
type ViewUpdate,
|
|
12
12
|
WidgetType,
|
|
13
13
|
} from "@codemirror/view";
|
|
14
|
-
import {
|
|
14
|
+
import { createDebouncedEditorUpdate } from "../debounced-editor-update";
|
|
15
15
|
import type { CellId } from "@/core/cells/ids";
|
|
16
16
|
import { getFeatureFlag } from "@/core/config/feature-flag";
|
|
17
17
|
import { dataConnectionsMapAtom } from "@/core/datasets/data-source-connections";
|
|
@@ -277,16 +277,14 @@ class CodeLensPlugin {
|
|
|
277
277
|
private readonly includeCache: boolean;
|
|
278
278
|
private readonly unsubscribes: Array<() => void>;
|
|
279
279
|
|
|
280
|
-
|
|
281
|
-
private readonly debounceMs = 300;
|
|
282
|
-
private readonly scheduleUpdate: DebouncedFunc<() => void>;
|
|
280
|
+
private readonly lensUpdate: ReturnType<typeof createDebouncedEditorUpdate>;
|
|
283
281
|
|
|
284
282
|
public constructor(view: EditorView, cellId: CellId, includeCache: boolean) {
|
|
285
283
|
this.view = view;
|
|
286
284
|
this.cellId = cellId;
|
|
287
285
|
this.includeCache = includeCache;
|
|
288
|
-
this.
|
|
289
|
-
const onStoreChange = () => this.
|
|
286
|
+
this.lensUpdate = createDebouncedEditorUpdate(view, () => this.run());
|
|
287
|
+
const onStoreChange = () => this.lensUpdate.schedule();
|
|
290
288
|
this.unsubscribes = [
|
|
291
289
|
store.sub(datasetTablesAtom, onStoreChange),
|
|
292
290
|
store.sub(dataConnectionsMapAtom, onStoreChange),
|
|
@@ -294,7 +292,7 @@ class CodeLensPlugin {
|
|
|
294
292
|
// The declaring-cell filter depends on variables
|
|
295
293
|
store.sub(variablesAtom, onStoreChange),
|
|
296
294
|
];
|
|
297
|
-
this.
|
|
295
|
+
this.lensUpdate.schedule();
|
|
298
296
|
}
|
|
299
297
|
|
|
300
298
|
public update(update: ViewUpdate) {
|
|
@@ -303,18 +301,22 @@ class CodeLensPlugin {
|
|
|
303
301
|
const adapterChanged =
|
|
304
302
|
update.startState.field(languageAdapterState, false)?.type !==
|
|
305
303
|
update.state.field(languageAdapterState, false)?.type;
|
|
304
|
+
this.documentChanged ||= update.docChanged;
|
|
306
305
|
if (update.docChanged || adapterChanged) {
|
|
307
|
-
this.
|
|
306
|
+
this.lensUpdate.schedule();
|
|
308
307
|
}
|
|
309
308
|
}
|
|
310
309
|
|
|
311
310
|
public destroy() {
|
|
312
|
-
this.
|
|
311
|
+
this.lensUpdate.destroy();
|
|
313
312
|
for (const unsubscribe of this.unsubscribes) {
|
|
314
313
|
unsubscribe();
|
|
315
314
|
}
|
|
316
315
|
}
|
|
317
316
|
|
|
317
|
+
private previousLenses: CodeLensSpec[] = [];
|
|
318
|
+
private documentChanged = false;
|
|
319
|
+
|
|
318
320
|
private run() {
|
|
319
321
|
const { state } = this.view;
|
|
320
322
|
const lenses: CodeLensSpec[] = [];
|
|
@@ -346,10 +348,16 @@ class CodeLensPlugin {
|
|
|
346
348
|
}
|
|
347
349
|
}
|
|
348
350
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
351
|
+
if (
|
|
352
|
+
!this.documentChanged &&
|
|
353
|
+
lenses.length === this.previousLenses.length &&
|
|
354
|
+
lenses.every((lens, i) => specEquals(lens, this.previousLenses[i]))
|
|
355
|
+
) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
this.previousLenses = lenses;
|
|
359
|
+
this.documentChanged = false;
|
|
360
|
+
return { effects: setCodeLenses.of(lenses) };
|
|
353
361
|
}
|
|
354
362
|
}
|
|
355
363
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import type { TransactionSpec } from "@codemirror/state";
|
|
3
|
+
import type { EditorView } from "@codemirror/view";
|
|
4
|
+
import { debounce } from "lodash-es";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Coalesce invalidations and compute against the latest state outside CM's
|
|
8
|
+
* update cycle. Return undefined from compute when nothing needs dispatching.
|
|
9
|
+
* destroy cancels both the timer and any already queued microtask.
|
|
10
|
+
*/
|
|
11
|
+
export function createDebouncedEditorUpdate(
|
|
12
|
+
view: EditorView,
|
|
13
|
+
compute: () => TransactionSpec | undefined,
|
|
14
|
+
delay = 300,
|
|
15
|
+
) {
|
|
16
|
+
let destroyed = false;
|
|
17
|
+
let generation = 0;
|
|
18
|
+
const run = debounce((scheduledGeneration: number) => {
|
|
19
|
+
queueMicrotask(() => {
|
|
20
|
+
if (destroyed || scheduledGeneration !== generation) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const transaction = compute();
|
|
24
|
+
if (transaction) {
|
|
25
|
+
view.dispatch(transaction);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}, delay);
|
|
29
|
+
return {
|
|
30
|
+
schedule() {
|
|
31
|
+
if (!destroyed) {
|
|
32
|
+
run(++generation);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
destroy() {
|
|
36
|
+
destroyed = true;
|
|
37
|
+
generation++;
|
|
38
|
+
run.cancel();
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { python } from "@codemirror/lang-python";
|
|
3
|
+
import { EditorView } from "@codemirror/view";
|
|
4
|
+
import { expect, it, vi } from "vitest";
|
|
5
|
+
import { createUnderlinePlugin, underlineField } from "../underline";
|
|
6
|
+
|
|
7
|
+
it("shares modifier listeners and clears underlines on blur", () => {
|
|
8
|
+
const add = vi.spyOn(window, "addEventListener");
|
|
9
|
+
const remove = vi.spyOn(window, "removeEventListener");
|
|
10
|
+
const views = Array.from(
|
|
11
|
+
{ length: 20 },
|
|
12
|
+
() =>
|
|
13
|
+
new EditorView({
|
|
14
|
+
doc: "value",
|
|
15
|
+
extensions: [python(), underlineField, createUnderlinePlugin(vi.fn())],
|
|
16
|
+
parent: document.body,
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
const events = new Set(["keydown", "keyup", "blur", "mouseleave"]);
|
|
20
|
+
expect(add.mock.calls.filter(([name]) => events.has(name))).toHaveLength(4);
|
|
21
|
+
const view = views[0];
|
|
22
|
+
vi.spyOn(view, "posAtCoords").mockReturnValue(2);
|
|
23
|
+
view.dom.dispatchEvent(new MouseEvent("mousemove", { ctrlKey: true }));
|
|
24
|
+
expect(view.state.field(underlineField).size).toBe(1);
|
|
25
|
+
window.dispatchEvent(new Event("blur"));
|
|
26
|
+
expect(view.state.field(underlineField).size).toBe(0);
|
|
27
|
+
for (const view of views) {
|
|
28
|
+
view.destroy();
|
|
29
|
+
}
|
|
30
|
+
expect(remove.mock.calls.filter(([name]) => events.has(name))).toHaveLength(
|
|
31
|
+
4,
|
|
32
|
+
);
|
|
33
|
+
vi.restoreAllMocks();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("keeps navigation active until both modifiers are released", () => {
|
|
37
|
+
const navigate = vi.fn();
|
|
38
|
+
const view = new EditorView({
|
|
39
|
+
doc: "value",
|
|
40
|
+
extensions: [python(), underlineField, createUnderlinePlugin(navigate)],
|
|
41
|
+
});
|
|
42
|
+
vi.spyOn(view, "posAtCoords").mockReturnValue(2);
|
|
43
|
+
view.dom.dispatchEvent(
|
|
44
|
+
new MouseEvent("mousemove", { ctrlKey: true, metaKey: true }),
|
|
45
|
+
);
|
|
46
|
+
window.dispatchEvent(
|
|
47
|
+
new KeyboardEvent("keyup", { key: "Meta", ctrlKey: true }),
|
|
48
|
+
);
|
|
49
|
+
expect(view.state.field(underlineField).size).toBe(1);
|
|
50
|
+
view.dom.dispatchEvent(new MouseEvent("click", { ctrlKey: true }));
|
|
51
|
+
expect(navigate).toHaveBeenCalledWith(view);
|
|
52
|
+
window.dispatchEvent(new KeyboardEvent("keyup", { key: "Control" }));
|
|
53
|
+
expect(view.state.field(underlineField).size).toBe(0);
|
|
54
|
+
navigate.mockClear();
|
|
55
|
+
view.dom.dispatchEvent(new MouseEvent("click"));
|
|
56
|
+
expect(navigate).not.toHaveBeenCalled();
|
|
57
|
+
view.destroy();
|
|
58
|
+
});
|
|
@@ -3,6 +3,14 @@ import { EditorView } from "@codemirror/view";
|
|
|
3
3
|
import { createUnderlinePlugin, underlineField } from "./underline";
|
|
4
4
|
import { goToDefinitionWithLspFallback } from "./utils";
|
|
5
5
|
|
|
6
|
+
const underlineTheme = EditorView.baseTheme({
|
|
7
|
+
".underline": {
|
|
8
|
+
textDecoration: "underline",
|
|
9
|
+
cursor: "pointer",
|
|
10
|
+
color: "var(--link)",
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
6
14
|
/**
|
|
7
15
|
* Create a go-to-definition extension.
|
|
8
16
|
*/
|
|
@@ -12,12 +20,6 @@ export function goToDefinitionBundle() {
|
|
|
12
20
|
createUnderlinePlugin((view) => {
|
|
13
21
|
goToDefinitionWithLspFallback(view);
|
|
14
22
|
}),
|
|
15
|
-
|
|
16
|
-
".underline": {
|
|
17
|
-
textDecoration: "underline",
|
|
18
|
-
cursor: "pointer",
|
|
19
|
-
color: "var(--link)",
|
|
20
|
-
},
|
|
21
|
-
}),
|
|
23
|
+
underlineTheme,
|
|
22
24
|
];
|
|
23
25
|
}
|