vimsheet.controller.search

Find-and-replace logic for VimSheet.

class vimsheet.controller.search.SearchState(pattern='', replace='', case_sensitive=False, use_regex=False, whole_cell=False, current_match=None, matches=<factory>)[source]

Bases: object

Holds the current search/replace state.

Parameters:
pattern: str = ''
replace: str = ''
case_sensitive: bool = False
use_regex: bool = False
whole_cell: bool = False
current_match: tuple[int, int] | None = None
matches: list[tuple[int, int]]
__init__(pattern='', replace='', case_sensitive=False, use_regex=False, whole_cell=False, current_match=None, matches=<factory>)
Parameters:
Return type:

None

class vimsheet.controller.search.Searcher(sheet)[source]

Bases: object

Performs find/replace operations on a Sheet.

Parameters:

sheet (Sheet)

__init__(sheet)[source]
Parameters:

sheet (Sheet)

Return type:

None

find_all(state)[source]

Return all (row, col) positions matching state.pattern.

If the pattern is empty every non-empty cell is returned.

Parameters:

state (SearchState)

Return type:

list[tuple[int, int]]

find_next(state, from_pos)[source]

Return the next match after from_pos, wrapping around.

Returns None when there are no matches at all.

Parameters:
Return type:

tuple[int, int] | None

find_prev(state, from_pos)[source]

Return the previous match before from_pos, wrapping around.

Returns None when there are no matches at all.

Parameters:
Return type:

tuple[int, int] | None

replace_one(state, row, col, max_subs=0)[source]

Replace text in (row, col) using state.replace.

max_subs=0 replaces all occurrences; max_subs=1 replaces only the first. Returns True if a replacement was made.

Parameters:
Return type:

bool

collect_replacements(state, rows=None, cols=None)[source]

Return (row, col, new_value, new_formula) for matches without mutating.

If rows and cols are both None, scans the entire sheet. If only rows given, scans those rows entirely. If only cols given, scans those columns entirely. If both given, scans the row×col intersection.

Parameters:
Return type:

list[tuple[int, int, Any, str | None]]

replace_all(state)[source]

Replace all occurrences of state.pattern with state.replace.

Returns the number of cells where a replacement was made.

Parameters:

state (SearchState)

Return type:

int

replace_in_cols(state, cols, max_subs=0)[source]

Replace in the given column indices only.

max_subs=0 replaces all occurrences per cell; max_subs=1 replaces the first. Returns the number of cells where a replacement was made.

Parameters:
Return type:

int

replace_in_range(state, rows, cols, max_subs=0)[source]

Replace within a specific row+col intersection.

Returns the number of cells where a replacement was made.

Parameters:
Return type:

int

replace_in_rows(state, rows, max_subs=0)[source]

Replace in the given row indices only.

max_subs=0 replaces all occurrences per cell; max_subs=1 replaces the first. Returns the number of cells where a replacement was made.

Parameters:
Return type:

int