namespace FooEditEngine
{
- internal enum MoveFlow
+ public enum MoveFlow
{
- Horizontical,
- Vertical,
+ Character,
+ Word,
+ Line,
+ Paragraph
}
internal enum ScrollDirection
{
public void MoveCaretHorizontical(int realLength, bool isSelected,bool alignWord = false)
{
TextPoint caret = this.Document.CaretPostion;
- for (int i = Math.Abs(realLength); i > 0; i--)
- {
- bool MoveFlow = realLength > 0;
- if (this.Document.RightToLeft)
- MoveFlow = !MoveFlow;
- caret = this.MoveCaretHorizontical(caret,MoveFlow);
-
- if (alignWord)
- caret = this.AlignNearestWord(caret, MoveFlow);
- }
+ int moved;
+ caret = GetNextCaret(caret, realLength, alignWord ? MoveFlow.Word : MoveFlow.Character,out moved);
this.View.JumpCaret(caret.row, caret.col, false);
this.View.AdjustCaretAndSrc(AdjustFlow.Both);
this.SelectWithMoveCaret(isSelected);
}
+ /// <summary>
+ /// 移動後のキャレット位置を求める
+ /// </summary>
+ /// <param name="caret">起点となるキャレット位置</param>
+ /// <param name="count">移動量</param>
+ /// <param name="method">移動方法</param>
+ /// <param name="moved">実際に移動した量</param>
+ /// <returns>移動後のキャレット位置</returns>
+ public TextPoint GetNextCaret(TextPoint caret, int count,MoveFlow method,out int moved)
+ {
+ moved = 0;
+ if(method == MoveFlow.Character || method == MoveFlow.Word)
+ {
+ for (int i = Math.Abs(count); i > 0; i--)
+ {
+ bool moveFlow = count > 0;
+ if (this.Document.RightToLeft)
+ moveFlow = !moveFlow;
+ caret = this.MoveCaretHorizontical(caret, moveFlow);
+
+ if (method == FooEditEngine.MoveFlow.Word)
+ caret = this.AlignNearestWord(caret, moveFlow);
+ moved++;
+ }
+ }
+ if(method == MoveFlow.Line || method == MoveFlow.Paragraph)
+ {
+ for (int i = Math.Abs(count); i > 0; i--)
+ {
+ caret = this.MoveCaretVertical(caret, count > 0);
+ moved++;
+ }
+ }
+ if (count < 0)
+ moved = -moved;
+ return caret;
+ }
+
TextPoint AlignNearestWord(TextPoint caret,bool MoveFlow)
{
string str = this.View.LayoutLines[caret.row];
public void MoveCaretVertical(int deltarow,bool isSelected)
{
TextPoint caret = this.Document.CaretPostion;
- for (int i = Math.Abs(deltarow); i > 0; i--)
- caret = this.MoveCaretVertical(caret, deltarow > 0);
+ int moved;
+ caret = this.GetNextCaret(caret, deltarow, MoveFlow.Line,out moved);
this.View.JumpCaret(caret.row, caret.col, true);
this.View.AdjustCaretAndSrc(AdjustFlow.Both);
this.SelectWithMoveCaret(isSelected);