OSDN Git Service

領域外でダブルクリックした場合、行全体を選択できるようにした
authorgdkhd812 <test@yahoo.co.jp>
Sun, 9 Apr 2017 06:25:15 +0000 (15:25 +0900)
committergdkhd812 <test@yahoo.co.jp>
Sun, 9 Apr 2017 06:25:15 +0000 (15:25 +0900)
Core/Document.cs
UWP/FooEditEngine.UWP/FooTextBox.cs
WPF/FooEditEngine/FooTextBox.cs
Windows/FooEditEngine/FooTextBox.cs

index dc41812..14d325a 100644 (file)
@@ -873,23 +873,47 @@ namespace FooEditEngine
         /// <param name="changeAnchor">選択の起点となるとインデックスを変更するなら真。そうでなければ偽</param>
         public void SelectWord(int index, bool changeAnchor = false)
         {
+            this.SelectSepartor(index, (c) => Util.IsWordSeparator(c), changeAnchor);
+        }
+
+        /// <summary>
+        /// 行単位で選択する
+        /// </summary>
+        /// <param name="index">探索を開始するインデックス</param>
+        /// <param name="changeAnchor">選択の起点となるとインデックスを変更するなら真。そうでなければ偽</param>
+        public void SelectLine(int index,bool changeAnchor = false)
+        {
+            this.SelectSepartor(index, (c) => c == Document.NewLine, changeAnchor);
+        }
+
+        /// <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");
+
             if (this.Length <= 0 || index >= this.Length)
                 return;
 
             Document str = this;
 
             int start = index;
-            while (start > 0 && !Util.IsWordSeparator(str[start]))
+            while (start > 0 && !find_sep_func(str[start]))
                 start--;
 
-            if (Util.IsWordSeparator(str[start]))
+            if (find_sep_func(str[start]))
                 start++;
 
             int end = index;
-            while (end < this.Length && !Util.IsWordSeparator(str[end]))
+            while (end < this.Length && !find_sep_func(str[end]))
                 end++;
 
             this.Select(start, end - start);
index 13deed5..412456a 100644 (file)
@@ -1085,11 +1085,14 @@ namespace FooEditEngine.UWP
             this.Document.SelectGrippers.BottomLeft.Enabled = false;
             this.Document.SelectGrippers.BottomRight.Enabled = touched;
             this.JumpCaret(e.Position);
-            if (e.TapCount == 2)
+            if(e.TapCount == 2)
             {
+                //タッチスクリーンでトリプルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
                 this.Document.SelectGrippers.BottomLeft.Enabled = touched;
-                //タッチスクリーンでダブルタップした場合、アンカーインデックスを単語の先頭にしないとバグる
-                this.Document.SelectWord(this.Controller.SelectionStart, touched);
+                if (e.Position.X < this.Render.TextArea.X)
+                    this.Document.SelectLine(this.Controller.SelectionStart, touched);
+                else
+                    this.Document.SelectWord(this.Controller.SelectionStart, touched);
                 this.Refresh();
             }
         }
index f82b6e1..38a1039 100644 (file)
@@ -838,8 +838,11 @@ namespace FooEditEngine.WPF
 
             if (e.LeftButton == MouseButtonState.Pressed)
             {
+                if (p.X < this.Render.TextArea.X)
+                    this.Document.SelectLine((int)index);
+                else
+                    this.Document.SelectWord((int)index);
 
-                this.Document.SelectWord((int)index);
                 this.textStore.NotifySelectionChanged();
                 if(this.peer != null)
                     this.peer.OnNotifyCaretChanged();
index 2e4edb9..3797bd8 100644 (file)
@@ -1174,7 +1174,10 @@ namespace FooEditEngine.Windows
             if (mouseEvent.Handled)
                 return;
 
-            this.Document.SelectWord(index);
+            if (e.X < this.render.TextArea.X)
+                this.Document.SelectLine(index);
+            else
+                this.Document.SelectWord(index);
             
             this.Refresh();
         }