Ejemplo n.º 1
0
        private void Box_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (lua_editor.Text != "")
            {
                tool.Text.Clear();
                List <string> newFuncs = new List <string>();
                foreach (var line in lua_editor.Lines)
                {
                    string pattern = @"function \w+-?\([(\w+-?)*(\W+-?)*]+-?\)";
                    foreach (Match m in Regex.Matches(line, pattern))
                    {
                        if (m.Success)//(line.Contains("function "))
                        {
                            string[] arr     = line.Split(new[] { "function ", }, StringSplitOptions.RemoveEmptyEntries);
                            string[] sorting = arr[0].Split('(');
                            if (tool.Text.Exists(x => x.Contains(sorting[0])))
                            {//tool.Text.RemoveAt(tool.Text.FindIndex(x => x.Contains(sorting[0])));
                                tool.Text.Add(arr[0]);
                            }
                            else
                            {
                                tool.Text.Add(arr[0]);
                            }
                        }
                    }
                }
                tool.AddNewItem(this);
            }

            if (!this.Text.EndsWith("*"))
            {
                this.Text = $"{this.Text}*";
            }

            //Init the style
            e.ChangedRange.ClearStyle(CommentStyle);
            e.ChangedRange.ClearStyle(KeywordStyle);
            e.ChangedRange.ClearStyle(ArgStyle);
            e.ChangedRange.ClearStyle(StringStyle);
            //Set the style
            e.ChangedRange.SetStyle(CommentStyle, @"--.*$", RegexOptions.Multiline);
            e.ChangedRange.SetStyle(KeywordStyle, @"\b(and|end|in|repeat|break|false|local|return|do|for|nil|then|else|function|not|true|elseif|if|or|untile|while)\b");
            e.ChangedRange.SetStyle(ArgStyle, @"\((.*?)[^\""]\)", RegexOptions.Multiline);
            e.ChangedRange.SetStyle(StringStyle, @"\""(.*?)\""");

            //Init folding marker
            e.ChangedRange.ClearFoldingMarkers();
            //Set the folding marker
            e.ChangedRange.SetFoldingMarkers(@"--region\b", @"--endregion\b");
        }