static int ScanWord (TextDocument doc, int offset, bool forwardDirection)
{
if (offset < 0 || offset >= doc.TextLength)
return offset;
var line = doc.GetLineByOffset (offset);
char first = doc.GetCharAt (offset);
if (char.IsPunctuation (first))
return forwardDirection ? System.Math.Min (line.Offset + line.Length, offset + 1) : System.Math.Max (line.Offset, offset);
while (offset >= line.Offset && offset < line.Offset + line.Length) {
char ch = doc.GetCharAt (offset);
if (char.IsWhiteSpace (first) && !char.IsWhiteSpace (ch)
|| WordFindStrategy.IsNoIdentifierPart (first) && !WordFindStrategy.IsNoIdentifierPart (ch)
|| (char.IsLetterOrDigit (first) || first == '_') && !(char.IsLetterOrDigit (ch) || ch == '_'))
break;
offset = forwardDirection ? offset + 1 : offset - 1;
}
return System.Math.Min (line.Offset + line.Length,
System.Math.Max (line.Offset, offset + (forwardDirection ? 0 : 1)));
}