[DE] Fix autocorrection list

This commit is contained in:
Julia Radzhabova 2020-07-24 12:25:17 +03:00
parent acecca032a
commit 99fc8388b2
2 changed files with 28 additions and 22 deletions

View file

@ -108,7 +108,7 @@ define([
var path = this.appPrefix + "settings-math-correct"; var path = this.appPrefix + "settings-math-correct";
var value = Common.Utils.InternalSettings.get(path + "-add"); var value = Common.Utils.InternalSettings.get(path + "-add");
this.arrAdd = value ? JSON.parse(value) : {}; this.arrAdd = value ? JSON.parse(value) : [];
value = Common.Utils.InternalSettings.get(path + "-rem"); value = Common.Utils.InternalSettings.get(path + "-rem");
this.arrRem = value ? JSON.parse(value) : []; this.arrRem = value ? JSON.parse(value) : [];
@ -279,14 +279,18 @@ define([
var rec = this.mathList.getSelectedRec(), var rec = this.mathList.getSelectedRec(),
by = ''; by = '';
if (rec) { if (rec) {
if (!this.inputBy.getValue() && rec.get('defaultValue') && (rec.get('defaultValueStr')!==rec.get('by'))) { var idx = _.findIndex(this.arrAdd, function(item){return (item[0]==rec.get('replaced'));});
if (!this.inputBy.getValue() && rec.get('defaultValue') && (rec.get('defaultValueStr')!==rec.get('by'))) {// reset to default
by = rec.get('defaultValue'); by = rec.get('defaultValue');
rec.set('by', rec.get('defaultValueStr')); rec.set('by', rec.get('defaultValueStr'));
delete this.arrAdd[rec.get('replaced')]; (idx>=0) && this.arrAdd.splice(idx, 1);
} else { } else { // replace
by = this.inputBy.getValue(); by = this.inputBy.getValue();
rec.set('by', by); rec.set('by', by);
this.arrAdd[rec.get('replaced')] = by; if (idx<0)
this.arrAdd.push([rec.get('replaced'), by]);
else
this.arrAdd[idx][1] = by;
} }
} else { } else {
rec = this.mathStore.add({ rec = this.mathStore.add({
@ -297,7 +301,7 @@ define([
this.mathList.selectRecord(rec); this.mathList.selectRecord(rec);
this.mathList.scrollToRecord(rec); this.mathList.scrollToRecord(rec);
by = rec.get('by'); by = rec.get('by');
this.arrAdd[rec.get('replaced')] = by; this.arrAdd.push([rec.get('replaced'), by]);
} }
var path = this.appPrefix + "settings-math-correct-add"; var path = this.appPrefix + "settings-math-correct-add";
var val = JSON.stringify(this.arrAdd); var val = JSON.stringify(this.arrAdd);
@ -322,7 +326,7 @@ define([
Common.localStorage.setItem(path + "-add", val); Common.localStorage.setItem(path + "-add", val);
Common.Utils.InternalSettings.set(path + "-rem", val); Common.Utils.InternalSettings.set(path + "-rem", val);
Common.localStorage.setItem(path + "-rem", val); Common.localStorage.setItem(path + "-rem", val);
this.arrAdd = {}; this.arrAdd = [];
this.arrRem = []; this.arrRem = [];
} }
var arrAdd = this.arrAdd, var arrAdd = this.arrAdd,
@ -336,31 +340,33 @@ define([
defaultValue: item[1], defaultValue: item[1],
defaultDisabled: arrRem.indexOf(item[0])>-1 defaultDisabled: arrRem.indexOf(item[0])>-1
}; };
var by = arrAdd[item[0]];
if (typeof item[1]=='object') { if (typeof item[1]=='object') {
itm.defaultValueStr = ''; itm.defaultValueStr = '';
_.each(item[1], function(ch){ _.each(item[1], function(ch){
itm.defaultValueStr += Common.Utils.String.encodeSurrogateChar(ch); itm.defaultValueStr += Common.Utils.String.encodeSurrogateChar(ch);
}); });
itm.by = by ? by : itm.defaultValueStr; itm.by = itm.defaultValueStr;
} else { } else {
itm.defaultValueStr = Common.Utils.String.encodeSurrogateChar(item[1]); itm.by = itm.defaultValueStr = Common.Utils.String.encodeSurrogateChar(item[1]);
itm.by = by ? by : itm.defaultValueStr;
} }
data.push(itm); data.push(itm);
by && (arrAdd[item[0]] = undefined);
}); });
for(var key in arrAdd){
if(arrAdd.hasOwnProperty(key) && arrAdd[key]){ var dataAdd = [];
var itm = { _.each(arrAdd, function(item, index){
replaced: key, var idx = _.findIndex(data, {replaced: item[0]});
by: arrAdd[key], if (idx<0) {
dataAdd.push({
replaced: item[0],
by: item[1],
defaultDisabled: false defaultDisabled: false
}; });
data.push(itm); } else {
var changed = data[idx];
changed.by = item[1];
} }
} });
this.mathStore.reset(data); this.mathStore.reset(data.concat(dataAdd));
this.updateControls(); this.updateControls();
}, },

View file

@ -1057,7 +1057,7 @@ define([
// autocorrection // autocorrection
value = Common.localStorage.getItem("de-settings-math-correct-add"); value = Common.localStorage.getItem("de-settings-math-correct-add");
Common.Utils.InternalSettings.set("de-settings-math-correct-add", value); Common.Utils.InternalSettings.set("de-settings-math-correct-add", value);
var arrAdd = value ? JSON.parse(value) : {}; var arrAdd = value ? JSON.parse(value) : [];
value = Common.localStorage.getItem("de-settings-math-correct-rem"); value = Common.localStorage.getItem("de-settings-math-correct-rem");
Common.Utils.InternalSettings.set("de-settings-math-correct-rem", value); Common.Utils.InternalSettings.set("de-settings-math-correct-rem", value);
var arrRem = value ? JSON.parse(value) : []; var arrRem = value ? JSON.parse(value) : [];