Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat: merge with default settings if necessary

Elijah Potterb48de624a8c2
diff --git a/src/harper/useLintBoxes.ts b/src/harper/useLintBoxes.ts
index a9000d0bc..165049925 100644
--- a/src/harper/useLintBoxes.ts
+++ b/src/harper/useLintBoxes.ts
@@ -25,15 +25,12 @@ export default function useLintBoxes(
const updateLints = useCallback(async () => {
await linter.clearIgnoredLints();
-
- const tasks = [linter.setLintConfig(config)];
+ await linter.setLintConfig(config);
if (ignoreState) {
- tasks.push(linter.importIgnoredLints(ignoreState));
+ await linter.importIgnoredLints(ignoreState);
}
- await Promise.all(tasks);
-
// We assume that a given index always refers to the same rich text field.
const newLints = await Promise.all(
richTexts.map(async (richText) => {
diff --git a/src/harper/useLintConfig.ts b/src/harper/useLintConfig.ts
index adb43deba..df3d16a55 100644
--- a/src/harper/useLintConfig.ts
+++ b/src/harper/useLintConfig.ts
@@ -1,3 +1,4 @@
+import { merge } from 'lodash-es';
import { useDispatch, useSelect } from '@wordpress/data';
import { LintConfig } from 'harper.js';
import { useLinter } from './LinterProvider';
@@ -22,14 +23,19 @@ export default function useLintConfig(): [
}, []);
useEffect(() => {
- if (lintConfig == null) {
- setConfig(defaultConfig);
+ if (
+ lintConfig == null ||
+ Object.entries(lintConfig).length <
+ Object.entries(defaultConfig).length
+ ) {
+ merge(lintConfig, defaultConfig);
+ setConfig({ ...lintConfig });
}
}, [defaultConfig, setConfig]);
const nonNull = useMemo(() => {
if (lintConfig == null) {
- return {};
+ return defaultConfig;
}
return lintConfig;
}, [lintConfig]);