@marimo-team/islands 0.26.1-dev105 → 0.26.1-dev112

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.
Files changed (117) hide show
  1. package/dist/{ConnectedDataExplorerComponent-C6dY5fiI.js → ConnectedDataExplorerComponent-DQaiOY7w.js} +15 -15
  2. package/dist/{ErrorBoundary-Bn664FZa.js → ErrorBoundary-pNKOBKXw.js} +19 -19
  3. package/dist/{abnfDiagram-VCTEODGH-Ba0MYVW8.js → abnfDiagram-VCTEODGH-Df80tEYq.js} +2 -2
  4. package/dist/{any-language-editor-BNe8do3C.js → any-language-editor-BW-gNmbk.js} +2 -2
  5. package/dist/{architectureDiagram-5GKGNRK7-7MqAehef.js → architectureDiagram-5GKGNRK7-DNNMvKkY.js} +1 -1
  6. package/dist/{assertNever-5vhHGKOK.js → assertNever-B9_7z-dW.js} +13 -13
  7. package/dist/{chat-ui-zGgiq5zN.js → chat-ui-C9NZA-bk.js} +49 -49
  8. package/dist/{check-DUIc04aK.js → check-BqF09bSG.js} +1 -1
  9. package/dist/{chunk-IMKFNOWR-CAWA0HGB.js → chunk-IMKFNOWR-pXqnQ_fj.js} +1 -1
  10. package/dist/{chunk-SHT3W25Y-BIwVQjG5.js → chunk-SHT3W25Y-BWrxB3I2.js} +1 -1
  11. package/dist/{chunk-SVP7TREG-Cux251TB.js → chunk-SVP7TREG-CPdQP8_U.js} +1 -1
  12. package/dist/{chunk-TICWLB2K-DJVQ6khO.js → chunk-TICWLB2K-C5MYCwBz.js} +1 -1
  13. package/dist/{circle-question-mark-evCnVIut.js → circle-question-mark-YmLYXyvS.js} +1 -1
  14. package/dist/{classDiagram-ZZMXUADV-Cwve77ev.js → classDiagram-ZZMXUADV-Ba0SRm01.js} +2 -2
  15. package/dist/{classDiagram-v2-VYDZK3BY-BAeHKXmD.js → classDiagram-v2-VYDZK3BY-DSSzL_Dk.js} +2 -2
  16. package/dist/{code-visibility-CMgSFUs7.js → code-visibility-B9s3Hl8z.js} +18 -18
  17. package/dist/{common-DWnR77Qk.js → common-Bn3jx0X6.js} +170 -168
  18. package/dist/{copy-icon-CmNLxT5_.js → copy-icon-zP4__HPI.js} +2 -2
  19. package/dist/{createReducer-m7yAXmDu.js → createReducer-CArOwUaJ.js} +1 -1
  20. package/dist/{cynefinDiagram-5FMLGOSQ-t4eEkPJh.js → cynefinDiagram-5FMLGOSQ-BOtNvA04.js} +1 -1
  21. package/dist/{dagre-GXQ25YYZ-IuZuI28B.js → dagre-GXQ25YYZ-FpCEOTxX.js} +1 -1
  22. package/dist/{data-grid-overlay-editor-zS1h3iMI.js → data-grid-overlay-editor-mxwwRaQy.js} +1 -1
  23. package/dist/{diagram-S7CK7UJ4-D8R5Q_ok.js → diagram-S7CK7UJ4-Cm1HaBuu.js} +1 -1
  24. package/dist/{diagram-UQ7AKVKN-BGuMPsr-.js → diagram-UQ7AKVKN-D1lA7Ggu.js} +1 -1
  25. package/dist/{diagram-VX7I27RA-BkTtpO8P.js → diagram-VX7I27RA-BX3e-Rue.js} +1 -1
  26. package/dist/{diagram-Z3DM3KII-C0__Mxfm.js → diagram-Z3DM3KII-Dgoj7bPf.js} +1 -1
  27. package/dist/{dialog-BvjfalZ9.js → dialog-DfKgafXJ.js} +30 -30
  28. package/dist/{dropdown-menu-D0DeN-aL.js → dropdown-menu-Dge_SmqE.js} +168 -168
  29. package/dist/{ebnfDiagram-PWID7BFC-CSESPZoz.js → ebnfDiagram-PWID7BFC-B0xWiXrz.js} +2 -2
  30. package/dist/{erDiagram-RLTQ6QDP-DsDTtabH.js → erDiagram-RLTQ6QDP-Cm-GO31-.js} +1 -1
  31. package/dist/{error-banner-CXLjTW24.js → error-banner-CfYrJaIb.js} +91 -91
  32. package/dist/{error-entries-DVclFjaE.js → error-entries-1DC4BiYB.js} +661 -656
  33. package/dist/{export-context-CkgZeARR.js → export-context-B1jdxzHF.js} +21 -21
  34. package/dist/{feedback-button-BMGqp8Ff.js → feedback-button-BrzbnRTT.js} +72 -72
  35. package/dist/{flowDiagram-HODETNUW-qxDPYbfV.js → flowDiagram-HODETNUW-CH6xMlW_.js} +2 -2
  36. package/dist/{formats-CcQrzFo8.js → formats-Y52bg800.js} +1 -1
  37. package/dist/{glide-data-editor-Bra6h4KB.js → glide-data-editor-Cnsv3NcI.js} +11 -11
  38. package/dist/{glide-utils-CD8BaFTm.js → glide-utils-BRcuSTCx.js} +2 -2
  39. package/dist/{globals-_bXqC0R8.js → globals-BGqfFPx8.js} +3 -3
  40. package/dist/{html-to-image-Cst4BlIm.js → html-to-image-CsvAOgd3.js} +5073 -5076
  41. package/dist/{infoDiagram-27XIBGKW-B5hq8RM_.js → infoDiagram-27XIBGKW-DbUO63CX.js} +1 -1
  42. package/dist/{ishikawaDiagram-5VMMS53U-DkHc_9ET.js → ishikawaDiagram-5VMMS53U-CfQrrELH.js} +1 -1
  43. package/dist/{kanban-definition-UXKFOSKX-CqkTFXmU.js → kanban-definition-UXKFOSKX-C5SJcu1W.js} +1 -1
  44. package/dist/{loader-CGrYn73j.js → loader-C9-qRO3m.js} +2 -2
  45. package/dist/main.js +6696 -6602
  46. package/dist/{mermaid-pmVHDUQA.js → mermaid-C2alqcd8.js} +34 -34
  47. package/dist/{mindmap-definition-YA3MSWOX-D6cNa__z.js → mindmap-definition-YA3MSWOX-ByVHE0Ax.js} +1 -1
  48. package/dist/{number-overlay-editor-XLUhOVa7.js → number-overlay-editor-DuSCOMTK.js} +1 -1
  49. package/dist/{pegDiagram-XKGWAZYB-CmWJX_s1.js → pegDiagram-XKGWAZYB-DF5FBKZi.js} +2 -2
  50. package/dist/{pencil-CxMgOe04.js → pencil-D7jyZPnP.js} +1 -1
  51. package/dist/{pieDiagram-E7YTZNPT-CAQAxHah.js → pieDiagram-E7YTZNPT-B5n9nBQN.js} +1 -1
  52. package/dist/{process-output-DizFa5IE.js → process-output-CtfJ_Gbp.js} +4 -4
  53. package/dist/{railroadDiagram-O6MQD6OU-jlSsiQg3.js → railroadDiagram-O6MQD6OU-r5t7OYNE.js} +2 -2
  54. package/dist/{requirementDiagram-BXWQKSXE-DkDjfPhn.js → requirementDiagram-BXWQKSXE-D4QtEyZQ.js} +1 -1
  55. package/dist/{reveal-component-llpC324_.js → reveal-component-DzmiQyN9.js} +1008 -1008
  56. package/dist/{select-CEnB18uc.js → select-Buk3aXi1.js} +341 -341
  57. package/dist/{sequenceDiagram-WJ2MYXX4-DLywsGCW.js → sequenceDiagram-WJ2MYXX4-CK3Atn-z.js} +1 -1
  58. package/dist/{spec-Dz-Avv1m.js → spec-BEp9O9dy.js} +4 -4
  59. package/dist/{stateDiagram-D77RDMKH-DUmlKwYU.js → stateDiagram-D77RDMKH-C1SxRI8V.js} +2 -2
  60. package/dist/{stateDiagram-v2-MP3YSRHH-D646KiXs.js → stateDiagram-v2-MP3YSRHH-DK5X6bsr.js} +2 -2
  61. package/dist/{static-state-iw0PrHK4.js → static-state-D-aT9dOr.js} +9 -9
  62. package/dist/style.css +1 -1
  63. package/dist/{swimlanes-42K2YHIH-L7B1GphF.js → swimlanes-42K2YHIH-DdH5TZdu.js} +1 -1
  64. package/dist/{swimlanesDiagram-VR7AAH4N-DEu2wxtC.js → swimlanesDiagram-VR7AAH4N-CWBIvzgR.js} +2 -2
  65. package/dist/{timeline-definition-24CTP7MA-DDPyx1yG.js → timeline-definition-24CTP7MA-DE7-o2zU.js} +1 -1
  66. package/dist/{toast-BTjH6fIf.js → toast-b3k4YxaT.js} +54 -54
  67. package/dist/{tooltip-DyLdBIM4.js → tooltip-D-9pDheN.js} +62 -62
  68. package/dist/{use-restore-focus-DJ_-uSn_.js → use-restore-focus-CCfk-ey2.js} +1 -1
  69. package/dist/{useDateFormatter-HpKD0jEC.js → useDateFormatter-DH0uFwfL.js} +2 -2
  70. package/dist/{useDeepCompareMemoize-CHx-NxMl.js → useDeepCompareMemoize-Dn-ZJVTd.js} +1 -1
  71. package/dist/{useLifecycle-tPpAt-OE.js → useLifecycle-yjK7JsRL.js} +1 -1
  72. package/dist/{vega-component-BzNDFvQf.js → vega-component-BIq0qzhQ.js} +8 -8
  73. package/dist/{vennDiagram-4TSXK5OY-CRwWeb7g.js → vennDiagram-4TSXK5OY-D7yfNz0d.js} +1 -1
  74. package/dist/{wardleyDiagram-VM6X3IG4-DVlG9eoq.js → wardleyDiagram-VM6X3IG4-m5Jcz26Z.js} +1 -1
  75. package/dist/{xychartDiagram-S5SC5T6Z-CM32AISp.js → xychartDiagram-S5SC5T6Z-CA3zV3RW.js} +1 -1
  76. package/package.json +1 -1
  77. package/src/__mocks__/intersection-observer.ts +13 -12
  78. package/src/components/editor/Output.tsx +1 -1
  79. package/src/components/editor/__tests__/cell-renders.test.tsx +344 -2
  80. package/src/components/editor/ai/__tests__/completion-utils.test.ts +12 -20
  81. package/src/components/editor/ai/ai-completion-editor.tsx +391 -289
  82. package/src/components/editor/ai/completion-utils.ts +9 -7
  83. package/src/components/editor/cell/CellDeleteShoulder.tsx +82 -0
  84. package/src/components/editor/cell/DeleteButton.tsx +11 -2
  85. package/src/components/editor/cell/__tests__/CellDeleteShoulder.test.tsx +181 -0
  86. package/src/components/editor/cell/code/cell-editor.tsx +15 -25
  87. package/src/components/editor/chrome/panels/__tests__/logs-panel.test.tsx +26 -2
  88. package/src/components/editor/chrome/panels/logs-panel.tsx +27 -11
  89. package/src/components/editor/chrome/panels/outline/__tests__/outline-keyboard.test.tsx +517 -68
  90. package/src/components/editor/chrome/panels/outline/__tests__/useActiveOutline.test.ts +17 -5
  91. package/src/components/editor/chrome/panels/outline/floating-outline.tsx +29 -59
  92. package/src/components/editor/chrome/panels/outline/useActiveOutline.tsx +333 -133
  93. package/src/components/editor/chrome/panels/outline-panel.tsx +5 -19
  94. package/src/components/editor/notebook-cell.tsx +250 -274
  95. package/src/core/ai/state.ts +6 -0
  96. package/src/core/cells/__tests__/cells.test.ts +34 -20
  97. package/src/core/cells/__tests__/layout.test.ts +1 -1
  98. package/src/core/cells/__tests__/notebook-outline.test.ts +31 -3
  99. package/src/core/cells/cell-log-chunks.ts +31 -0
  100. package/src/core/cells/cells.ts +31 -20
  101. package/src/core/cells/outline.ts +8 -8
  102. package/src/core/codemirror/language/extension.ts +6 -3
  103. package/src/core/codemirror/language/panel/panel.test.tsx +144 -0
  104. package/src/core/codemirror/language/panel/panel.tsx +9 -6
  105. package/src/core/codemirror/lsp/__tests__/log-messages.test.ts +1 -1
  106. package/src/core/codemirror/lsp/__tests__/transports.test.ts +1 -1
  107. package/src/core/codemirror/react-dom/createPanel.tsx +15 -15
  108. package/src/core/dom/__tests__/outline.test.ts +29 -170
  109. package/src/core/dom/outline.ts +21 -61
  110. package/src/core/executions/atoms.ts +12 -4
  111. package/src/core/islands/__tests__/bridge.test.ts +2 -5
  112. package/src/core/islands/components/output-wrapper.tsx +7 -2
  113. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +10 -1
  114. package/src/css/common.css +11 -0
  115. package/src/hooks/useFinePointer.ts +30 -0
  116. package/src/plugins/layout/OutlinePlugin.tsx +5 -17
  117. package/src/stories/log-viewer.stories.tsx +48 -44
