2

我正在为 codemirror 创建一个新的简单模式。

我希望当用户按下“制表符”时,整行都会缩进(而不是光标之后的行的一部分,将行“拆分”成两部分)。

最简单的方法是什么?

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

4

3 回答 3

10

只需将选项卡的键盘映射更改为 indentMore:

extraKeys: {
    "Tab": "indentMore"
}

此解决方案也不会破坏选择缩进。

小提琴

于 2015-01-17T23:49:11.540 回答
2

这应该有效。 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 });
        }
     }
于 2014-10-25T23:50:12.150 回答
1

关于手册:

extraKeys: {
  'Tab': 'indentAuto'
}
于 2014-10-20T14:32:24.937 回答