From 0ce49e818039a29963847482bc147957668eb0bd Mon Sep 17 00:00:00 2001 From: Casey Date: Sun, 4 Oct 2020 14:48:09 +0800 Subject: [PATCH] #32 resolved pressed enter several times --- Dakje.pyw | 6 ++++-- managers/TokenManager.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Dakje.pyw b/Dakje.pyw index 90acbed..50c3cc7 100755 --- a/Dakje.pyw +++ b/Dakje.pyw @@ -344,7 +344,9 @@ class Editor(QtWidgets.QMainWindow): # 新的字串做 segment newTokens = self.tokenManager.segment(afterChangingString) - if tokenStart == tokenEnd and not (tokenStart == 0): + if tokenStart == tokenEnd and \ + not (tokenStart == 0) and \ + not tokens[-1].text in afterChangingString: start = time.time() ## if newTokens[0] == '།' or newTokens[0] == '\n': self.tokens.extend(newTokens[1:]) @@ -352,7 +354,7 @@ class Editor(QtWidgets.QMainWindow): self.tokens.extend(newTokens[0:]) end = time.time() ## print(f'self.tokens.extend(): {round((end-start) * 1000, 2)}ms') ## - elif tokenStart == 0 and tokenEnd == 0: + elif tokenStart == 0 and tokenEnd == 0: start = time.time() ## string = self.centralWidget.textEdit.toPlainText() self.tokens = self.tokenManager.segment(string) diff --git a/managers/TokenManager.py b/managers/TokenManager.py index 852d8e9..21b9e5c 100644 --- a/managers/TokenManager.py +++ b/managers/TokenManager.py @@ -276,6 +276,8 @@ def diff(self, tokens, oldText, newText): start = oldString.find('།', lastWordIndex) elif '\n' in oldString: # 使用 \n 時的時候 start = oldString.find('\n', lastWordIndex) + if string == '\n': + start += 1 else: # start = oldString.find('་', lastWordIndex) start = -1 @@ -318,7 +320,6 @@ def diff(self, tokens, oldText, newText): if endOld == -1 and endNew == -1: #找不到時 endOld = len(oldString) - 1 endNew = len(newString) - 1 - if (tokens[-1].end == changePos) or (changePos == -1): # 在文章最後面加字 if (tokens[-1].end == changePos): start = len(oldString)