int FindWordEnd(IDocument document, int offset)
{
LineSegment line = document.GetLineSegmentForOffset(offset);
if (line.Length == 0)
return offset;
int endPos = line.Offset + line.Length;
offset = Math.Min(offset, endPos - 1);
if (IsSelectableChar(document.GetCharAt(offset))) {
while (offset < endPos && IsSelectableChar(document.GetCharAt(offset))) {
++offset;
}
} else if (Char.IsWhiteSpace(document.GetCharAt(offset))) {
if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1))) {
while (offset < endPos && Char.IsWhiteSpace(document.GetCharAt(offset))) {
++offset;
}
}
} else {
return Math.Max(0, offset + 1);
}
return offset;
}
TextLocation minSelection = TextLocation.Empty;