让Fireball CodeEditor控件支持中文

Fireball.CodeEditor是个很强大的编辑器。实话说,就一个编辑器,附加那么多DLL,有些不合算,呵呵。

语法文件内置,编译的时候已经提供了大量的语法文件,是全部编辑器里面内置最多的一个编辑器。可以使用DLL文件对语法进行扩充。提供设置界面对语法高亮进行设置,只是界面不咋滴,呵呵,过于简单了一些。提供传说中的无限级别的redo功能,这个功能的确是编辑器不可或缺的。提供find和 replace功能。中文支持不是差劲的问题,是非常非常差劲。一旦输入中文就会出现光标位置不对,@_@.

代码折叠存在问题,没有办法折叠注释块。正常的代码折叠,我测试了一下C#和Java没有问题,但是XML折叠存在问题,只能折叠CDATA,有点不可思议。

折叠的方式比较漂亮,和VS的风格一致

1

有意思的是,这个编辑器组件对在注释中的东东也进行了语法高亮、括号匹配,不知道是错误还是就是如此,哈哈。

2

致命伤:输入中文的时候出现错误,例如你输入"测试",在编辑器里面会出现"测试测试",任何中文字符都是如此,如果使用Copy则不会出现这样的问题。在输入中文的时候redo也存在问题,原本输入两个汉字变成4个汉字,但是redo的时候却需要redo 4次。打开中文文件时大多会出现乱码。:)。

//解决重复输入问题:
//CodeEditor\Editors\EditView\EditViewControl.cs
protected override void OnKeyPress(KeyPressEventArgs e)
{
    base.OnKeyPress(e);
    if (!e.Handled && !_KeyDownHandled && e.KeyChar != (char)127)
    {
        if (((int)e.KeyChar) < 32)
            return;
        if (!this.ReadOnly)
        {
            switch ((Keys)(int)e.KeyChar)
            {
                default:
                    {
                        InsertText(e.KeyChar.ToString());

                        if (this.Indent == IndentStyle.Scope || this.Indent == IndentStyle.Smart)
                        {
                            if (Caret.CurrentRow.ShouldOutdent)
                            {
                                OutdentEndRow();
                            }
                        }
                        //增加本行,如果不增加则输入中文的时候会重复输入一次,寒 
                        e.Handled = true;
                        break;
                    }
            }
        }
    }
    if (AutoListVisible && !e.Handled && _CodeEditor.AutoListAutoSelect)
    {
        string s = Caret.CurrentRow.Text;
        //try 
        //{ 
        if (Caret.Position.X - AutoListStartPos.X >= 0)
        {
            s = s.Substring(AutoListStartPos.X, Caret.Position.X - AutoListStartPos.X);
            AutoList.SelectItem(s);
        }
        //} 
        //catch 
        //{ 
        //} 
    }
}
/************************************************************/
//解决打开文件出现乱码的问题: 
//CodeEditor\Editors\CodeEditorControl.cs
public void Open(string filename)
{
    if (this.Document == null)
        throw new NullReferenceException("CodeEditorControl.Document");
    //添加System.Text.Encoding.Default,否则中文显示为乱码
    StreamReader swr = new StreamReader(filename, System.Text.Encoding.Default);
    this.Document.Text = swr.ReadToEnd();
    swr.Close();
    SetFileName(filename);
    this.Saved = true;
}

posted on 2009-05-29 01:59  Lionheart Zhang  阅读(1093)  评论(5编辑  收藏  举报

导航