codemirror焦点_CodeMirror:将焦点设置在行尾

codemirror焦点

CodeMirror is a WYSIWYG-like editor that allows for rich text editing on a small scale, oftentimes used to allow Markdown editing, much like ReviewBoard uses it for.  One problem I've found, however, is that calling a CodeMirror instance's focus method put the cursor at the beginning of the input, which is annoying when there is input in the field.  In theory you'd always want to put the cursor at the end so that the user can continue adding to the text that's already there.

CodeMirror是一种类似于WYSIWYG的编辑器,它可以进行小规模的富文本编辑,通常用于允许Markdown编辑,就像ReviewBoard所使用的那样。 但是,我发现的一个问题是,调用CodeMirror实例的focus方法会将光标放在输入的开头,当字段中有输入时,这很烦人。 理论上,您总是希望将光标放在末尾,以便用户可以继续添加到已经存在的文本中。

Here's a snippet that will set the cursor to the end of existing input:

这是一个将光标设置到现有输入末尾的代码段:

cmInstance.focus();
// Set the cursor at the end of existing content
cmInstance.setCursor(cmInstance.lineCount(), 0);


You would think that there would be a method which would accomplish this task, or even have focus set the cursor to the end of input by default if the instance has existing text.  Anyways, this is the code that will put the cursor at the end of your CodeMirror input instance!

您会认为,如果实例具有现有文本,则默认情况下将存在一种可以完成此任务的方法,甚至可以focus设置为默认情况下将光标设置在输入的末尾。 无论如何,这是将光标置于CodeMirror输入实例末尾的代码!

翻译自: https://davidwalsh.name/codemirror-set-focus-line

codemirror焦点

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值