diff --git a/webapp/static/clients/codemirror/list.js b/webapp/static/clients/codemirror/list.js index 455a668..8bafc46 100644 --- a/webapp/static/clients/codemirror/list.js +++ b/webapp/static/clients/codemirror/list.js @@ -8,18 +8,18 @@ class ListComponent extends HTMLElement { #iconKinds; //array from kind integer to codicon name constructor() { super(); - this.#shadow = this.attachShadow({ mode: "open" ,delegatesFocus: true}); + this.#shadow = this.attachShadow({ mode: "open", delegatesFocus: true }); this.#data = []; this.#iconKinds = []; this.render(); } - setData(newData,icons, append = false) { + setData(newData, icons, append = false) { if (!Array.isArray(newData)) { console.warn("Invalid format, expected an array."); return; } - this.#iconKinds=icons; + this.#iconKinds = icons; this.#data = append ? this.#data.concat(newData) : structuredClone(newData); this.render(); } @@ -34,14 +34,17 @@ class ListComponent extends HTMLElement { /* Render the list items #data */ render() { const list = document.createElement('ul'); - list.style="max-height:80cqh;overflow: auto;"; - const shad=this.#shadow; + list.style = "max-height:80cqh;overflow: auto;"; + const shad = this.#shadow; this.#data.forEach((item, index) => { const listItem = document.createElement('li'); listItem.innerHTML = ` ${item.name} - ${item.detail}`; - // Adding a click event listener for user interaction - listItem.addEventListener('click', () => { + + listItem.addEventListener('click', function (e) { + shad.querySelectorAll('li.selected').forEach(item => { item.className = ''; }); + e.currentTarget.className = 'selected'; + console.log('Item clicked:', item, listItem); // You can dispatch a custom event here if needed. this.dispatchEvent(new CustomEvent('itemSelected', { @@ -50,12 +53,6 @@ class ListComponent extends HTMLElement { composed: true })); }); - list.addEventListener('click', function (e) { - if (e.target.tagName === 'LI') { - shad.querySelectorAll('li.selected').forEach(item=>{item.className = '';}); - e.target.className = 'selected'; - } - }); list.appendChild(listItem); });