OSDN Git Service

キャレットの移動周りで無駄な動作を省いた
authortest <test@yahoo.co.jp>
Fri, 1 Jan 2021 06:41:36 +0000 (15:41 +0900)
committertest <test@yahoo.co.jp>
Fri, 1 Jan 2021 06:41:36 +0000 (15:41 +0900)
Core/Controller.cs

index f2a8f4c..fa97f54 100644 (file)
@@ -518,41 +518,41 @@ namespace FooEditEngine
         /// <param name="alignWord">単語単位で移動するなら真。そうでないなら偽</param>
         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;
-                this.MoveCaretHorizontical(MoveFlow);
+                caret = this.MoveCaretHorizontical(caret,MoveFlow);
 
                 if (alignWord)
-                    this.AlignNearestWord(MoveFlow);
+                    caret = this.AlignNearestWord(caret, MoveFlow);
             }
-            if(this.Document.LayoutLines.WrapWidth == LineToIndexTable.NONE_BREAK_LINE)
-               this.View.AdjustCaretAndSrc(AdjustFlow.Col);
-            else
-                this.View.AdjustCaretAndSrc(AdjustFlow.Both);
+            this.View.JumpCaret(caret.row, caret.col, false);
+            this.View.AdjustCaretAndSrc(AdjustFlow.Both);
             this.SelectWithMoveCaret(isSelected);
         }
 
-        void AlignNearestWord(bool MoveFlow)
+        TextPoint AlignNearestWord(TextPoint caret,bool MoveFlow)
         {
-            string str = this.View.LayoutLines[this.Document.CaretPostion.row];
-            while (this.Document.CaretPostion.col > 0 &&
-                this.Document.CaretPostion.col < str.Length &&
-                str[this.Document.CaretPostion.col] != Document.NewLine)
+            string str = this.View.LayoutLines[caret.row];
+            while (caret.col > 0 &&
+                caret.col < str.Length &&
+                str[caret.col] != Document.NewLine)
             {
-                if (!Util.IsWordSeparator(str[this.Document.CaretPostion.col]))
+                if (!Util.IsWordSeparator(str[caret.col]))
                 {
-                    this.MoveCaretHorizontical(MoveFlow);
+                    caret = this.MoveCaretHorizontical(caret, MoveFlow);
                 }
                 else
                 {
                     if(MoveFlow)
-                        this.MoveCaretHorizontical(MoveFlow);
+                        caret = this.MoveCaretHorizontical(caret, MoveFlow);
                     break;
                 }
             }
+            return caret;
         }
 
         /// <summary>
@@ -563,8 +563,10 @@ namespace FooEditEngine
         /// <param name="isSelected"></param>
         public void MoveCaretVertical(int deltarow,bool isSelected)
         {
+            TextPoint caret = this.Document.CaretPostion;
             for (int i = Math.Abs(deltarow); i > 0; i--)
-                this.MoveCaretVertical(deltarow > 0);
+                caret = this.MoveCaretVertical(caret, deltarow > 0);
+            this.View.JumpCaret(caret.row, caret.col, true);
             this.View.AdjustCaretAndSrc(AdjustFlow.Both);
             this.SelectWithMoveCaret(isSelected);
         }
@@ -949,43 +951,41 @@ namespace FooEditEngine
         /// <summary>
         /// キャレットを一文字移動させる
         /// </summary>
+        /// <param name="caret">キャレット</param>
         /// <param name="isMoveNext">真なら1文字すすめ、そうでなければ戻す</param>
         /// <remarks>このメソッドを呼び出した後でScrollToCaretメソッドとSelectWithMoveCaretメソッドを呼び出す必要があります</remarks>
-        void MoveCaretHorizontical(bool isMoveNext)
+        TextPoint MoveCaretHorizontical(TextPoint caret,bool isMoveNext)
         {
             if (this.Document.FireUpdateEvent == false)
                 throw new InvalidOperationException("");
             int delta = isMoveNext ? 0 : -1;
-            int prevcol = this.Document.CaretPostion.col;
-            int col = this.Document.CaretPostion.col + delta;
-            string lineString = this.View.LayoutLines[this.Document.CaretPostion.row];
-            if (col < 0 || this.Document.CaretPostion.row >= this.View.LayoutLines.Count)
+            int prevcol = caret.col;
+            int col = caret.col + delta;
+            string lineString = this.View.LayoutLines[caret.row];
+            if (col < 0 || caret.row >= this.View.LayoutLines.Count)
             {
-                if (this.Document.CaretPostion.row == 0)
+                if (caret.row == 0)
                 {
-                    col = 0;
-                    return;
+                    caret.col = 0;
+                    return caret;
                 }
-                this.MoveCaretVertical(false);
-                this.View.AdjustCaretAndSrc(AdjustFlow.Row);  //この段階で調整しないとスクロールされない
-                col = this.View.LayoutLines.GetLengthFromLineNumber(this.Document.CaretPostion.row) - 1;  //最終行以外はすべて改行コードが付くはず
+                caret = this.MoveCaretVertical(caret,false);
+                caret.col = this.View.LayoutLines.GetLengthFromLineNumber(caret.row) - 1;  //最終行以外はすべて改行コードが付くはず
             }
             else if (col >= lineString.Length || lineString[col] == Document.NewLine)
             {
-                if (this.Document.CaretPostion.row < this.View.LayoutLines.Count - 1)
+                if (caret.row < this.View.LayoutLines.Count - 1)
                 {
-                    this.MoveCaretVertical(true);
-                    this.View.AdjustCaretAndSrc(AdjustFlow.Row);  //この段階で調整しないとスクロールされない
-                    col = 0;
+                    caret = this.MoveCaretVertical(caret, true);
+                    caret.col = 0;
                 }
             }
             else
             {
                 AlignDirection direction = isMoveNext ? AlignDirection.Forward : AlignDirection.Back;
-                col = this.View.LayoutLines.GetLayout(this.Document.CaretPostion.row).AlignIndexToNearestCluster(col, direction);
+                caret.col = this.View.LayoutLines.GetLayout(caret.row).AlignIndexToNearestCluster(col, direction);
             }
-
-            this.View.JumpCaret(this.Document.CaretPostion.row, col,false);
+            return caret;
         }
 
         /// <summary>
@@ -993,14 +993,12 @@ namespace FooEditEngine
         /// </summary>
         /// <param name="isMoveNext">プラス方向に移動するなら真</param>
         /// <remarks>このメソッドを呼び出した後でScrollToCaretメソッドとSelectWithMoveCaretメソッドを呼び出す必要があります</remarks>
-        void MoveCaretVertical(bool isMoveNext)
+        TextPoint MoveCaretVertical(TextPoint caret,bool isMoveNext)
         {
             if (this.Document.FireUpdateEvent == false)
                 throw new InvalidOperationException("");
 
-            TextPoint nextPoint = this.GetTextPointAfterMoveLine(isMoveNext ? 1 : -1, this.Document.CaretPostion);
-
-            this.View.JumpCaret(nextPoint.row, nextPoint.col,false);
+            return this.GetTextPointAfterMoveLine(isMoveNext ? 1 : -1, this.Document.CaretPostion);
         }
 
         private void ReplaceBeforeSelectionArea(SelectCollection Selections, int removeLength, string insertStr)