(
view: EditorView,
overrides: FormattingOptions = {},
)
| 1247 | } |
| 1248 | |
| 1249 | function buildFormattingOptions( |
| 1250 | view: EditorView, |
| 1251 | overrides: FormattingOptions = {}, |
| 1252 | ): FormattingOptions { |
| 1253 | const state = view?.state; |
| 1254 | if (!state) return { ...overrides }; |
| 1255 | |
| 1256 | const unitValue = state.facet(indentUnit); |
| 1257 | const unit = |
| 1258 | typeof unitValue === "string" && unitValue.length |
| 1259 | ? unitValue |
| 1260 | : String(unitValue ?? "\t"); |
| 1261 | let tabSize = getIndentUnit(state); |
| 1262 | if ( |
| 1263 | typeof tabSize !== "number" || |
| 1264 | !Number.isFinite(tabSize) || |
| 1265 | tabSize <= 0 |
| 1266 | ) { |
| 1267 | tabSize = resolveIndentWidth(unit); |
| 1268 | } |
| 1269 | const insertSpaces = !unit.includes("\t"); |
| 1270 | |
| 1271 | return { |
| 1272 | tabSize, |
| 1273 | insertSpaces, |
| 1274 | ...overrides, |
| 1275 | }; |
| 1276 | } |
| 1277 | |
| 1278 | function resolveIndentWidth(unit: string): number { |
| 1279 | if (typeof unit !== "string" || !unit.length) return 4; |
no test coverage detected