Skip to content

Commit

Permalink
#32
Browse files Browse the repository at this point in the history
resolved pressed enter several times
  • Loading branch information
Casey committed Oct 4, 2020
1 parent 393bf21 commit 0ce49e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Dakje.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,17 @@ 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:])
else:
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)
Expand Down
3 changes: 2 additions & 1 deletion managers/TokenManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0ce49e8

Please sign in to comment.