From 723437d0858b41097e25b2500a286084f2b98191 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 24 Jun 2023 22:42:53 +0800 Subject: [PATCH] InputHandler // Deduplicate `%quick` results for IMKCandidates. --- Source/Modules/InputHandler_HandleComposition.swift | 9 +++++++-- Source/Modules/InputHandler_HandleStates.swift | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Source/Modules/InputHandler_HandleComposition.swift b/Source/Modules/InputHandler_HandleComposition.swift index 20c52d98..dcc9586b 100644 --- a/Source/Modules/InputHandler_HandleComposition.swift +++ b/Source/Modules/InputHandler_HandleComposition.swift @@ -271,8 +271,13 @@ extension InputHandler { if !isStrokesFull { var result = generateStateOfInputting() - if !calligrapher.isEmpty, let fetched = currentLM.cassetteQuickSetsFor(key: calligrapher) { - result.candidates = fetched.map { (keyArray: [""], value: $0.description) } + if !calligrapher.isEmpty, var fetched = currentLM.cassetteQuickSetsFor(key: calligrapher) { + if prefs.useIMKCandidateWindow { + fetched = fetched.deduplicated.filter { $0.description != currentLM.nullCandidateInCassette } + } + result.candidates = fetched.enumerated().map { + (keyArray: [$0.offset.description], value: $0.element.description) + } } delegate.switchState(result) return true diff --git a/Source/Modules/InputHandler_HandleStates.swift b/Source/Modules/InputHandler_HandleStates.swift index 843bddb1..d613d72a 100644 --- a/Source/Modules/InputHandler_HandleStates.swift +++ b/Source/Modules/InputHandler_HandleStates.swift @@ -507,8 +507,13 @@ extension InputHandler { switch isConsideredEmptyForNow { case false: var result = generateStateOfInputting() - if prefs.cassetteEnabled, let fetched = currentLM.cassetteQuickSetsFor(key: calligrapher) { - result.candidates = fetched.map { (keyArray: [""], value: $0.description) } + if prefs.cassetteEnabled, var fetched = currentLM.cassetteQuickSetsFor(key: calligrapher) { + if prefs.useIMKCandidateWindow { + fetched = fetched.deduplicated.filter { $0.description != currentLM.nullCandidateInCassette } + } + result.candidates = fetched.enumerated().map { + (keyArray: [$0.offset.description], value: $0.element.description) + } } delegate.switchState(result) case true: delegate.switchState(IMEState.ofAbortion())