/// <summary> /// Calculate index of the next word. /// </summary> public static int Calc_NextWord(IViewInternal view) { int index; Document doc = view.Document; // if EOL code comes, return just after them if (Utl.IsEol(doc, doc.CaretIndex)) { return(Utl.SkipOneEol(doc, doc.CaretIndex)); } // if the caret is at the end of document, return end of document index = doc.CaretIndex + 1; if (doc.Length <= index) { return(doc.Length); } // seek to next word starting position index = doc.WordProc.NextWordStart(doc, index); // skip trailling whitespace if (Utl.IsWhiteSpace(doc, index)) { index = doc.WordProc.NextWordStart(doc, index + 1); } return(index); }
/// <summary> /// Calculate index of the previous word. /// </summary> public static int Calc_PrevWord(IViewInternal view) { int index; int startIndex; Document doc = view.Document; // if the caret is at the head of document, return head of document index = doc.CaretIndex - 1; if (index <= 0) { return(0); } // skip whitespace startIndex = index; if (Utl.IsWhiteSpace(doc, index)) { index = doc.WordProc.PrevWordStart(doc, index) - 1; if (index < 0) { return(0); } } DebugUtl.Assert(0 <= index && index <= doc.Length); // if EOL code comes, return just before them if (Utl.IsEol(doc, index)) { if (startIndex != index) { // do not skip this EOL code // if this was detected after skipping whitespaces return(index + 1); } else if (doc[index] == '\r') { return(index); } else { DebugUtl.Assert(doc[index] == '\n'); if (0 <= index - 1 && doc[index - 1] == '\r') { return(index - 1); } else { return(index); } } } // seek to previous word starting position index = doc.WordProc.PrevWordStart(doc, index); return(index); }