Skip to content

Commit

Permalink
Fix a regression bug caused by missing null check introduced in PR #570
Browse files Browse the repository at this point in the history
… shift move cursor.
  • Loading branch information
PCMan committed Apr 8, 2020
1 parent 4ba923b commit 6a94a35
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions python/input_methods/chewing/chewing_ime.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def onKeyDown(self, keyEvent):
# return False,表示我們不需要這個鍵,系統會原封不動把按鍵傳給應用程式
def filterKeyUp(self, keyEvent):
# 最後按下和放開都是 Shift 鍵
if self.lastKeyEvent.keyCode == VK_SHIFT and keyEvent.keyCode == VK_SHIFT:
if self.lastKeyEvent and self.lastKeyEvent.keyCode == VK_SHIFT and keyEvent.keyCode == VK_SHIFT:
# 若啟用使用 Shift 在打字時移動游標,呼叫onKeyUp()
if chewingConfig.shiftMoveCursor:
return True
Expand All @@ -624,7 +624,7 @@ def filterKeyUp(self, keyEvent):
self.toggleLanguageMode() # 切換中英文模式

# 使用 Ctrl + F12 切換簡體/繁體中文
if chewingConfig.enableSwitchTCSC:
if chewingConfig.enableSwitchTCSC and self.lastKeyEvent:
if keyEvent.isKeyDown(VK_CONTROL) and self.lastKeyEvent.keyCode == VK_F12 and keyEvent.keyCode == VK_F12:
self.setOutputSimplifiedChinese(not self.outputSimpChinese)

Expand All @@ -634,12 +634,13 @@ def filterKeyUp(self, keyEvent):
def onKeyUp(self, keyEvent):
pressedDuration = time.time() - self.lastKeyDownTime
if pressedDuration < 0.5 and self.isComposing() and not self.chewingContext.bopomofo_Check():
if self.lastKeyEvent.isKeyDown(VK_RSHIFT) and self.compositionCursor < len(self.compositionString):
self.chewingContext.handle_Right()
self.setCompositionCursor(self.chewingContext.cursor_Current())
if self.lastKeyEvent.isKeyDown(VK_LSHIFT) and self.compositionCursor > 0:
self.chewingContext.handle_Left()
self.setCompositionCursor(self.chewingContext.cursor_Current())
if self.lastKeyEvent:
if self.lastKeyEvent.isKeyDown(VK_RSHIFT) and self.compositionCursor < len(self.compositionString):
self.chewingContext.handle_Right()
self.setCompositionCursor(self.chewingContext.cursor_Current())
if self.lastKeyEvent.isKeyDown(VK_LSHIFT) and self.compositionCursor > 0:
self.chewingContext.handle_Left()
self.setCompositionCursor(self.chewingContext.cursor_Current())

self.lastKeyDownTime = 0.0
return True
Expand Down

0 comments on commit 6a94a35

Please sign in to comment.