private static bool PreviousUnit(int start, ITextRange subrange, TomUnit unit) { if (subrange.Start <= start) { return false; } else { // collapse the range to the end and then extend it another unit. subrange.Collapse(TomStartEnd.tomStart); subrange.MoveStart(unit, -1); // truncate if necessary to ensure it fits inside the range if (subrange.Start < start) { subrange.Start = start; } return true; } }
private static bool NextUnit(int end, ITextRange subrange, TomUnit unit) { if (subrange.End >= end) { return false; } else { // collapse the range to the end and then extend it another unit. subrange.Collapse(TomStartEnd.tomEnd); subrange.MoveEnd(unit, 1); // truncate if necessary to ensure it fits inside the range if (subrange.End > end) { subrange.End = end; } return true; } }