OSDN Git Service

関連付けからの起動もできるようにした
[fooeditengine/FooEditEngine.git] / Core / Controller.cs
index 7489e6b..fb5f39f 100644 (file)
@@ -55,7 +55,6 @@ namespace FooEditEngine
     {
         EditView View;
         Document _Document;
-        bool keepAnchor = false;
         
         public Controller(Document doc, EditView view)
         {
@@ -63,7 +62,7 @@ namespace FooEditEngine
             this.View = view;
             this.View.render.ChangedRenderResource += render_ChangedRenderResource;
             this.View.PageBoundChanged += View_PageBoundChanged;
-            this.Document.Clear();
+            //this.Document.Clear();
         }
 
         public Document Document
@@ -96,8 +95,6 @@ namespace FooEditEngine
 
         private void _Document_CaretChanged(object sender, EventArgs e)
         {
-            if (keepAnchor)
-                return;
             TextPoint pos = this.Document.CaretPostion;
             this.JumpCaret(pos.row, pos.col);
         }
@@ -106,13 +103,17 @@ namespace FooEditEngine
         {
             if (this.IsReverseSelect())
             {
-                this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.SelectionStart);
-                this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.SelectionStart + this.SelectionLength);
+                if (this.Document.SelectGrippers.BottomRight.Enabled)
+                    this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.SelectionStart);
+                if (this.Document.SelectGrippers.BottomLeft.Enabled)
+                    this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.SelectionStart + this.SelectionLength);
             }
             else
             {
-                this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.SelectionStart);
-                this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.SelectionStart + this.SelectionLength);
+                if (this.Document.SelectGrippers.BottomLeft.Enabled)
+                    this.Document.SelectGrippers.BottomLeft.MoveByIndex(this.View, this.SelectionStart);
+                if (this.Document.SelectGrippers.BottomRight.Enabled)
+                    this.Document.SelectGrippers.BottomRight.MoveByIndex(this.View, this.SelectionStart + this.SelectionLength);
             }
         }
 
@@ -500,7 +501,6 @@ 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;
@@ -513,7 +513,6 @@ namespace FooEditEngine
             }
             this.View.AdjustCaretAndSrc(AdjustFlow.Col);
             this.SelectWithMoveCaret(isSelected);
-            keepAnchor = false;
         }
 
         void AlignNearestWord(bool MoveFlow)
@@ -544,12 +543,10 @@ 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>
@@ -578,7 +575,7 @@ namespace FooEditEngine
             if (this.Document[index] == Document.NewLine)
                 next = index + 1;
 
-            this.Document.Replace(index, next - index, "");
+            this.Document.Replace(index, next - index, "", true);
         }
 
         public bool IsRectInsertMode()
@@ -631,7 +628,7 @@ namespace FooEditEngine
                 newIndex--;
             }
 
-            this.Document.Replace(newIndex, oldIndex - newIndex, "");
+            this.Document.Replace(newIndex, oldIndex - newIndex, "", true);
         }
 
         /// <summary>
@@ -702,7 +699,7 @@ namespace FooEditEngine
                 if (foldingData != null && !foldingData.Expand && index > foldingData.Start && index <= foldingData.End)
                     index = foldingData.End + 1;
             }
-            this.Document.Replace(index, length, str);
+            this.Document.Replace(index, length, str, true);
         }
 
         /// <summary>
@@ -736,14 +733,24 @@ namespace FooEditEngine
         /// JumpCaretで移動した位置からキャレットを移動し、選択状態にする
         /// </summary>
         /// <param name="tp"></param>
-        public void MoveCaretAndSelect(TextPoint tp)
+        /// <param name="alignWord">単語単位で選択するかどうか</param>
+        public void MoveCaretAndSelect(TextPoint tp,bool alignWord = false)
         {
-            keepAnchor = true;
+            TextPoint endSelectPostion = tp;
             int CaretPostion = this.View.GetIndexFromLayoutLine(tp);
+            if (alignWord)
+            {
+                if (this.IsReverseSelect())
+                    while (CaretPostion >= 0 && CaretPostion < this.Document.Length && !Util.IsWordSeparator(this.Document[CaretPostion])) CaretPostion--;
+                else
+                    while (CaretPostion < this.Document.Length && !Util.IsWordSeparator(this.Document[CaretPostion])) CaretPostion++;
+                if (CaretPostion < 0)
+                    CaretPostion = 0;
+                endSelectPostion = this.View.LayoutLines.GetTextPointFromIndex(CaretPostion);
+            }
             this.Document.Select(this.Document.AnchorIndex, CaretPostion - this.Document.AnchorIndex);
-            this.View.JumpCaret(tp.row, tp.col);
+            this.View.JumpCaret(endSelectPostion.row, endSelectPostion.col);
             this.View.AdjustCaretAndSrc();
-            keepAnchor = false;
         }
 
         /// <summary>
@@ -873,7 +880,7 @@ namespace FooEditEngine
                 return;
             int selectionStart = this.SelectionStart;
             string insertStr = this.IndentMode == IndentMode.Space ? this.GetIndentSpace(0) : "\t";
-            string text = this.RemoveLineHead(GetTextFromLineSelectArea(this.View.Selections), insertStr);
+            string text = this.RemoveLineHead(GetTextFromLineSelectArea(this.View.Selections), insertStr, insertStr.Length);
             this.RepleaceSelectionArea(this.View.Selections, text);
             this.Document.Select(selectionStart, text.Length);
         }
@@ -892,14 +899,14 @@ namespace FooEditEngine
             return output.ToString();
         }
 
-        public string RemoveLineHead(string s, string str)
+        public string RemoveLineHead(string s, string str,int remove_count)
         {
             string[] lines = s.Split(new string[] { Document.NewLine.ToString() }, StringSplitOptions.None);
             StringBuilder output = new StringBuilder();
             for (int i = 0; i < lines.Length; i++)
             {
                 if (lines[i].StartsWith(str))
-                    output.Append(lines[i].Substring(1) + Document.NewLine);
+                    output.Append(lines[i].Substring(remove_count) + Document.NewLine);
                 else if (i < lines.Length - 1)
                     output.Append(lines[i] + Document.NewLine);
             }