Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

779 B
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */
import { foldAll, unfoldAll } from "@codemirror/language";
import type { Command, EditorView } from "@codemirror/view";

type MaybeEditorView = EditorView | undefined | null;

export type BulkCommand = (targets: MaybeEditorView[]) => boolean;

/**
 * Make a bulk command from a single {@type Command} that applies
 * the given command to all targets.
 */
export function makeBulkCommand(command: Command) {
  return (targets: MaybeEditorView[]) => {
    let changed = false;
    for (const target of targets) {
      if (target) {
        changed = command(target) || changed;
      }
    }
    return changed;
  };
}

export const foldAllBulk = makeBulkCommand(foldAll);
export const unfoldAllBulk = makeBulkCommand(unfoldAll);