Simplify candidate fixing by moving code to Grid
This commit is contained in:
parent
71e232c89c
commit
71b97f82b3
|
@ -47,6 +47,7 @@ namespace Formosa {
|
||||||
size_t width() const;
|
size_t width() const;
|
||||||
vector<NodeAnchor> nodesEndingAt(size_t inLocation);
|
vector<NodeAnchor> nodesEndingAt(size_t inLocation);
|
||||||
vector<NodeAnchor> nodesCrossingOrEndingAt(size_t inLocation);
|
vector<NodeAnchor> nodesCrossingOrEndingAt(size_t inLocation);
|
||||||
|
void fixNodeSelectedCandidate(size_t location, const string& value);
|
||||||
|
|
||||||
const string dumpDOT();
|
const string dumpDOT();
|
||||||
|
|
||||||
|
@ -175,6 +176,20 @@ namespace Formosa {
|
||||||
return result;
|
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<NodeAnchor> 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<Node*>(nodeAnchor.node)->selectCandidateAtIndex(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline const string Grid::dumpDOT()
|
inline const string Grid::dumpDOT()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1471,19 +1471,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t cursorIndex = [self actualCandidateCursorIndex];
|
size_t cursorIndex = [self actualCandidateCursorIndex];
|
||||||
vector<NodeAnchor> nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex);
|
_builder->grid().fixNodeSelectedCandidate(cursorIndex, selectedValue);
|
||||||
|
|
||||||
for (vector<NodeAnchor>::iterator ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) {
|
|
||||||
const vector<KeyValuePair>& 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<Node*>((*ni).node)->selectCandidateAtIndex(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[_candidates removeAllObjects];
|
[_candidates removeAllObjects];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue