/// <summary> /// 現在位置の単語を選択する。 /// </summary> public void SelectWord() { if (CurrentLine.IsEmpty) { return; } var text = CurrentLine.Text; var charIndex = (Caret.Pos.CharIndex < text.Length) ? Caret.Pos.CharIndex : Caret.Pos.CharIndex - 1; var currentChar = text[charIndex]; var prevCharIndex = charIndex; while (0 < prevCharIndex && CharUtil.EqualsWordGroup(currentChar, text[prevCharIndex - 1])) { prevCharIndex--; } var nextCharIndex = charIndex + 1; while (nextCharIndex < text.Length && CharUtil.EqualsWordGroup(currentChar, text[nextCharIndex])) { nextCharIndex++; } ClearSelect(); _anchorPos = new TextPos(Caret.Pos.LineIndex, prevCharIndex); SetCaretPos(new TextPos(Caret.Pos.LineIndex, nextCharIndex), true, true); }
/// <summary> /// 次の単語へ移動。 /// </summary> public void MoveNextWord(bool isSelect) { if (Caret.Pos == CurrentLineEndPos) { MoveRight(isSelect); return; } var text = CurrentLine.Text; var charIndex = Caret.Pos.CharIndex + 1; while (charIndex < text.Length && CharUtil.EqualsWordGroup(text[charIndex - 1], text[charIndex])) { charIndex++; } while (charIndex < text.Length && Char.IsWhiteSpace(text[charIndex])) { charIndex++; } SetCaretPos(new TextPos(Caret.Pos.LineIndex, charIndex), isSelect, true); }
/// <summary> /// 前の単語へ移動。 /// </summary> public void MovePrevWord(bool isSelect) { if (Caret.Pos == CurrentLineTopPos) { MoveLeft(isSelect); return; } var text = CurrentLine.Text; var charIndex = Caret.Pos.CharIndex - 1; while (0 < charIndex && Char.IsWhiteSpace(text[charIndex])) { charIndex--; } while (0 < charIndex && CharUtil.EqualsWordGroup(text[charIndex], text[charIndex - 1])) { charIndex--; } SetCaretPos(new TextPos(Caret.Pos.LineIndex, charIndex), isSelect, true); }