This commit is contained in:
恍兮惚兮 2024-10-29 23:03:08 +08:00
parent bc0687772b
commit aac082cf45

View File

@ -212,6 +212,14 @@ class TextBrowser(QWidget, dataget):
return True return True
return False return False
def __findsame(self, s1, s2):
i = 0
while i < len(s1) and i < len(s2):
if s1[i] != s2[i]:
break
i += 1
return i
def iter_append(self, iter_context_class, origin, atcenter, text, color): def iter_append(self, iter_context_class, origin, atcenter, text, color):
if self.checkskip(origin): if self.checkskip(origin):
return return
@ -224,18 +232,19 @@ class TextBrowser(QWidget, dataget):
} }
currbefore = self.saveiterclasspointer[iter_context_class]["curr"] currbefore = self.saveiterclasspointer[iter_context_class]["curr"]
currlen = len(self.saveiterclasspointer[iter_context_class]["currtext"]) currtext = self.saveiterclasspointer[iter_context_class]["currtext"]
if len(text) < currlen: currlen = len(currtext)
_samenum = self.__findsame(text, currtext)
if _samenum < currlen:
self._deletebetween( self._deletebetween(
self.saveiterclasspointer[iter_context_class]["start"] + len(text), self.saveiterclasspointer[iter_context_class]["start"] + _samenum,
self.saveiterclasspointer[iter_context_class]["curr"], self.saveiterclasspointer[iter_context_class]["curr"],
) )
else: newtext = text[_samenum:]
newtext = text[currlen:] self._insertatpointer(
self._insertatpointer( self.saveiterclasspointer[iter_context_class]["start"] + _samenum,
self.saveiterclasspointer[iter_context_class]["start"] + currlen, newtext,
newtext, )
)
self.saveiterclasspointer[iter_context_class]["currtext"] = text self.saveiterclasspointer[iter_context_class]["currtext"] = text
currcurrent = self._getcurrpointer() currcurrent = self._getcurrpointer()