diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index 8d9a4279..88d8a974 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -555,6 +555,8 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; - (void)dealWithOverrideModelSuggestions { + // 讓 grid 知道目前的游標候選字判定是前置還是後置 + _builder->grid().setHaninInputEnabled(!mgrPrefs.selectPhraseAfterCursorAsCandidate); // 這一整段都太 C++ 且只出現一次,就整個端過來了。 // 拆開封裝的話,只會把問題搞得更麻煩而已。 std::string overrideValue = (mgrPrefs.useSCPCTypingMode) @@ -599,6 +601,9 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; - (NSArray *)getCandidatesArray { + // 讓 grid 知道目前的游標候選字判定是前置還是後置 + _builder->grid().setHaninInputEnabled(!mgrPrefs.selectPhraseAfterCursorAsCandidate); + NSMutableArray *candidatesArray = [[NSMutableArray alloc] init]; NSInteger cursorIndex = [self getActualCandidateCursorIndex]; diff --git a/Source/Modules/LanguageParsers/Gramambular/Grid.h b/Source/Modules/LanguageParsers/Gramambular/Grid.h index 0244d076..52b3e7da 100644 --- a/Source/Modules/LanguageParsers/Gramambular/Grid.h +++ b/Source/Modules/LanguageParsers/Gramambular/Grid.h @@ -44,6 +44,9 @@ class Grid void insertNode(const Node &node, size_t location, size_t spanningLength); bool hasNodeAtLocationSpanningLengthMatchingKey(size_t location, size_t spanningLength, const std::string &key); + void setHaninInputEnabled(bool enabled); + bool HaninInputEnabled(); + void expandGridByOneAtLocation(size_t location); void shrinkGridByOneAtLocation(size_t location); @@ -116,8 +119,19 @@ class Grid protected: std::vector m_spans; + bool m_bolHaninEnabled; }; +inline void Grid::setHaninInputEnabled(bool enabled) +{ + m_bolHaninEnabled = enabled; +} + +inline bool Grid::HaninInputEnabled() +{ + return m_bolHaninEnabled; +} + inline void Grid::clear() { m_spans.clear(); @@ -234,7 +248,9 @@ inline std::vector Grid::nodesCrossingOrEndingAt(size_t location) { for (size_t j = 1, m = span.maximumLength(); j <= m; j++) { - if (i + j < location) + // 左半是漢音模式,已經自威注音 1.5.2 版開始解決了可以在詞中間叫出候選字的問題。 + // TODO: 右半是微軟新注音模式,仍有可以在詞中間叫出候選字的問題。 + if (((i + j != location) && m_bolHaninEnabled) || ((i + j < location) && !m_bolHaninEnabled)) { continue; }