MCPcopy Index your code
hub / github.com/marimo-team/marimo / move_cell

Method move_cell

marimo/_code_mode/_context.py:1258–1301  ·  view source on GitHub ↗

Queue a cell to be repositioned in the notebook. Moves only affect visual ordering — they do not re-execute cells or change the dependency graph. Examples: ```python ctx.move_cell("imports", before="analysis") ctx.move_cell("cleanup", aft

(
        self,
        target: str,
        *,
        before: str | None = None,
        after: str | None = None,
    )

Source from the content-addressed store, hash-verified

1256 self._ops.append(_DeleteOp(cell_id=cell_id))
1257
1258 def move_cell(
1259 self,
1260 target: str,
1261 *,
1262 before: str | None = None,
1263 after: str | None = None,
1264 ) -> None:
1265 """Queue a cell to be repositioned in the notebook.
1266
1267 Moves only affect visual ordering — they do not re-execute
1268 cells or change the dependency graph.
1269
1270 Examples:
1271 ```python
1272 ctx.move_cell("imports", before="analysis")
1273 ctx.move_cell("cleanup", after="main_logic")
1274 ```
1275
1276 Args:
1277 target (str): Cell ID or cell name to move.
1278 before (str, optional): Place before this cell (ID or name).
1279 Mutually exclusive with `after`.
1280 after (str, optional): Place after this cell (ID or name).
1281 Mutually exclusive with `before`.
1282 """
1283 self._require_entered()
1284 if before is not None and after is not None:
1285 raise ValueError("Cannot specify both 'before' and 'after'")
1286 if before is None and after is None:
1287 raise ValueError("Must specify either 'before' or 'after'")
1288
1289 cell_id = self._resolve_target(target)
1290 before_id = (
1291 self._resolve_target(before) if before is not None else None
1292 )
1293 after_id = self._resolve_target(after) if after is not None else None
1294
1295 self._ops.append(
1296 _MoveOp(
1297 cell_id=cell_id,
1298 before=before_id,
1299 after=after_id,
1300 )
1301 )
1302
1303 def run_cell(self, target: str) -> None:
1304 """Queue a cell for execution.

Callers 1

Calls 4

_require_enteredMethod · 0.95
_resolve_targetMethod · 0.95
_MoveOpClass · 0.90
appendMethod · 0.45

Tested by 1