Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions frontend/src/core/codemirror/cells/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ function cellKeymaps({
function cellCodeEditing(hotkeys: HotkeyProvider): Extension[] {
const onChangePlugin = EditorView.updateListener.of((update) => {
if (update.docChanged) {
// Skip changes that came from Loro sync (RTC) — these are
// already reflected in the shared LoroDoc and don't need to
// round-trip through the transaction middleware.
const isLoroSync = update.transactions.some(
(tr) => tr.annotation(loroSyncAnnotation) != null,
);
if (isLoroSync) {
return;
}

// Check if the doc update was a formatting change
// e.g. changing from python to markdown
const isFormattingChange = update.transactions.some((tr) =>
Expand Down
30 changes: 30 additions & 0 deletions marimo/_notebook/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2026 Marimo. All rights reserved.
"""Notebook document model — canonical representation of notebook structure."""

from marimo._messaging.notebook.changes import (
CreateCell,
DeleteCell,
DocumentChange,
MoveCell,
ReorderCells,
SetCode,
SetConfig,
SetName,
Transaction,
)
from marimo._notebook.document import CellMeta, NotebookCell, NotebookDocument

__all__ = [
"CellMeta",
"CreateCell",
"DeleteCell",
"DocumentChange",
"MoveCell",
"NotebookCell",
"NotebookDocument",
"ReorderCells",
"SetCode",
"SetConfig",
"SetName",
"Transaction",
]
27 changes: 27 additions & 0 deletions marimo/_notebook/_loro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2026 Marimo. All rights reserved.
"""Typed wrappers for ``loro`` APIs with incomplete stubs.

The ``loro`` stubs omit return types on ``__new__`` and the
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should raise upstream tbh

``ValueOrContainer`` union lacks a typed ``.container`` accessor.
These helpers isolate the ``type: ignore`` comments so the rest of
the codebase stays clean.
"""

from __future__ import annotations

from loro import LoroDoc, LoroText, ValueOrContainer


def create_doc() -> LoroDoc:
return LoroDoc() # type: ignore[no-untyped-call]


def create_text() -> LoroText:
return LoroText() # type: ignore[no-untyped-call]


def unwrap_text(val: ValueOrContainer) -> LoroText:
"""Extract a ``LoroText`` from a ``ValueOrContainer``."""
container = val.container # type: ignore[union-attr,attr-defined]
assert isinstance(container, LoroText)
return container
Loading
Loading