Skip to content

Commit cb2efd0

Browse files
committed
feat(basic-setup): add tabSize options (#400).
1 parent b2341d3 commit cb2efd0

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

extensions/basic-setup/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ export interface BasicSetupOptions extends MinimalSetupOptions {
107107
foldKeymap?: boolean;
108108
completionKeymap?: boolean;
109109
lintKeymap?: boolean;
110+
/**
111+
* Facet for overriding the unit by which indentation happens. Should be a string consisting either entirely of spaces or entirely of tabs. When not set, this defaults to 2 spaces
112+
* https://codemirror.net/docs/ref/#language.indentUnit
113+
* @default 2
114+
*/
115+
tabSize?: number;
110116
}
111117
/**
112118
This is an extension value that just pulls together a number of

extensions/basic-setup/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
syntaxHighlighting,
2121
defaultHighlightStyle,
2222
bracketMatching,
23+
indentUnit,
2324
foldKeymap,
2425
} from '@codemirror/language';
2526

@@ -45,6 +46,12 @@ export interface BasicSetupOptions extends MinimalSetupOptions {
4546
foldKeymap?: boolean;
4647
completionKeymap?: boolean;
4748
lintKeymap?: boolean;
49+
/**
50+
* Facet for overriding the unit by which indentation happens. Should be a string consisting either entirely of spaces or entirely of tabs. When not set, this defaults to 2 spaces
51+
* https://codemirror.net/docs/ref/#language.indentUnit
52+
* @default 2
53+
*/
54+
tabSize?: number;
4855
}
4956

5057
/**
@@ -126,6 +133,8 @@ export const basicSetup = (options: BasicSetupOptions = {}): Extension[] => {
126133
if (options.crosshairCursor !== false) extensions.push(crosshairCursor());
127134
if (options.highlightActiveLine !== false) extensions.push(highlightActiveLine());
128135
if (options.highlightSelectionMatches !== false) extensions.push(highlightSelectionMatches());
136+
if (options.tabSize && typeof options.tabSize === 'number')
137+
extensions.push(indentUnit.of(' '.repeat(options.tabSize)));
129138

130139
return extensions.concat([keymap.of(keymaps.flat())]).filter(Boolean);
131140
};

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
"engines": {
2424
"node": ">=16.0.0"
2525
},
26-
"lint-staged": {
27-
"*.{js,jsx,ts,tsx,less,json}": [
28-
"prettier --write"
29-
]
30-
},
3126
"devDependencies": {
3227
"@kkt/ncc": "^1.0.13",
3328
"@kkt/less-modules": "^7.2.0",

www/src/pages/extensions/basic-setup/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const BasicSetupDoc = () => {
3737
}, []);
3838

3939
const [basicSetup, setBasicSetup] = useState<BasicSetupOptions>({});
40+
console.log('basicSetup', basicSetup);
4041
return (
4142
<PageWarpper>
4243
<CodeMirror
@@ -48,6 +49,15 @@ export const BasicSetupDoc = () => {
4849
extensions={[langs.markdown()]}
4950
/>
5051
<Warpper>
52+
<select
53+
value={basicSetup.tabSize}
54+
onChange={(evn) => setBasicSetup({ ...basicSetup, tabSize: Number(evn.target.value || '2') })}
55+
>
56+
<option value={2}>2</option>
57+
<option value={4}>4</option>
58+
<option value={6}>6</option>
59+
<option value={8}>8</option>
60+
</select>
5161
<Options
5262
checked={basicSetup.lineNumbers !== false}
5363
onChange={(evn) => setBasicSetup({ ...basicSetup, lineNumbers: evn.target.checked })}

0 commit comments

Comments
 (0)