From 67b00dfd7db636e83b2b29ea5a5ee6a3d8375e1c Mon Sep 17 00:00:00 2001 From: Casey Date: Tue, 6 Oct 2020 15:15:50 +0800 Subject: [PATCH] =?UTF-8?q?#34=20bug=20with=20shey=20punctuation=20?= =?UTF-8?q?=E0=BC=8D=20Fixs=20small=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- managers/TokenManager.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/managers/TokenManager.py b/managers/TokenManager.py index 3904d8a..3288afd 100644 --- a/managers/TokenManager.py +++ b/managers/TokenManager.py @@ -266,6 +266,7 @@ def diff(self, tokens, oldText, newText): newString = '' sameStringLength = 0 isDeleteShey = False + isDeleteLastShey = False sheyIsMoreThanOne = False i = 0 for op, string in changes: @@ -328,6 +329,11 @@ def diff(self, tokens, oldText, newText): if numOfShey > 1: sheyIsMoreThanOne = True + # 當刪除的地方在最後而且又是 ། + if i + 1 == len(changes): + if string == '།': + isDeleteLastShey = True + if start == -1: # 改的地方前面沒有'།'或'\n' start = 0 else: @@ -346,8 +352,10 @@ def diff(self, tokens, oldText, newText): #當 ། 有很多個同時在一起時 if endOld == endNew: endOld += 1 - if isDeleteShey: + if isDeleteShey and not isDeleteLastShey: endOld = endNew + 1 + if isDeleteLastShey: + endNew = endOld - 1 # 在文章最後面加字 if (tokens[-1].end == changePos) or (changePos == -1): @@ -382,7 +390,13 @@ def diff(self, tokens, oldText, newText): tokenEnd = i break i += 1 + # 前後 scan 得到的修改後字串 afterChangingString = newText[start: endNew + 1] + if len(tokens) > tokenStart and afterChangingString != '།': + # 當 tokens 裡為 །། 時,afterChangingString 要多加 ། 在最前面,不然取代掉時會少 + if '།།' == tokens[tokenStart].text: + afterChangingString = f'།{afterChangingString}' + return tokenStart, tokenEnd, afterChangingString