Skip to content

Commit 516e532

Browse files
committed
When user types tab, translate it into spaces for consistent indentation.
Before this, CodeMirror was storing literal tabs. They align in the IDE because it has tab size set to 2, but are inconsistent when saved to disk or viewed in another editor. The issue is discussed and my solution comes from this CodeMirror thread: codemirror/codemirror5#988
1 parent 6cb08e6 commit 516e532

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/ide.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,15 @@ export class Editor {
657657
"Cmd-1": () => this.format({type: "heading", level: 1}),
658658
"Cmd-2": () => this.format({type: "heading", level: 2}),
659659
"Cmd-3": () => this.format({type: "heading", level: 3}),
660-
"Cmd-L": () => this.format({type: "item"})
660+
"Cmd-L": () => this.format({type: "item"}),
661+
"Tab": (cm) => {
662+
if (cm.somethingSelected()) {
663+
cm.indentSelection("add");
664+
} else {
665+
cm.replaceSelection(cm.getOption("indentWithTabs")? "\t":
666+
Array(cm.getOption("indentUnit") + 1).join(" "), "end", "+input");
667+
}
668+
}
661669
})
662670
};
663671

0 commit comments

Comments
 (0)