OSDN Git Service

シフトキーを押したときも正しく選択できないバグを修正した
authorkonekoneko <test2214@hotmail.co.jp>
Sat, 5 Nov 2016 06:17:41 +0000 (11:47 +0530)
committerkonekoneko <test2214@hotmail.co.jp>
Sat, 5 Nov 2016 06:17:41 +0000 (11:47 +0530)
Core/Controller.cs

index c8001a3..7489e6b 100644 (file)
@@ -55,6 +55,7 @@ namespace FooEditEngine
     {
         EditView View;
         Document _Document;
+        bool keepAnchor = false;
         
         public Controller(Document doc, EditView view)
         {
@@ -95,6 +96,8 @@ namespace FooEditEngine
 
         private void _Document_CaretChanged(object sender, EventArgs e)
         {
+            if (keepAnchor)
+                return;
             TextPoint pos = this.Document.CaretPostion;
             this.JumpCaret(pos.row, pos.col);
         }
@@ -497,6 +500,7 @@ namespace FooEditEngine
         /// <param name="alignWord">単語単位で移動するなら真。そうでないなら偽</param>
         public void MoveCaretHorizontical(int realLength, bool isSelected,bool alignWord = false)
         {
+            keepAnchor = true;
             for (int i = Math.Abs(realLength); i > 0; i--)
             {
                 bool MoveFlow = realLength > 0;
@@ -509,6 +513,7 @@ namespace FooEditEngine
             }
             this.View.AdjustCaretAndSrc(AdjustFlow.Col);
             this.SelectWithMoveCaret(isSelected);
+            keepAnchor = false;
         }
 
         void AlignNearestWord(bool MoveFlow)
@@ -539,10 +544,12 @@ namespace FooEditEngine
         /// <param name="isSelected"></param>
         public void MoveCaretVertical(int deltarow,bool isSelected)
         {
+            keepAnchor = true;
             for (int i = Math.Abs(deltarow); i > 0; i--)
                 this.MoveCaretVertical(deltarow > 0);
             this.View.AdjustCaretAndSrc(AdjustFlow.Both);
             this.SelectWithMoveCaret(isSelected);
+            keepAnchor = false;
         }
 
         /// <summary>
@@ -731,13 +738,12 @@ namespace FooEditEngine
         /// <param name="tp"></param>
         public void MoveCaretAndSelect(TextPoint tp)
         {
+            keepAnchor = true;
             int CaretPostion = this.View.GetIndexFromLayoutLine(tp);
-            //キャレットを移動するとアンカーインデックスが再設定されてしまうので覚えておく
-            int oldAnchorIndex = this.Document.AnchorIndex;
             this.Document.Select(this.Document.AnchorIndex, CaretPostion - this.Document.AnchorIndex);
             this.View.JumpCaret(tp.row, tp.col);
             this.View.AdjustCaretAndSrc();
-            this.Document.AnchorIndex = oldAnchorIndex;
+            keepAnchor = false;
         }
 
         /// <summary>
@@ -953,7 +959,7 @@ namespace FooEditEngine
                 throw new InvalidOperationException("");
 
             TextPoint nextPoint = this.GetTextPointAfterMoveLine(isMoveNext ? 1 : -1, this.Document.CaretPostion);
-            
+
             this.View.JumpCaret(nextPoint.row, nextPoint.col,false);
         }