2828from TermTk .TTkCore .constant import TTkK
2929from TermTk .TTkCore .string import TTkString
3030
31- from .text_wrap_data import _RetScreenRows , _WrapLine , _WrapState , _ReWrapData
31+ from .text_wrap_data import _RetScreenPosition , _RetScreenPositions , _RetScreenRows , _WrapLine , _WrapState , _ReWrapData
3232
3333class _WrapEngine_Interface ():
3434 '''Base interface for text wrap engines.
@@ -41,8 +41,8 @@ class _WrapEngine_Interface():
4141 :py:attr:`TTkTextDocument.contentsChange` signal.
4242 * :py:class:`_WrapEngine_VimWrap` -- lazily wraps only the visible window,
4343 caching the last viewport for coordinate conversions.
44- * :py:class:`_WrapEngine_FastWrap` -- placeholder for a future incremental
45- wrapping strategy .
44+ * :py:class:`_WrapEngine_FastWrap` -- chunk-based lazy wrapping strategy
45+ for large documents .
4646 '''
4747 __slots__ = ('_wrapState' )
4848
@@ -77,10 +77,13 @@ def rewrap(self, data: Optional[_ReWrapData]=None) -> None:
7777 :py:class:`_WrapEngine_FullWrap`) rebuild it here; engines
7878 that wrap lazily (e.g. :py:class:`_WrapEngine_NoWrap`,
7979 :py:class:`_WrapEngine_VimWrap`) may be a no-op.
80+
81+ :param data: optional incremental change descriptor.
82+ :type data: Optional[:py:class:`_ReWrapData`]
8083 '''
8184 raise NotImplementedError ()
8285
83- def dataToScreenPosition (self , line :int , pos :int ) -> Tuple [ int , int ] :
86+ def dataToScreenPosition (self , line :int , pos :int ) -> _RetScreenPositions :
8487 '''Map a document position to wrapped screen coordinates.
8588
8689 Converts a logical ``(line, pos)`` pair in the source document
@@ -92,9 +95,9 @@ def dataToScreenPosition(self, line:int, pos:int) -> Tuple[int, int]:
9295 :param pos: character offset within the document line.
9396 :type pos: int
9497
95- :return: ``(x, y)`` screen coordinates where *x* is the
96- terminal-cell column and *y* is the wrapped row index.
97- :rtype: Tuple[int, int]
98+ :return: wrapped screen coordinates where *main. x* is the
99+ terminal-cell column and *main. y* is the wrapped row index.
100+ :rtype: :py:class:`_RetScreenPositions`
98101 '''
99102 raise NotImplementedError ()
100103
@@ -144,8 +147,8 @@ def screenRows(self, y:int, h:int) -> _RetScreenRows:
144147 :param h: number of rows to retrieve.
145148 :type h: int
146149
147- :return: list of wrapped row descriptors.
148- :rtype: List[ :py:class:`_WrapLine`]
150+ :return: wrapped row descriptors.
151+ :rtype: :py:class:`_RetScreenRows`
149152 '''
150153 raise NotImplementedError ()
151154
@@ -188,12 +191,12 @@ def _wrapLine(self, _w:int, _i:int, _l:TTkString) -> List[_WrapLine]:
188191 wordWrapMode = self ._wrapState .wordWrapMode
189192 fr = 0
190193 if not len (_l ): # if the line is empty append it
191- ret .append (_WrapLine (_i ,0 ,0 ))
194+ ret .append (_WrapLine (_i ,0 ,0 , True ))
192195 return ret
193196 while len (_l ):
194197 to = _l .tabCharPos (_w , tabSpaces )
195198 if to >= len (_l ):
196- ret .append (_WrapLine (_i ,fr ,fr + len (_l )+ 1 ))
199+ ret .append (_WrapLine (_i ,fr ,fr + len (_l )+ 1 , True ))
197200 return ret
198201 to = max (1 ,to )
199202 if wordWrapMode == TTkK .WordWrap : # Find the index of the first white space
@@ -202,7 +205,9 @@ def _wrapLine(self, _w:int, _i:int, _l:TTkString) -> List[_WrapLine]:
202205 while newTo and ( s [newTo ] != ' ' and s [newTo ] != '\t ' ): newTo -= 1
203206 if newTo : to = newTo
204207
205- ret .append (_WrapLine (_i ,fr ,fr + to ))
208+ ret .append (_WrapLine (_i ,fr ,fr + to , False ))
206209 _l = _l .substring (to )
207210 fr += to
211+ if ret :
212+ ret [- 1 ].last_slice = True
208213 return ret
0 commit comments