@@ -126,6 +126,7 @@ def _getSnap(self, lines, d):
126126 lines [d ._i1 :d ._i2 ] = d ._slice
127127 return d ._snap
128128
129+ _default_init_text = ' '
129130
130131 __slots__ = (
131132 '_dataLines' , '_modified' ,
@@ -140,7 +141,7 @@ def _getSnap(self, lines, d):
140141 'undoAvailable' , 'redoAvailable' , 'undoCommandAdded' ,
141142 'modificationChanged'
142143 )
143- def __init__ (self , * , text :TTkString = " " ) -> None :
144+ def __init__ (self , * , text :Union [ TTkString , str ] = _default_init_text ) -> None :
144145 from TermTk .TTkGui .textcursor import TTkTextCursor
145146 self ._docMutex = Lock ()
146147 self .cursorPositionChanged = pyTTkSignal (TTkTextCursor )
@@ -254,6 +255,8 @@ def setText(self, text:Union[str,TTkString]):
254255 def appendText (self , text ):
255256 if type (text ) == str :
256257 text = TTkString () + text
258+ if len (self ._dataLines ) == 1 and self ._dataLines [0 ] == TTkString (TTkTextDocument ._default_init_text ):
259+ return self .setText (text )
257260 self ._acquire ()
258261 oldLines = len (self ._dataLines )
259262 self ._dataLines += text .split ('\n ' )
0 commit comments