TTkTextWrap๐ŸŒถ๏ธ

class TTkTextWrap(document: TTkTextDocument)[source]๐ŸŒถ๏ธ

Bases: object

TTkTextWrap:

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:

TTkTextDocument

Signals๐ŸŒถ๏ธ

wrapChanged

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 from TTkK.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

wordWrapMode() WrapMode[source]๐ŸŒถ๏ธ

Return the active word-wrap mode.

Returns:

current wrap mode.

Return type:

TTkK.WrapMode

wrapWidth() int[source]๐ŸŒถ๏ธ

Return the current wrap width in terminal cells.

Returns:

wrap width.

Return type:

int