Hi guys,
How to change the indentation when entering a new line?
Sorry for the probability silly question.
Hi guys,
How to change the indentation when entering a new line?
Sorry for the probability silly question.
See the indentUnit
facet, and see this example for information on how to provide values to facets.
@marijn Just checked your given example. It is pretty useful. Thanks!
Awesome, thanks! I was able to make an Xcode-like settings:
const getIndentationExtensions = (indentation: IIndentation): Array<Extension> => {
const extensions: Array<Extension> = [];
const tabSizeCompartment = new Compartment();
let indentUnitString: string; // What will be added when user presses tab or indentation happens
extensions.push(
tabSizeCompartment.of(EditorState.tabSize.of(indentation.tabWidth)) // Tab width (how many spaces in a tab)
);
if (indentation.using === 'spaces') {
indentUnitString = ' '.repeat(indentation.indentWidth);
} else {
const numberOfTabs = Math.floor(indentation.indentWidth / indentation.tabWidth);
indentUnitString = '\t'.repeat(numberOfTabs);
}
extensions.push(indentUnit.of(indentUnitString));
return extensions;
};
const keymaps: Array<KeyBinding> = [];
if (indentation.tabKeyAction === 'indent') {
keymaps.push(indentWithTab); // Trigger indentation instead of typing tab
}