Browse Source

feat(TextDocument): append on an empty document replace the text (#429)

pull/430/head
Pier CeccoPierangioliEugenio 8 months ago committed by GitHub
parent
commit
8c5f7d75cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      libs/pyTermTk/TermTk/TTkGui/textdocument.py

5
libs/pyTermTk/TermTk/TTkGui/textdocument.py

@ -126,6 +126,7 @@ class TTkTextDocument():
lines[d._i1:d._i2] = d._slice
return d._snap
_default_init_text = ' '
__slots__ = (
'_dataLines', '_modified',
@ -140,7 +141,7 @@ class TTkTextDocument():
'undoAvailable', 'redoAvailable', 'undoCommandAdded',
'modificationChanged'
)
def __init__(self, *, text:TTkString=" ") -> None:
def __init__(self, *, text:Union[TTkString,str]=_default_init_text) -> None:
from TermTk.TTkGui.textcursor import TTkTextCursor
self._docMutex = Lock()
self.cursorPositionChanged = pyTTkSignal(TTkTextCursor)
@ -254,6 +255,8 @@ class TTkTextDocument():
def appendText(self, text):
if type(text) == str:
text = TTkString() + text
if len(self._dataLines) == 1 and self._dataLines[0] == TTkString(TTkTextDocument._default_init_text):
return self.setText(text)
self._acquire()
oldLines = len(self._dataLines)
self._dataLines += text.split('\n')

Loading…
Cancel
Save