@@ -17,10 +17,6 @@ import { Logger } from "@/utils/Logger";
17
17
 
18
18
  export const CONTEXT_TRIGGER = "@";
19
19
 
20
- interface Opts {
21
- input: string;
22
- }
23
-
24
20
  interface AICompletionBodyWithAttachments {
25
21
  body: Omit<AiCompletionRequest, "language" | "prompt" | "code">;
26
22
  attachments: FileUIPart[];
@@ -31,7 +27,11 @@ interface AICompletionBodyWithAttachments {
31
27
  */
32
28
  export function getAICompletionBody({
33
29
  input,
34
- }: Opts): Omit<AiCompletionRequest, "language" | "prompt" | "code"> {
30
+ includeOtherCode,
31
+ }: {
32
+ input: string;
33
+ includeOtherCode: string;
34
+ }): Omit<AiCompletionRequest, "language" | "prompt" | "code"> {
35
35
  let contextString = "";
36
36
 
37
37
  // Skip if no '@' in the input
@@ -41,7 +41,7 @@ export function getAICompletionBody({
41
41
  }
42
42
 
43
43
  return {
44
- includeOtherCode: getCodes(""),
44
+ includeOtherCode,
45
45
  context: {
46
46
  plainText: contextString,
47
47
  schema: [],
@@ -175,7 +175,9 @@ export async function resolveChatContext(
175
175
  */
176
176
  export async function getAICompletionBodyWithAttachments({
177
177
  input,
178
- }: Opts): Promise<AICompletionBodyWithAttachments> {
178
+ }: {
179
+ input: string;
180
+ }): Promise<AICompletionBodyWithAttachments> {
179
181
  const { plainText, attachments } = await resolveContextAttachments(input);
180
182
 
181
183
  return {
@@ -0,0 +1,82 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { atom, useSetAtom } from "jotai";
4
+ import { useMemo } from "react";
5
+ import { cellFocusAtom } from "@/core/cells/focus";
6
+ import { outputIsLoading } from "@/core/cells/cell";
7
+ import type { CellId } from "@/core/cells/ids";
8
+ import type { CellRunStatus } from "@/core/executions";
9
+ import { isAppInteractionDisabled } from "@/core/session/connection-utils";
10
+ import { createKeyedAtomHook } from "@/core/state/create-keyed-atom-hook";
11
+ import type { ConnectionState } from "@/core/session/types";
12
+ import { useFinePointer } from "@/hooks/useFinePointer";
13
+ import { DeleteButton } from "./DeleteButton";
14
+ import { useDeleteCellCallback } from "./useDeleteCell";
15
+
16
+ const hoveredCellIdAtom = atom<CellId | null>(null);
17
+
18
+ /**
19
+ * Pointer handlers for a cell root. React delegates these events, so cells
20
+ * add no native listeners, and only the hovered cell's shoulder re-renders.
21
+ */
22
+ export function useCellHoverProps(cellId: CellId) {
23
+ const setHoveredCellId = useSetAtom(hoveredCellIdAtom);
24
+ return useMemo(
25
+ () => ({
26
+ onPointerEnter: () => setHoveredCellId(cellId),
27
+ onPointerLeave: () =>
28
+ setHoveredCellId((current) => (current === cellId ? null : current)),
29
+ }),
30
+ [cellId, setHoveredCellId],
31
+ );
32
+ }
33
+
34
+ const useIsCellActive = createKeyedAtomHook((cellId: CellId) =>
35
+ atom(
36
+ (get) =>
37
+ get(hoveredCellIdAtom) === cellId ||
38
+ get(cellFocusAtom).focusedCellId === cellId,
39
+ ),
40
+ );
41
+
42
+ /**
43
+ * The delete control at the bottom corner of a cell.
44
+ *
45
+ * The wrapper always renders, so layout and the hit area stay the same.
46
+ * With a fine pointer, the button mounts only while the cell is hovered or
47
+ * holds focus. Coarse pointers show the button at all times.
48
+ */
49
+ export const CellDeleteShoulder = ({
50
+ cellId,
51
+ status,
52
+ connectionState,
53
+ showButton,
54
+ }: {
55
+ cellId: CellId;
56
+ status: CellRunStatus;
57
+ connectionState: ConnectionState;
58
+ showButton: boolean;
59
+ }) => {
60
+ const deleteCell = useDeleteCellCallback();
61
+ const isFinePointer = useFinePointer();
62
+ const isActive = useIsCellActive(cellId);
63
+
64
+ return (
65
+ <div className="shoulder-bottom hover-action">
66
+ {showButton && (isActive || !isFinePointer) && (
67
+ <DeleteButton
68
+ status={status}
69
+ connectionState={connectionState}
70
+ onClick={() => {
71
+ if (
72
+ !outputIsLoading(status) &&
73
+ !isAppInteractionDisabled(connectionState)
74
+ ) {
75
+ deleteCell({ cellId });
76
+ }
77
+ }}
78
+ />
79
+ )}
80
+ </div>
81
+ );
82
+ };
@@ -46,11 +46,20 @@ export const DeleteButton = (props: {
46
46
  // This is needed to delete cells when the cell editor
47
47
  // is shown temporarily (e.g. when set to `hidden`)
48
48
  onMouseDown={Events.preventFocus}
49
+ onKeyDown={(evt) => {
50
+ // Keep native Enter/Space activation from reaching cell navigation.
51
+ if (
52
+ !Events.hasModifier(evt) &&
53
+ (evt.key === "Enter" || evt.key === " ")
54
+ ) {
55
+ evt.stopPropagation();
56
+ }
57
+ }}
49
58
  className={cn(
50
- "hover:bg-transparent text-destructive/60 hover:text-destructive",
59
+ // shadow-none keeps the focus ring, which an inline boxShadow removes.
60
+ "shadow-none hover:bg-transparent text-destructive/60 hover:text-destructive",
51
61
  (isDisabled || loading) && "inactive-button",
52
62
  )}
53
- style={{ boxShadow: "none" }}
54
63
  >
55
64
  <Trash2Icon size={14} />
56
65
  </Button>
@@ -0,0 +1,181 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { act, fireEvent, render, screen } from "@testing-library/react";
4
+ import { createStore, Provider } from "jotai";
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
+ import { cellFocusAtom } from "@/core/cells/focus";
7
+ import type { CellId } from "@/core/cells/ids";
8
+ import type { ConnectionState } from "@/core/session/types";
9
+ import { TooltipProvider } from "@/components/ui/tooltip";
10
+ import { CellDeleteShoulder, useCellHoverProps } from "../CellDeleteShoulder";
11
+
12
+ const deleteCell = vi.fn();
13
+ vi.mock("../useDeleteCell", () => ({
14
+ useDeleteCellCallback: () => deleteCell,
15
+ }));
16
+
17
+ const FINE_QUERY = "(hover: hover) and (pointer: fine)";
18
+
19
+ let finePointer = true;
20
+ const listeners = new Set<() => void>();
21
+
22
+ function setFinePointer(value: boolean) {
23
+ finePointer = value;
24
+ act(() => {
25
+ for (const listener of listeners) {
26
+ listener();
27
+ }
28
+ });
29
+ }
30
+
31
+ const CELL_A = "a" as CellId;
32
+ const CELL_B = "b" as CellId;
33
+
34
+ function Cell(props: {
35
+ cellId: CellId;
36
+ status?: "idle" | "running";
37
+ connectionState?: ConnectionState;
38
+ showButton?: boolean;
39
+ onKeyDown?: () => void;
40
+ }) {
41
+ const hoverProps = useCellHoverProps(props.cellId);
42
+ return (
43
+ <TooltipProvider>
44
+ <div
45
+ data-testid={`cell-${props.cellId}`}
46
+ onKeyDown={props.onKeyDown}
47
+ {...hoverProps}
48
+ >
49
+ <CellDeleteShoulder
50
+ cellId={props.cellId}
51
+ status={props.status ?? "idle"}
52
+ connectionState={props.connectionState ?? "OPEN"}
53
+ showButton={props.showButton ?? true}
54
+ />
55
+ </div>
56
+ </TooltipProvider>
57
+ );
58
+ }
59
+
60
+ function renderCells(cells = [CELL_A, CELL_B], store = createStore()) {
61
+ render(
62
+ <Provider store={store}>
63
+ {cells.map((id) => (
64
+ <Cell key={id} cellId={id} />
65
+ ))}
66
+ </Provider>,
67
+ );
68
+ return store;
69
+ }
70
+
71
+ describe("CellDeleteShoulder", () => {
72
+ beforeEach(() => {
73
+ finePointer = true;
74
+ listeners.clear();
75
+ deleteCell.mockClear();
76
+ vi.stubGlobal("matchMedia", (query: string) => ({
77
+ get matches() {
78
+ return query === FINE_QUERY && finePointer;
79
+ },
80
+ addEventListener: (_: string, cb: () => void) => listeners.add(cb),
81
+ removeEventListener: (_: string, cb: () => void) => listeners.delete(cb),
82
+ }));
83
+ });
84
+
85
+ afterEach(() => {
86
+ vi.unstubAllGlobals();
87
+ });
88
+
89
+ it("mounts no delete button while idle with a fine pointer", () => {
90
+ renderCells();
91
+ expect(screen.queryAllByTestId("delete-button")).toHaveLength(0);
92
+ });
93
+
94
+ it("mounts the button only in the hovered cell", () => {
95
+ renderCells();
96
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
97
+ expect(screen.getAllByTestId("delete-button")).toHaveLength(1);
98
+ expect(
99
+ screen.getByTestId("cell-a").querySelector("[data-testid=delete-button]"),
100
+ ).not.toBeNull();
101
+
102
+ fireEvent.pointerLeave(screen.getByTestId("cell-a"));
103
+ expect(screen.queryAllByTestId("delete-button")).toHaveLength(0);
104
+ });
105
+
106
+ it("keeps the button mounted while the cell holds focus", () => {
107
+ const store = renderCells();
108
+ act(() => {
109
+ store.set(cellFocusAtom, {
110
+ focusedCellId: CELL_B,
111
+ lastFocusedCellId: CELL_B,
112
+ });
113
+ });
114
+ expect(
115
+ screen.getByTestId("cell-b").querySelector("[data-testid=delete-button]"),
116
+ ).not.toBeNull();
117
+ expect(screen.getAllByTestId("delete-button")).toHaveLength(1);
118
+ });
119
+
120
+ it("does not mount the button when it is not allowed", () => {
121
+ render(<Cell cellId={CELL_A} showButton={false} />);
122
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
123
+ expect(screen.queryByTestId("delete-button")).toBeNull();
124
+ });
125
+
126
+ it("always mounts the button for coarse pointers", () => {
127
+ finePointer = false;
128
+ renderCells();
129
+ expect(screen.getAllByTestId("delete-button")).toHaveLength(2);
130
+ });
131
+
132
+ it("follows pointer capability changes", () => {
133
+ renderCells();
134
+ expect(screen.queryAllByTestId("delete-button")).toHaveLength(0);
135
+ setFinePointer(false);
136
+ expect(screen.getAllByTestId("delete-button")).toHaveLength(2);
137
+ setFinePointer(true);
138
+ expect(screen.queryAllByTestId("delete-button")).toHaveLength(0);
139
+ });
140
+
141
+ it("uses one media query listener for many cells", () => {
142
+ renderCells([CELL_A, CELL_B, "c" as CellId, "d" as CellId]);
143
+ expect(listeners.size).toBe(1);
144
+ });
145
+
146
+ it("deletes the cell on click", () => {
147
+ renderCells();
148
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
149
+ fireEvent.click(screen.getByTestId("delete-button"));
150
+ expect(deleteCell).toHaveBeenCalledWith({ cellId: CELL_A });
151
+ });
152
+
153
+ it("does not delete a running cell", () => {
154
+ render(<Cell cellId={CELL_A} status="running" />);
155
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
156
+ fireEvent.click(screen.getByTestId("delete-button"));
157
+ expect(deleteCell).not.toHaveBeenCalled();
158
+ });
159
+
160
+ it("does not delete while the connection is closed", () => {
161
+ render(<Cell cellId={CELL_A} connectionState="CLOSED" />);
162
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
163
+ fireEvent.click(screen.getByTestId("delete-button"));
164
+ expect(deleteCell).not.toHaveBeenCalled();
165
+ });
166
+
167
+ it("keeps Enter and Space from reaching cell navigation", () => {
168
+ const onKeyDown = vi.fn();
169
+ render(<Cell cellId={CELL_A} onKeyDown={onKeyDown} />);
170
+ fireEvent.pointerEnter(screen.getByTestId("cell-a"));
171
+ const button = screen.getByTestId("delete-button");
172
+
173
+ fireEvent.keyDown(button, { key: "Enter" });
174
+ fireEvent.keyDown(button, { key: " " });
175
+ expect(onKeyDown).not.toHaveBeenCalled();
176
+
177
+ fireEvent.keyDown(button, { key: "Enter", metaKey: true });
178
+ fireEvent.keyDown(button, { key: "ArrowDown" });
179
+ expect(onKeyDown).toHaveBeenCalledTimes(2);
180
+ });
181
+ });
@@ -2,10 +2,10 @@
2
2
  import { historyField } from "@codemirror/commands";
3
3
  import { EditorState, type Extension, StateEffect } from "@codemirror/state";
4
4
  import { EditorView, ViewPlugin } from "@codemirror/view";
5
- import { useAtom, useAtomValue, useSetAtom } from "jotai";
5
+ import { useAtomValue, useSetAtom } from "jotai";
6
6
  import React, { memo, useEffect, useMemo, useRef } from "react";
7
7
  import useEvent from "react-use-event-hook";
8
- import { aiCompletionCellAtom } from "@/core/ai/state";
8
+ import { aiCompletionCellAtom, useAiCompletionCell } from "@/core/ai/state";
9
9
  import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";
10
10
  import { useCellActions } from "@/core/cells/actions";
11
11
  import {
@@ -22,6 +22,7 @@ import type { CellData } from "@/core/cells/types";
22
22
  import type { CellRunStatus } from "@/core/executions";
23
23
  import { setupCodeMirror } from "@/core/codemirror/cm";
24
24
  import { acceptCompletionOnEnterAtom } from "@/core/codemirror/completion/accept-on-enter-atom";
25
+ import { replaceEditorContent } from "@/core/codemirror/replace-editor-content";
25
26
  import { useLazyEditorMount } from "@/core/codemirror/use-lazy-editor-mount";
26
27
  import {
27
28
  getInitialLanguageAdapter,
@@ -120,7 +121,8 @@ const CellEditorInternal = ({
120
121
  tooltipParentSelector,
121
122
  extensions: extraExtensions,
122
123
  }: CellEditorProps) => {
123
- const [aiCompletionCell, setAiCompletionCell] = useAtom(aiCompletionCellAtom);
124
+ const aiCompletionCell = useAiCompletionCell(cellId);
125
+ const setAiCompletionCell = useSetAtom(aiCompletionCellAtom);
124
126
  const serializedEditorState = useRestoredEditorState(cellId);
125
127
  const takeRestoredEditorState = useSetAtom(takeRestoredEditorStateAtom);
126
128
  const showHiddenCodeNow = useSetAtom(showHiddenCodeAtom);
@@ -379,7 +381,7 @@ const CellEditorInternal = ({
379
381
  }, [handleReconfigureEditor, extensions, editorViewRef]);
380
382
 
381
383
  // An AI edit applies to the editor, which a dormant cell does not have yet.
382
- const isAiCompletionTarget = aiCompletionCell?.cellId === cellId;
384
+ const isAiCompletionTarget = aiCompletionCell !== null;
383
385
  useEffect(() => {
384
386
  if (isAiCompletionTarget) {
385
387
  promote();
@@ -404,29 +406,17 @@ const CellEditorInternal = ({
404
406
  aiCompletionCell={aiCompletionCell}
405
407
  currentCode={mountedEditorView?.state.doc.toString() ?? code}
406
408
  currentLanguageAdapter={languageAdapter}
407
- declineChange={useEvent(() => {
408
- setAiCompletionCell(null);
409
- editorViewRef.current?.focus();
409
+ close={useEvent(() => {
410
+ setAiCompletionCell((target) =>
411
+ target?.cellId === cellId ? null : target,
412
+ );
410
413
  })}
414
+ focusEditor={useEvent(() => editorViewRef.current?.focus())}
411
415
  onChange={useEvent((newCode) => {
412
- editorViewRef.current?.dispatch({
413
- changes: {
414
- from: 0,
415
- to: editorViewRef.current.state.doc.length,
416
- insert: newCode,
417
- },
418
- });
419
- })}
420
- acceptChange={useEvent((newCode) => {
421
- editorViewRef.current?.dispatch({
422
- changes: {
423
- from: 0,
424
- to: editorViewRef.current.state.doc.length,
425
- insert: newCode,
426
- },
427
- });
428
- editorViewRef.current?.focus();
429
- setAiCompletionCell(null);
416
+ const view = editorViewRef.current;
417
+ if (view) {
418
+ replaceEditorContent(view, newCode);
419
+ }
430
420
  })}
431
421
  runCell={handleRunCell}
432
422
  outputArea={outputArea}
@@ -1,7 +1,9 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { render, screen } from "@testing-library/react";
4
- import { describe, expect, it } from "vitest";
4
+ import { describe, expect, it, vi } from "vitest";
5
+ import { appendCellLogs, LOG_CHUNK_SIZE } from "@/core/cells/cell-log-chunks";
6
+ import * as cellLogs from "@/core/cells/logs";
5
7
  import type { CellLog } from "@/core/cells/logs";
6
8
  import { LogViewer } from "../logs-panel";
7
9
 
@@ -16,10 +18,32 @@ describe("LogViewer", () => {
16
18
  },
17
19
  ];
18
20
 
19
- render(<LogViewer logs={logs} />);
21
+ render(<LogViewer logs={[logs]} />);
20
22
 
21
23
  expect(screen.getByText("(lsp:pylsp)")).toBeInTheDocument();
22
24
  expect(screen.getByText("pylsp failed to start")).toBeInTheDocument();
23
25
  expect(screen.getByText("STDERR")).toBeInTheDocument();
24
26
  });
27
+
28
+ it("continues row numbers without formatting a full chunk again", () => {
29
+ const log: CellLog = {
30
+ timestamp: 1,
31
+ level: "stdout",
32
+ message: "message",
33
+ source: { type: "lsp", name: "pylsp" },
34
+ };
35
+ const logs = appendCellLogs(
36
+ [],
37
+ Array.from({ length: LOG_CHUNK_SIZE }, () => log),
38
+ );
39
+ const { rerender } = render(<LogViewer logs={logs} />);
40
+ const format = vi.spyOn(cellLogs, "formatLogTimestamp");
41
+ try {
42
+ rerender(<LogViewer logs={appendCellLogs(logs, [log])} />);
43
+ expect(format).toHaveBeenCalledTimes(1);
44
+ expect(screen.getByText(String(LOG_CHUNK_SIZE + 1))).toBeInTheDocument();
45
+ } finally {
46
+ format.mockRestore();
47
+ }
48
+ });
25
49
  });
@@ -3,6 +3,10 @@
3
3
  import { FileTextIcon } from "lucide-react";
4
4
  import React from "react";
5
5
  import { ClearButton } from "@/components/buttons/clear-button";
6
+ import {
7
+ type CellLogChunks,
8
+ LOG_CHUNK_SIZE,
9
+ } from "@/core/cells/cell-log-chunks";
6
10
  import { useCellLogs } from "@/core/cells/cells";
7
11
  import { useCellActions } from "@/core/cells/actions";
8
12
  import {
@@ -16,7 +20,7 @@ import { PanelEmptyState } from "./empty-state";
16
20
 
17
21
  interface Props {
18
22
  className?: string;
19
- logs: CellLog[];
23
+ logs: CellLogChunks;
20
24
  }
21
25
 
22
26
  const LogsPanel: React.FC = () => {
@@ -52,7 +56,6 @@ const LogsPanel: React.FC = () => {
52
56
  export default LogsPanel;
53
57
 
54
58
  export const LogViewer: React.FC<Props> = ({ logs, className }) => {
55
- const hover = "opacity-70 group-hover:bg-(--gray-3) group-hover:opacity-100";
56
59
  return (
57
60
  <div className={cn("flex flex-col", className)}>
58
61
  <pre className="grid text-xs font-mono gap-1 whitespace-break-spaces font-semibold align-left">
@@ -60,15 +63,8 @@ export const LogViewer: React.FC<Props> = ({ logs, className }) => {
60
63
  className="grid grid-cols-[30px_1fr]"
61
64
  style={{ whiteSpace: "pre-wrap" }}
62
65
  >
63
- {logs.map((log, index) => (
64
- <div key={index} className="contents group">
65
- <span className={cn(hover, "text-right col-span-1 py-1 pr-1")}>
66
- {index + 1}
67
- </span>
68
- <span className={cn(hover, "px-2 flex gap-x-1.5 py-1 flex-wrap")}>
69
- {formatLog(log)}
70
- </span>
71
- </div>
66
+ {logs.map((chunk, index) => (
67
+ <LogRows key={index} logs={chunk} offset={index * LOG_CHUNK_SIZE} />
72
68
  ))}
73
69
  </div>
74
70
  </pre>
@@ -76,6 +72,26 @@ export const LogViewer: React.FC<Props> = ({ logs, className }) => {
76
72
  );
77
73
  };
78
74
 
75
+ const LogRows = React.memo(function LogRows({
76
+ logs,
77
+ offset,
78
+ }: {
79
+ logs: readonly CellLog[];
80
+ offset: number;
81
+ }) {
82
+ const hover = "opacity-70 group-hover:bg-(--gray-3) group-hover:opacity-100";
83
+ return logs.map((log, index) => (
84
+ <div key={index} className="contents group">
85
+ <span className={cn(hover, "text-right col-span-1 py-1 pr-1")}>
86
+ {offset + index + 1}
87
+ </span>
88
+ <span className={cn(hover, "px-2 flex gap-x-1.5 py-1 flex-wrap")}>
89
+ {formatLog(log)}
90
+ </span>
91
+ </div>
92
+ ));
93
+ });
94
+
79
95
  function formatLog(log: CellLog) {
80
96
  const timestamp = formatLogTimestamp(log.timestamp);
81
97