mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
20 lines
476 B
TypeScript
20 lines
476 B
TypeScript
|
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;
|