OSDN Git Service

ナレーターと単語単位の選択のロジックが似ていたのでまとめた
authortest <test@yahoo.co.jp>
Fri, 1 Jan 2021 05:36:39 +0000 (14:36 +0900)
committertest <test@yahoo.co.jp>
Fri, 1 Jan 2021 05:36:39 +0000 (14:36 +0900)
Core/Automaion/FooTextBoxAutomationPeer.cs
Core/Document.cs

index 99f23b6..5872981 100644 (file)
@@ -352,6 +352,8 @@ namespace FooEditEngine
 
         public void ExpandToEnclosingUnit(TextUnit unit)
         {
+            Controller ctrl = this.textbox.Controller;
+            Document doc = this.textbox.Document;
             if (unit == TextUnit.Character)
             {
                 if (this.start == this.end)
@@ -361,15 +363,19 @@ namespace FooEditEngine
                 }
                 return;
             }
-            if (unit == TextUnit.Format || unit == TextUnit.Word || unit == TextUnit.Line)
+            if (unit == TextUnit.Format || unit == TextUnit.Word || unit == TextUnit.Line || unit == TextUnit.Paragraph)
             {
-                LineToIndexTable layoutLineCollection = this.textbox.LayoutLineCollection;
-                int row = layoutLineCollection.GetLineNumberFromIndex(this.start);
-                this.start = layoutLineCollection.GetIndexFromLineNumber(row);
-                this.end = this.start + layoutLineCollection.GetLengthFromLineNumber(row);
+                var t = doc.GetSepartor(this.start, (c) => c == Document.NewLine);
+                if (t == null)
+                    this.start = this.end = 0;
+                else
+                {
+                    this.start = t.Item1;
+                    this.end = t.Item2;
+                }
                 return;
             }
-            if (unit == TextUnit.Paragraph || unit == TextUnit.Page || unit == TextUnit.Document)
+            if (unit == TextUnit.Page || unit == TextUnit.Document)
             {
                 this.start = 0;
                 this.end = this.textbox.Document.Length;
index 54a2693..9c5932f 100644 (file)
@@ -894,21 +894,18 @@ namespace FooEditEngine
         }
 
         /// <summary>
-        /// ã\82»ã\83\91ã\83¬ã\83¼ã\82¿ã\83¼ã\81§å\9b²ã\81¾ã\82\8cã\81\9fç¯\84å\9b²å\86\85ã\82\92é\81¸æ\8a\9eする
+        /// ã\82»ã\83\91ã\83¬ã\83¼ã\82¿ã\83¼ã\81§å\8cºå\88\87ã\82\89ã\82\8cã\81\9fé \98å\9f\9fã\82\92å\8f\96å¾\97する
         /// </summary>
         /// <param name="index">探索を開始するインデックス</param>
         /// <param name="find_sep_func">セパレーターなら真を返し、そうでないなら偽を返す</param>
-        /// <param name="changeAnchor">選択の起点となるとインデックスを変更するなら真。そうでなければ偽</param>
-        public void SelectSepartor(int index,Func<char,bool> find_sep_func, bool changeAnchor = false)
+        /// <returns>開始インデックス、終了インデックス</returns>
+        public Tuple<int,int> GetSepartor(int index, Func<char, bool> find_sep_func)
         {
-            if (this.FireUpdateEvent == false)
-                throw new InvalidOperationException("");
-
             if (find_sep_func == null)
                 throw new ArgumentNullException("find_sep_func must not be null");
 
             if (this.Length <= 0 || index >= this.Length)
-                return;
+                return null;
 
             Document str = this;
 
@@ -925,6 +922,29 @@ namespace FooEditEngine
             while (end < this.Length && !find_sep_func(str[end]))
                 end++;
 
+            return new Tuple<int, int>(start, end);
+        }
+
+        /// <summary>
+        /// セパレーターで囲まれた範囲内を選択する
+        /// </summary>
+        /// <param name="index">探索を開始するインデックス</param>
+        /// <param name="find_sep_func">セパレーターなら真を返し、そうでないなら偽を返す</param>
+        /// <param name="changeAnchor">選択の起点となるとインデックスを変更するなら真。そうでなければ偽</param>
+        public void SelectSepartor(int index,Func<char,bool> find_sep_func, bool changeAnchor = false)
+        {
+            if (this.FireUpdateEvent == false)
+                throw new InvalidOperationException("");
+
+            if (find_sep_func == null)
+                throw new ArgumentNullException("find_sep_func must not be null");
+
+            var t = this.GetSepartor(index, find_sep_func);
+            if (t == null)
+                return;
+
+            int start = t.Item1, end = t.Item2;
+
             this.Select(start, end - start);
 
             if (changeAnchor)