// Sanity check
if (startOffset < 0 || startOffset >= units.length)
startOffset = 0;
// Now iterate though the units and find the first one that is acceptable
IMXMLUnitData ret = null;
for (int i = startOffset; (i < units.length) && (ret == null); i++)
{
IMXMLUnitData unit = units[i];
// unit is a match if it "contains" the offset.
// We are using a somewhat bizarre form of "contains" here, in that we are
// using getStart() and getConentEnd(). This asymmetric mismatch is for several reasons:
// * it's the only way to match the existing (non-falcon) behavior
// * If our cursor is before the <, we want to match the tag.
// example: |<foo > will find "foo" as the nearest tag.
// So we need to use start here (not content start)
// * If our cursor is between two tags, we want to match the NEXT one, not the previous one
// example: <bar >|<foo> should match foo, not bar
if (MXMLData.contains(unit.getAbsoluteStart(), unit.getContentEnd(), offset))
{
ret = unit;
}
// if we find a unit that starts after the offset, then it must
// be the "first one after", so return it
else if (unit.getAbsoluteStart() >= offset)
{
ret = unit;
}
}