首页 > 网站 > WEB开发 > 正文

(三)CodeMirror

2024-04-27 14:16:26
字体:
来源:转载
供稿:网友

(三)CodeMirror - Event

"change"(instance: CodeMirror, changeObj: object)

{    from,         // object    to,           // object    text,         // array     removed,      // string,被删除的字符    origin}           

"beforeChange"(instance: CodeMirror, changeObj: object)

1 // 如编辑行存在init字符,则取消编辑2 editors.on("beforeChange", function(cm, co) {3     if(cm.doc.children[0].lines[co.from.line].text.indexOf('init')>-1){4         co.cancel();5     }6 });

"keyHandled"(instance: CodeMirror, name: string, event: Event)

当按下扩展快捷键触发

{    cm,    name,      // 扩展键名    event      // keyPRess或keydown事件对象}

1 editors.on('keyHandled', function(cm,name,e){2     console.log(name);3 });

"renderLine"(instance: CodeMirror, line: LineHandle, element: Element)

1 // 代码显示2 editors.on("renderLine", function(cm, line, elt) {3     var off = CodeMirror.countColumn(line.text, null, cm.getOption("tabSize")) * charWidth;4      elt.style.textIndent = "-" + off + "px";5      elt.style.paddingLeft = (basePadding + off) + "px";6 });


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表