[英]codemirror : how to indent the whole line when pressing tab?
我正在為codemirror創建一個新的簡單模式。
我希望當用戶按下“tab”時,整行會縮進(而不是僅僅是光標之后的行部分,“將行分成兩行”)。
最簡單的方法是什么?
注意:不必在模式中定義相應的代碼。 任何其他方法(例如添加或配置)也可以。
這應該工作。 的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 });
}
}
關於手冊:
extraKeys: {
'Tab': 'indentAuto'
}
indentAuto
命令: http : indentAuto
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.