admin管理员组文章数量:1305095
I am creating a new simple mode for codemirror.
I would like that when the user presses "tab", the whole line gets indented (as opposed to only the part of the line that is after the cursor, "splitting" the line in two).
What would be the simplest way to do this ?
note : the corresponding code does not have to be defined in the mode. Any other approach (e.g. add on or configuration) would work as well.
I am creating a new simple mode for codemirror.
I would like that when the user presses "tab", the whole line gets indented (as opposed to only the part of the line that is after the cursor, "splitting" the line in two).
What would be the simplest way to do this ?
note : the corresponding code does not have to be defined in the mode. Any other approach (e.g. add on or configuration) would work as well.
Share Improve this question asked Oct 20, 2014 at 9:16 VinceVince 4,43912 gold badges48 silver badges83 bronze badges3 Answers
Reset to default 10Simply change tab's keymap to indentMore:
extraKeys: {
"Tab": "indentMore"
}
This solution also doesn't break selection indenting.
Fiddle
This should work. jsfiddle
extraKeys: {
"Tab": function(cm){
// get cursor position
var pos = cm.getCursor();
// set cursor position to the begining of the line.
cm.setCursor({ line: pos.line, ch: 0 });
// insert a tab
cm.replaceSelection("\t", "end");
// set cursor position to original.
cm.setCursor({ line: pos.line, ch: pos.ch + 1 });
}
}
Regarding the manual:
extraKeys: {
'Tab': 'indentAuto'
}
- Extra keys: http://codemirror/doc/manual.html#option_extraKeys
indentAuto
mand: http://codemirror/doc/manual.html#mand_indentAuto
本文标签: javascriptcodemirrorhow to indent the whole line when pressing tabStack Overflow
版权声明:本文标题:javascript - codemirror : how to indent the whole line when pressing tab? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741798312a2398070.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论