Get selected profile vars despite pinned custom

This commit is contained in:
Norbert Renner 2022-02-16 16:12:24 +01:00
parent 4d44153316
commit 7bbbffbd3f

View file

@ -41,15 +41,11 @@ BR.Profile = L.Evented.extend({
update: function (options, cb) { update: function (options, cb) {
var profileName = options.profile, var profileName = options.profile,
profileUrl, profileUrl,
empty = !this.editor.getValue(),
clean = this.editor.isClean(),
loading = false; loading = false;
if (profileName && BR.conf.profilesUrl) { if (profileName && BR.conf.profilesUrl) {
// only synchronize profile editor/parameters with selection if no manual changes in full editor, this.selectedProfileName = profileName;
// else keep custom profile pinned - to prevent changes in another profile overwriting previous ones
if (empty || clean) {
this.profileName = profileName;
if (!(profileName in this.cache)) { if (!(profileName in this.cache)) {
profileUrl = BR.conf.profilesUrl + profileName + '.brf'; profileUrl = BR.conf.profilesUrl + profileName + '.brf';
loading = true; loading = true;
@ -65,23 +61,14 @@ BR.Profile = L.Evented.extend({
this.cache[profileName] = profileText; this.cache[profileName] = profileText;
// don't set when option has changed while loading // don't set when option has changed while loading
if (!this.profileName || this.profileName === profileName) { if (!this.profileName || this.selectedProfileName === profileName) {
this._setValue(profileText); this._updateProfile(profileName, profileText);
} }
if (cb) cb(); if (cb) cb();
}, this) }, this)
); );
} else { } else {
this._setValue(this.cache[profileName]); this._updateProfile(profileName, this.cache[profileName]);
}
if (!this.pinned.hidden) {
this.pinned.hidden = true;
}
} else {
if (this.pinned.hidden) {
this.pinned.hidden = false;
}
} }
} }
@ -107,7 +94,7 @@ BR.Profile = L.Evented.extend({
} }
} }
const profileText = this._getProfileText(); const profileText = this._getSelectedProfileText();
if (!profileText) return value; if (!profileText) return value;
const regex = new RegExp(`assign\\s*${name}\\s*=?\\s*([\\w\\.]*)`); const regex = new RegExp(`assign\\s*${name}\\s*=?\\s*([\\w\\.]*)`);
@ -194,6 +181,26 @@ BR.Profile = L.Evented.extend({
}); });
}, },
_updateProfile: function (profileName, profileText) {
const empty = !this.editor.getValue();
const clean = this.editor.isClean();
// only synchronize profile editor/parameters with selection if no manual changes in full editor,
// else keep custom profile pinned - to prevent changes in another profile overwriting previous ones
if (empty || clean) {
this.profileName = profileName;
this._setValue(profileText);
if (!this.pinned.hidden) {
this.pinned.hidden = true;
}
} else {
if (this.pinned.hidden) {
this.pinned.hidden = false;
}
}
},
_setValue: function (profileText) { _setValue: function (profileText) {
profileText = profileText || ''; profileText = profileText || '';
@ -369,4 +376,8 @@ BR.Profile = L.Evented.extend({
_getProfileText: function () { _getProfileText: function () {
return this.editor.getValue(); return this.editor.getValue();
}, },
_getSelectedProfileText: function () {
return this.cache[this.selectedProfileName] ?? this.editor.getValue();
},
}); });