在Codemirror中检测换行 [英] Detecting new line in codemirror

查看:1674
本文介绍了在Codemirror中检测换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以在Codemirror编辑器中检测到换行符,无论是用户按下Enter还是代码换行?



ps:在所附的屏幕快照中3个新用户单击回车键(228、229、230)创建了一行行,并且由于换行而创建了一行(229和300之间)。



此处的屏幕截图: http://s9.postimage.org/gsroinedp/Scr​​een_Shot_2012_11_19_at_11_30_09_PM.png

解决方案

在api中内置了回车键。

  var editor = CodeMirror.fromTextArea(document.getElementById( code),{
lineNumbers:true,
lineWrapping:'true',
extraKeys:{
输入:function(){
alert('entent按下');
}
}
});

我目前不知道任何允许您捕获包裹事件的api。 / p>

您可以得到CodeMirror-scrollbar-inner的高度,如果它的大小增加了,并且这不是onpaste事件,那么您知道换行或按回车键是:)


Is there any way to detect a newline in codemirror editor, either when user hits enter or a line of code wraps?

p.s: in the screenshot attached 3 new lines are created by user hitting enter key (228, 229, 230), and one line (between 229 and 300) is created because of line wrapping.

screenshot here: http://s9.postimage.org/gsroinedp/Screen_Shot_2012_11_19_at_11_30_09_PM.png

解决方案

Catching the enter key is built into the api.

  var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    lineWrapping:'true',
      extraKeys:{
        Enter: function(){
            alert('enter pressed');
        }
    }
  });

I'm not currently aware of any api that allows you to capture a 'wrap' event.

You could get the CodeMirror-scrollbar-inner height, and if it size increases, and it's not an onpaste event you know the line wrapped or enter was pressed :)

这篇关于在Codemirror中检测换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