diff --git a/src/LunaTranslator/gui/selecthook.py b/src/LunaTranslator/gui/selecthook.py index 034ee30a..5ced3f30 100644 --- a/src/LunaTranslator/gui/selecthook.py +++ b/src/LunaTranslator/gui/selecthook.py @@ -857,11 +857,10 @@ class hookselect(closeashidewindow): try: hc, hn, tp = key gobject.baseobject.textsource.usermanualaccepthooks.append(key) - if key in gobject.baseobject.textsource.selectedhook: - gobject.baseobject.textsource.selectedhook.remove(key) + gobject.baseobject.textsource.edit_selectedhook_remove(key) if select: - gobject.baseobject.textsource.selectedhook.append(key) + gobject.baseobject.textsource.edit_selectedhook_insert(key) if hn[:8] == "UserHook": needinserthookcode = savehook_new_data[gobject.baseobject.gameuid][ diff --git a/src/LunaTranslator/textsource/texthook.py b/src/LunaTranslator/textsource/texthook.py index 7a5c594d..30bf2f9f 100644 --- a/src/LunaTranslator/textsource/texthook.py +++ b/src/LunaTranslator/textsource/texthook.py @@ -168,6 +168,21 @@ class texthook(basetext): self.delaycollectallselectedoutput() self.autohookmonitorthread() + def edit_selectedhook_remove(self, key): + try: + self.selectedhook.remove(key) + except: + pass + _, _, tp = key + self.Luna_SyncThread(tp, False) + + def edit_selectedhook_insert(self, key, idx=-1): + if idx == -1: + idx = len(self.selectedhook) + self.selectedhook.insert(idx, key) + _, _, tp = key + self.Luna_SyncThread(tp, True) + def initdll(self): LunaHost = CDLL( gobject.GetDllpath( @@ -538,7 +553,7 @@ class texthook(basetext): insertindex = j else: insertindex = j + 1 - self.selectedhook.insert(insertindex, key) + self.edit_selectedhook_insert(key, insertindex) gobject.baseobject.hookselectdialog.addnewhooksignal.emit( key, select, isembedable ) @@ -627,7 +642,9 @@ class texthook(basetext): def delaycollectallselectedoutput(self): while not self.ending: time.sleep(0.01) - if time.time() < self.lastflushtime + self.config["textthreaddelay"] / 1000: + if time.time() < self.lastflushtime + min( + 0.1, self.config["textthreaddelay"] / 1000 + ): continue if len(self.multiselectedcollector) == 0: continue