OSDN Git Service

CompleteItemでドキュメントから補完候補を作成できるようにした
authorkonekoneko <test2214@hotmail.co.jp>
Tue, 15 Nov 2016 15:58:32 +0000 (21:28 +0530)
committerkonekoneko <test2214@hotmail.co.jp>
Tue, 15 Nov 2016 15:58:32 +0000 (21:28 +0530)
Core/AutoCompleteBoxBase.cs
Core/Document.cs
UWP/Test/MainViewModel.cs

index 22e64c7..c62460b 100644 (file)
@@ -76,6 +76,34 @@ namespace FooEditEngine
     }
 
     /// <summary>
+    /// イベントパラメーターイベントパラメーター
+    /// </summary>
+    public sealed class CollectCompleteItemEventArgs : EventArgs
+    {
+        /// <summary>
+        /// 入力された行
+        /// </summary>
+        public int InputedRow;
+        /// <summary>
+        /// 補完対象のテキストボックス
+        /// </summary>
+        public Document textbox;
+        /// <summary>
+        /// コンストラクター
+        /// </summary>
+        /// <param name="word"></param>
+        /// <param name="inputing_word"></param>
+        /// <param name="textbox"></param>
+        public CollectCompleteItemEventArgs(Document textbox)
+        {
+            this.textbox = textbox;
+            this.InputedRow = textbox.CaretPostion.row - 1;
+            if (this.InputedRow < 0)
+                this.InputedRow = 0;
+        }
+    }
+
+    /// <summary>
     /// イベントパンドラーの定義
     /// </summary>
     /// <param name="sender"></param>
@@ -147,6 +175,11 @@ namespace FooEditEngine
                     }
                 }
             };
+            this.CollectItems = (s, e) =>
+            {
+                AutoCompleteBoxBase box = (AutoCompleteBoxBase)s;
+                CompleteHelper.AddCompleteWords(box.Items, box.Operators, e.textbox.LayoutLines[e.InputedRow]);
+            };
             this.Operators = new char[] { ' ', '\t', Document.NewLine };
             this.Document = document;
         }
@@ -154,15 +187,19 @@ namespace FooEditEngine
         internal void ParseInput(string input_text)
         {
             if (this.Operators == null ||
-                input_text == "\r" ||
-                input_text == "\n" ||
                 this.ShowingCompleteBox == null ||
                 (this.IsCloseCompleteBox == false && input_text == "\b"))
                 return;
 
+            if (input_text == "\r" || input_text == "\n")
+            {
+                this.CollectItems(this, new CollectCompleteItemEventArgs(this.Document));
+                return;
+            }
+
             this.OpenCompleteBox(input_text);
         }
-
+        public EventHandler<CollectCompleteItemEventArgs> CollectItems;
         /// <summary>
         /// 補完すべき単語が選択されたときに発生するイベント
         /// </summary>
index 794909c..4ed7083 100644 (file)
@@ -1036,8 +1036,12 @@ namespace FooEditEngine
 
             if (this.FireUpdateEvent && UserInput)
             {
-                if(this.AutoComplete != null)
-                    this.AutoComplete.ParseInput(string.Empty); //入力は終わっているので空文字を渡す
+                var input_str = string.Empty;
+                if (s == Document.NewLine.ToString())
+                    input_str = s;
+                //入力は終わっているので空文字を渡すが処理の都合で一部文字だけはそのまま渡す
+                if (this.AutoComplete != null)
+                    this.AutoComplete.ParseInput(input_str);
                 if (s == Document.NewLine.ToString())
                     this.AutoIndentHook(this, null);
             }
index 00c4a0e..4bb19f3 100644 (file)
@@ -28,6 +28,7 @@ namespace Test
             var doc = new Document() { Title = "test1" };
             doc.AutoComplete = new AutoCompleteBox(doc);
             doc.AutoComplete.Items = complete_collection;
+            doc.AutoComplete.Enabled = true;
             this._list.Add(doc);
 
             doc = new Document() { Title = "test2" };