簡體   English   中英

codemirror:按Tab鍵時如何縮進整行?

[英]codemirror : how to indent the whole line when pressing tab?

我正在為codemirror創建一個新的簡單模式。

我希望當用戶按下“tab”時,整行會縮進(而不是僅僅是光標之后的行部分,“將行分成兩行”)。

最簡單的方法是什么?

注意:不必在模式中定義相應的代碼。 任何其他方法(例如添加或配置)也可以。

只需將tab的鍵盤映射更改為indentMore:

extraKeys: {
    "Tab": "indentMore"
}

此解決方案也不會破壞選擇縮進。

小提琴

這應該工作。 的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'
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM