autofocus on a manually added applies-to

This commit is contained in:
tophf 2020-10-10 07:54:57 +03:00
parent 02a9e409fb
commit eba5bc64e5

View File

@ -296,19 +296,14 @@ function createSection({
function insertApplyAfter(init, base) { function insertApplyAfter(init, base) {
const apply = createApply(init); const apply = createApply(init);
if (base) { appliesTo.splice(base ? appliesTo.indexOf(base) + 1 : appliesTo.length, 0, apply);
const index = appliesTo.indexOf(base); appliesToContainer.insertBefore(apply.el, base ? base.el.nextSibling : null);
appliesTo.splice(index + 1, 0, apply);
appliesToContainer.insertBefore(apply.el, base.el.nextSibling);
} else {
appliesTo.push(apply);
appliesToContainer.appendChild(apply.el);
}
dirty.add(apply, apply); dirty.add(apply, apply);
if (appliesTo.length > 1 && appliesTo[0].all) { if (appliesTo.length > 1 && appliesTo[0].all) {
removeApply(appliesTo[0]); removeApply(appliesTo[0]);
} }
emitSectionChange(); emitSectionChange();
return apply;
} }
function removeApply(apply) { function removeApply(apply) {
@ -380,7 +375,7 @@ function createSection({
} }
$('.add-applies-to', el).addEventListener('click', e => { $('.add-applies-to', el).addEventListener('click', e => {
e.preventDefault(); e.preventDefault();
insertApplyAfter({type, value: ''}, apply); $('input', insertApplyAfter({type, value: ''}, apply).el).focus();
}); });
return apply; return apply;