首页 > 代码库 > ICSharpCode.TextEditor

ICSharpCode.TextEditor

前段时间想写richtextbox的代码折行,但是网上没有搜到,只看到了一个FastColoredTextBox还不支持中文,
这几天突然搜索文本编辑器看到一个编译器,SharpDevelop 5.1,然后看到里面有一个组件TextEditor,
试了试支持中文也能代码折行,所以有时候做不出来可以先放一放,指不定什么时候看到什么就做出来了。

/// <summary>        /// @@ 折行        /// </summary>        /// <param name="document"></param>        /// <param name="fileName"></param>        /// <param name="parseInformation"></param>        /// <returns></returns>        public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)        {            List<FoldMarker> list = new List<FoldMarker>();            var startLines = new Stack<int>();            for (int i = 0; i < document.TotalNumberOfLines; i++)            {                // Get the text of current line.                string text = document.GetText(document.GetLineSegment(i));                if (text.Trim().Length >= 2 && text.Trim().Substring(0, 2) == "@@") // Look for method starts                {                    if (flag == false)                    {                        if (startLines.Count > 0)                        {                            int start = startLines.Pop();                            // 判断相邻两行是否都有标签                            if (start == i - 1)                            {                                startLines.Push(start);                            }                            else                            {                                if (count < 30)                                {                                    list.Add(new FoldMarker(document, start, document.GetLineSegment(start).Length, i - 1, 57, FoldType.TypeBody, "...}", true));                                }                                else                                {                                    list.Add(new FoldMarker(document, start, document.GetLineSegment(start).Length, i - 1, 57, FoldType.TypeBody, "...}", false));                                }                                count++;                            }                        }                        startLines.Push(i);                    }                    else                    {                        flag = false;                        startLines.Push(i);                    }                }            }            return list;        }        private int count = 0;        //是否是第一个标签        private bool flag = true;        /// <summary>        /// 保存        /// </summary>        /// <param name="msg"></param>        /// <param name="keyData"></param>        /// <returns></returns>        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, Keys keyData)        {            if (keyData =http://www.mamicode.com/= (Keys.Control | Keys.S))            {                textEditor.SaveFile(filename);                //return base.ProcessCmdKey(ref msg, keyData);            }            else if (keyData =http://www.mamicode.com/= Keys.F5)            {                textEditor.LoadFile(filename);            }            return base.ProcessCmdKey(ref msg, keyData);        }

 

ICSharpCode.TextEditor