diff --git a/static/js/skills.js b/static/js/skills.js index 8eac3954c..0bea897b2 100644 --- a/static/js/skills.js +++ b/static/js/skills.js @@ -514,6 +514,8 @@ function _buildBuiltinCards() { card.addEventListener('click', (e) => { if (e.target.closest('button, input, textarea')) return; + // Editing in progress → don't collapse on an outside-the-textarea click. + if (card.querySelector('.skill-md-editor')) return; _expandBuiltinCard(card, b.name); }); return card; @@ -786,6 +788,10 @@ function renderSkillsList() { card.addEventListener('click', (e) => { if (card._suppressNextClick) { card._suppressNextClick = false; return; } if (e.target.closest('button, input, textarea')) return; + // While editing, a click on the card body (outside the textarea) must + // NOT collapse the card — that silently discards unsaved edits. Only + // Save/Cancel exit edit mode. + if (card.querySelector('.skill-md-editor')) return; if (_selectMode) { const cb = card.querySelector('.skill-select-cb'); if (cb) { cb.checked = !cb.checked; cb.dispatchEvent(new Event('change')); } diff --git a/tests/test_skill_edit_no_collapse_on_outside_click_js.py b/tests/test_skill_edit_no_collapse_on_outside_click_js.py new file mode 100644 index 000000000..1a25c5325 --- /dev/null +++ b/tests/test_skill_edit_no_collapse_on_outside_click_js.py @@ -0,0 +1,56 @@ +"""Regression guard for issue #4002 — clicking the card body outside the +edit textarea collapsed the skill card and silently discarded unsaved edits. + +In Brain > Skills, the card's click handler toggles expand/collapse. The +edit