1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/packages/editor/CodeMirror/utils/formatting/tabsToSpaces.ts

20 lines
476 B
TypeScript
Raw Normal View History

import { EditorState } from '@codemirror/state';
import { getIndentUnit } from '@codemirror/language';
const tabsToSpaces = (state: EditorState, text: string): string => {
const chunks = text.split('\t');
const spaceLen = getIndentUnit(state);
let result = chunks[0];
for (let i = 1; i < chunks.length; i++) {
for (let j = result.length % spaceLen; j < spaceLen; j++) {
result += ' ';
}
result += chunks[i];
}
return result;
};
export default tabsToSpaces;