From 25f990fc2a889c4ce5ad5bf9a42e028c1c6a0d37 Mon Sep 17 00:00:00 2001 From: gdkhd812 Date: Sun, 9 Apr 2017 15:25:15 +0900 Subject: [PATCH] =?utf8?q?=E9=A0=98=E5=9F=9F=E5=A4=96=E3=81=A7=E3=83=80?= =?utf8?q?=E3=83=96=E3=83=AB=E3=82=AF=E3=83=AA=E3=83=83=E3=82=AF=E3=81=97?= =?utf8?q?=E3=81=9F=E5=A0=B4=E5=90=88=E3=80=81=E8=A1=8C=E5=85=A8=E4=BD=93?= =?utf8?q?=E3=82=92=E9=81=B8=E6=8A=9E=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?utf8?q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Core/Document.cs | 30 +++++++++++++++++++++++++++--- UWP/FooEditEngine.UWP/FooTextBox.cs | 9 ++++++--- WPF/FooEditEngine/FooTextBox.cs | 5 ++++- Windows/FooEditEngine/FooTextBox.cs | 5 ++++- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Core/Document.cs b/Core/Document.cs index dc41812..14d325a 100644 --- a/Core/Document.cs +++ b/Core/Document.cs @@ -873,23 +873,47 @@ namespace FooEditEngine /// 選択の起点となるとインデックスを変更するなら真。そうでなければ偽 public void SelectWord(int index, bool changeAnchor = false) { + this.SelectSepartor(index, (c) => Util.IsWordSeparator(c), changeAnchor); + } + + /// + /// 行単位で選択する + /// + /// 探索を開始するインデックス + /// 選択の起点となるとインデックスを変更するなら真。そうでなければ偽 + public void SelectLine(int index,bool changeAnchor = false) + { + this.SelectSepartor(index, (c) => c == Document.NewLine, changeAnchor); + } + + /// + /// セパレーターで囲まれた範囲内を選択する + /// + /// 探索を開始するインデックス + /// セパレーターなら真を返し、そうでないなら偽を返す + /// 選択の起点となるとインデックスを変更するなら真。そうでなければ偽 + public void SelectSepartor(int index,Func 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); diff --git a/UWP/FooEditEngine.UWP/FooTextBox.cs b/UWP/FooEditEngine.UWP/FooTextBox.cs index 13deed5..412456a 100644 --- a/UWP/FooEditEngine.UWP/FooTextBox.cs +++ b/UWP/FooEditEngine.UWP/FooTextBox.cs @@ -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(); } } diff --git a/WPF/FooEditEngine/FooTextBox.cs b/WPF/FooEditEngine/FooTextBox.cs index f82b6e1..38a1039 100644 --- a/WPF/FooEditEngine/FooTextBox.cs +++ b/WPF/FooEditEngine/FooTextBox.cs @@ -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(); diff --git a/Windows/FooEditEngine/FooTextBox.cs b/Windows/FooEditEngine/FooTextBox.cs index 2e4edb9..3797bd8 100644 --- a/Windows/FooEditEngine/FooTextBox.cs +++ b/Windows/FooEditEngine/FooTextBox.cs @@ -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(); } -- 2.11.0