vimsheet.model.undo

Command-pattern undo/redo stack for VimSheet.

class vimsheet.model.undo.YankedCell(value, formula, fmt=None, locked=False, comment=None)[source]

Bases: object

Register entry that preserves both a cell’s formula and its value.

Parameters:
value: Any
formula: str | None
fmt: CellFormat | None = None
locked: bool = False
comment: str | None = None
__init__(value, formula, fmt=None, locked=False, comment=None)
Parameters:
Return type:

None

class vimsheet.model.undo.Command[source]

Bases: ABC

description: str = ''
abstractmethod execute()[source]
Return type:

None

abstractmethod undo()[source]
Return type:

None

class vimsheet.model.undo.SetCellCommand(sheet, row, col, new_value, new_formula=None)[source]

Bases: Command

Parameters:
  • sheet (Sheet)

  • row (int)

  • col (int)

  • new_value (Any)

  • new_formula (str | None)

description: str = 'set cell'
__init__(sheet, row, col, new_value, new_formula=None)[source]
Parameters:
  • sheet (Sheet)

  • row (int)

  • col (int)

  • new_value (Any)

  • new_formula (str | None)

Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.ClearCellCommand(sheet, row, col)[source]

Bases: Command

Parameters:
description: str = 'clear cell'
__init__(sheet, row, col)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.DeleteRangeCommand(sheet, cell_range)[source]

Bases: Command

Parameters:
description: str = 'delete range'
__init__(sheet, cell_range)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.ValidationCommand(sheet, row, col, new_rule)[source]

Bases: Command

Set or clear a validation rule on a single cell, undoable.

Parameters:
description: str = 'set validation'
__init__(sheet, row, col, new_rule)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.SortRangeCommand(sheet, r1, c1, sorted_data)[source]

Bases: Command

Snapshot a range before sorting, allow undo/redo.

Parameters:
description: str = 'sort range'
__init__(sheet, r1, c1, sorted_data)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.FillRangeCommand(sheet, updates)[source]

Bases: Command

Parameters:
description: str = 'fill range'
__init__(sheet, updates)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.InsertRowCommand(sheet, row)[source]

Bases: Command

Parameters:
description: str = 'insert row'
__init__(sheet, row)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.DeleteRowCommand(sheet, row)[source]

Bases: Command

Parameters:
description: str = 'delete row'
__init__(sheet, row)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.InsertColCommand(sheet, col)[source]

Bases: Command

Parameters:
description: str = 'insert column'
__init__(sheet, col)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.DeleteColCommand(sheet, col)[source]

Bases: Command

Parameters:
description: str = 'delete column'
__init__(sheet, col)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.PasteCommand(sheet, base_row, base_col, data)[source]

Bases: Command

Parameters:
description: str = 'paste'
__init__(sheet, base_row, base_col, data)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.LockCommand(sheet, row, col, locked)[source]

Bases: Command

Parameters:
description: str = 'lock cell'
__init__(sheet, row, col, locked)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.FormatCommand(sheet, row, col, **new_fmt_kwargs)[source]

Bases: Command

Parameters:
  • sheet (Sheet)

  • row (int)

  • col (int)

  • new_fmt_kwargs (Any)

description: str = 'format cell'
__init__(sheet, row, col, **new_fmt_kwargs)[source]
Parameters:
  • sheet (Sheet)

  • row (int)

  • col (int)

  • new_fmt_kwargs (Any)

Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.SortCommand(sheet, sort_keys, range_bounds=None)[source]

Bases: Command

Parameters:
description: str = 'sort sheet'
__init__(sheet, sort_keys, range_bounds=None)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.ShiftCellsCommand(sheet, src, dr, dc)[source]

Bases: Command

Cascade-shift a cell block one step in direction (dr, dc).

The entire strip from the source’s leading edge to the end of used data shifts by one, so existing content is pushed out of the way rather than overwritten. The vacated leading edge is left empty.

Parameters:
description: str = 'shift cells'
__init__(sheet, src, dr, dc)[source]
Parameters:
Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.CompositeCommand(commands)[source]

Bases: Command

Parameters:

commands (list[Command])

description: str = 'composite'
__init__(commands)[source]
Parameters:

commands (list[Command])

Return type:

None

execute()[source]
Return type:

None

undo()[source]
Return type:

None

class vimsheet.model.undo.UndoStack(max_size=1000)[source]

Bases: object

Manages the undo/redo history for a sheet.

Parameters:

max_size (int)

__init__(max_size=1000)[source]
Parameters:

max_size (int)

Return type:

None

property can_undo: bool
property can_redo: bool
push(cmd)[source]

Execute cmd and push it onto the undo stack, clearing redo history.

Parameters:

cmd (Command)

Return type:

None

undo()[source]

Undo the most recent command. Returns True if something was undone.

Return type:

bool

redo()[source]

Re-apply the most recently undone command. Returns True if something was redone.

Return type:

bool

clear()[source]

Discard all undo and redo history.

Return type:

None