diff --git a/Source/Engine/Gramambular/Grid.h b/Source/Engine/Gramambular/Grid.h index 53d52e02..ee5a3bf3 100644 --- a/Source/Engine/Gramambular/Grid.h +++ b/Source/Engine/Gramambular/Grid.h @@ -47,6 +47,7 @@ namespace Formosa { size_t width() const; vector nodesEndingAt(size_t inLocation); vector nodesCrossingOrEndingAt(size_t inLocation); + void fixNodeSelectedCandidate(size_t location, const string& value); const string dumpDOT(); @@ -175,6 +176,20 @@ namespace Formosa { return result; } + // For nodes found at the location, fix their currently-selected candidate using the supplied string value. + inline void Grid::fixNodeSelectedCandidate(size_t location, const string& value) + { + vector nodes = nodesCrossingOrEndingAt(location); + for (auto nodeAnchor : nodes) { + auto candidates = nodeAnchor.node->candidates(); + for (size_t i = 0, c = candidates.size(); i < c; ++i) { + if (candidates[i].value == value) { + const_cast(nodeAnchor.node)->selectCandidateAtIndex(i); + break; + } + } + } + } inline const string Grid::dumpDOT() { diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 1de10626..0af52c86 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -1471,19 +1471,7 @@ public: } size_t cursorIndex = [self actualCandidateCursorIndex]; - vector nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); - - for (vector::iterator ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) { - const vector& candidates = (*ni).node->candidates(); - - for (size_t i = 0, c = candidates.size(); i < c; ++i) { - if (candidates[i].value == selectedValue) { - // found our node - const_cast((*ni).node)->selectCandidateAtIndex(i); - break; - } - } - } + _builder->grid().fixNodeSelectedCandidate(cursorIndex, selectedValue); [_candidates removeAllObjects];