Przeglądaj źródła

Исправление бага - не изменялись хоткеи в настройках

Book Pauk 4 lat temu
rodzic
commit
355410c03c
2 zmienionych plików z 49 dodań i 19 usunięć
  1. 44 17
      client/share/utils.js
  2. 5 2
      client/store/modules/reader.js

+ 44 - 17
client/share/utils.js

@@ -103,30 +103,57 @@ export function fromBase64(data) {
     ));
 }
 
-export function getObjDiff(oldObj, newObj) {
-    const result = {__isDiff: true, change: {}, add: {}, del: []};
-
-    for (const key of Object.keys(oldObj)) {
-        if (newObj.hasOwnProperty(key)) {
-            if (!_.isEqual(oldObj[key], newObj[key])) {
-                if (_.isObject(oldObj[key]) && _.isObject(newObj[key])) {
-                    result.change[key] = getObjDiff(oldObj[key], newObj[key]);
-                } else {
-                    result.change[key] = _.cloneDeep(newObj[key]);
+export function getObjDiff(oldObj, newObj, opts = {}) {
+    const {
+        exclude = [],
+        excludeAdd = [],
+        excludeDel = [],
+    } = opts;
+
+    const ex = new Set(exclude);
+    const exAdd = new Set(excludeAdd);
+    const exDel = new Set(excludeDel);
+
+    const makeObjDiff = (oldObj, newObj, keyPath) => {
+        const result = {__isDiff: true, change: {}, add: {}, del: []};
+
+        keyPath = `${keyPath}${keyPath ? '/' : ''}`;
+
+        for (const key of Object.keys(oldObj)) {
+            const kp = `${keyPath}${key}`;
+
+            if (newObj.hasOwnProperty(key)) {
+                if (ex.has(kp))
+                    continue;
+
+                if (!_.isEqual(oldObj[key], newObj[key])) {
+                    if (_.isObject(oldObj[key]) && _.isObject(newObj[key])) {
+                        result.change[key] = makeObjDiff(oldObj[key], newObj[key], kp);
+                    } else {
+                        result.change[key] = _.cloneDeep(newObj[key]);
+                    }
                 }
+            } else {
+                if (exDel.has(kp))
+                    continue;
+                result.del.push(key);
             }
-        } else {
-            result.del.push(key);
         }
-    }
 
-    for (const key of Object.keys(newObj)) {
-        if (!oldObj.hasOwnProperty(key)) {
-            result.add[key] = _.cloneDeep(newObj[key]);
+        for (const key of Object.keys(newObj)) {
+            const kp = `${keyPath}${key}`;
+            if (exAdd.has(kp))
+                continue;
+
+            if (!oldObj.hasOwnProperty(key)) {
+                result.add[key] = _.cloneDeep(newObj[key]);
+            }
         }
+
+        return result;
     }
 
-    return result;
+    return makeObjDiff(oldObj, newObj, '');
 }
 
 export function isObjDiff(diff) {

+ 5 - 2
client/store/modules/reader.js

@@ -268,9 +268,12 @@ for (const button of toolButtons)
 for (const hotKey of hotKeys)
     settingDefaults.userHotKeys[hotKey.name] = hotKey.codes;
 
+const excludeDiffHotKeys = [];
+for (const hotKey of hotKeys)
+    excludeDiffHotKeys.push(`userHotKeys/${hotKey.name}`);
+
 function addDefaultsToSettings(settings) {
-    const diff = utils.getObjDiff(settings, settingDefaults);
-    
+    const diff = utils.getObjDiff(settings, settingDefaults, {exclude: excludeDiffHotKeys});
     if (!utils.isEmptyObjDiffDeep(diff, {isApplyChange: false})) {
         return utils.applyObjDiff(settings, diff, {isApplyChange: false});
     }