TTkTextWrap๐ถ๏ธ
- class TTkTextWrap(document: TTkTextDocument)[source]๐ถ๏ธ
Bases:
objectTTkTextWrap:
Incremental text wrapping helper for
TTkTextDocument. It maps document positions to wrapped screen rows and vice versa.Create a wrap manager bound to a text document.
- param document:
the source text document to wrap.
- type document:
Signals๐ถ๏ธ
This signal is emitted whenever wrapped line mapping changes.
Slots๐ถ๏ธ
ensureScreenRows(y,ย h)Force materialization of wrapped rows in a viewport range.
Members๐ถ๏ธ
- wrapChanged: pyTTkSignal๐ถ๏ธ
This signal is emitted whenever wrapped line mapping changes.
It is triggered after incremental updates from document edits and after explicit full rewrap requests.
Methods๐ถ๏ธ
- dataToScreenPosition(line: int, pos: int) _RetScreenPositions[source]๐ถ๏ธ
Map a document position to wrapped screen coordinates.
- Parameters:
line (int) โ logical line index.
pos (int) โ character position in the logical line.
- Returns:
wrapped screen coordinates.
- Return type:
_RetScreenPositions
- documentLineCount() int[source]๐ถ๏ธ
Return the number of logical data lines in the document.
- Returns:
document line count.
- Return type:
int
- engine() WrapEngine[source]๐ถ๏ธ
- ensureScreenRows(y: int, h: int) None[source]๐ถ๏ธ
Force materialization of wrapped rows in a viewport range.
For lazy-loading engines (FastWrap, VimWrap, HybridVimWrap), this materializes the rows that would be returned by
screenRows(). For eager engines (FullWrap, NoWrap), this is typically a no-op.This is useful when you need
size()to return an accurate estimate instead of a prediction, as lazy engines improve their estimates as more chunks are materialized.- Parameters:
y (int) โ first screen row to materialize.
h (int) โ number of rows to materialize.
- normalizeScreenPosition(x: int, y: int) Tuple[int, int][source]๐ถ๏ธ
Snap a screen position to the nearest editable character cell.
- Parameters:
x (int) โ horizontal widget-relative coordinate.
y (int) โ vertical widget-relative coordinate.
- Returns:
normalized
(x, y)screen position.- Return type:
Tuple[int, int]
- rewrap() None[source]๐ถ๏ธ
Force a complete wrap refresh and emit
wrapChanged.This invalidates any incremental wrapping cache maintained by the active engine.
- screenRows(y: int, h: int) _RetScreenRows[source]๐ถ๏ธ
Return wrapped slices visible in the requested viewport.
- Parameters:
y (int) โ first screen row.
h (int) โ number of rows to extract.
- Returns:
wrapped row slices.
- Return type:
_RetScreenRows
- screenToDataPosition(x: int, y: int) Tuple[int, int][source]๐ถ๏ธ
Map wrapped screen coordinates to a document position.
- Parameters:
x (int) โ horizontal screen coordinate.
y (int) โ vertical screen coordinate.
- Returns:
(line, pos)document position.- Return type:
Tuple[int, int]
- setEngine(engine: WrapEngine, width: int | None = None) None[source]๐ถ๏ธ
Switch the wrapping backend implementation.
- Parameters:
engine (
TTkK.WrapEngine) โ engine selector fromTTkK.WrapEngine.width (Optional[int]) โ optional wrap width applied before switching engines when the engine type actually changes.
- setWordWrapMode(mode: WrapMode) None[source]๐ถ๏ธ
Set the word-wrap mode and invalidate cached wrapping.
- Parameters:
mode (
TTkK.WrapMode) โ new wrap mode.
- setWrapWidth(width: int) None[source]๐ถ๏ธ
Set wrap width and trigger a full rewrap.
- Parameters:
width (int) โ target width in terminal cells.
- size() int[source]๐ถ๏ธ
Return the estimated wrapped row count.
- Returns:
wrapped size in screen rows.
- Return type:
int