diff --git a/Source/Modules/InputHandler_Core.swift b/Source/Modules/InputHandler_Core.swift index 904f11be..05821b9b 100644 --- a/Source/Modules/InputHandler_Core.swift +++ b/Source/Modules/InputHandler_Core.swift @@ -428,10 +428,18 @@ public class InputHandler: InputHandlerProtocol { preConsolidate: PrefMgr.shared.consolidateContextOnCandidateSelection, skipObservation: true ) - let inputting = generateStateOfInputting(sansReading: true) - theState.data.displayTextSegments = inputting.data.displayTextSegments - theState.data.cursor = inputting.cursor - theState.data.marker = inputting.marker + theState.data.displayTextSegments = compositor.walkedNodes.values + theState.data.cursor = convertCursorForDisplay(compositor.cursor) + let markerBackup = compositor.marker + if compositor.cursor == compositor.length { + compositor.jumpCursorBySpan(to: .rear, isMarker: true) + } else if compositor.cursor == 0 { + compositor.jumpCursorBySpan(to: .front, isMarker: true) + } else { + compositor.jumpCursorBySpan(to: prefs.useRearCursorMode ? .front : .rear, isMarker: true) + } + theState.data.marker = compositor.marker + compositor.marker = markerBackup delegate.state = theState // 直接就地取代,不經過 switchState 處理,免得選字窗被重新載入。 delegate.setInlineDisplayWithCursor() delegate.updatePopupDisplayWithCursor() diff --git a/Source/Modules/InputHandler_HandleStates.swift b/Source/Modules/InputHandler_HandleStates.swift index f9ac8479..4046eb31 100644 --- a/Source/Modules/InputHandler_HandleStates.swift +++ b/Source/Modules/InputHandler_HandleStates.swift @@ -124,11 +124,18 @@ extension InputHandler { /// 拿著給定的候選字詞陣列資料內容,切換至選字狀態。 /// - Returns: 回呼一個新的選詞狀態,來就給定的候選字詞陣列資料內容顯示選字窗。 public func generateStateOfCandidates() -> IMEStateProtocol { - IMEState.ofCandidates( + var result = IMEState.ofCandidates( candidates: generateArrayOfCandidates(fixOrder: prefs.useFixecCandidateOrderOnSelection), displayTextSegments: compositor.walkedNodes.values, cursor: delegate?.state.cursor ?? generateStateOfInputting().cursor ) + if !prefs.useRearCursorMode { + let markerBackup = compositor.marker + compositor.jumpCursorBySpan(to: .rear, isMarker: true) + result.marker = compositor.marker + compositor.marker = markerBackup + } + return result } // MARK: - 用以接收聯想詞陣列且生成狀態