(panel, type)
| 562 | } |
| 563 | |
| 564 | function updateColorHistory(panel, type) { |
| 565 | const key = type === 'font' ? LS_KEYS.fontColors : LS_KEYS.bgColors; |
| 566 | const history = readJSON(key, []); |
| 567 | |
| 568 | panel.innerHTML = ''; |
| 569 | |
| 570 | if (history.length === 0) { |
| 571 | const emptyMsg = createElement('div', { className: 'nsn-history-empty' }, ['暂无历史颜色']); |
| 572 | panel.appendChild(emptyMsg); |
| 573 | } else { |
| 574 | const grid = createElement('div', { className: 'nsn-color-grid' }); |
| 575 | history.forEach(color => { |
| 576 | const colorBlock = createElement('div', { |
| 577 | className: 'nsn-color-block', |
| 578 | style: { backgroundColor: color }, |
| 579 | title: color |
| 580 | }); |
| 581 | colorBlock.addEventListener('mousedown', (e) => { |
| 582 | e.preventDefault(); |
| 583 | e.stopPropagation(); |
| 584 | saveSelection(); |
| 585 | }); |
| 586 | colorBlock.addEventListener('click', (e) => { |
| 587 | e.preventDefault(); |
| 588 | e.stopPropagation(); |
| 589 | restoreSelection(); |
| 590 | if (type === 'font') { |
| 591 | fontColorPicker.value = color; |
| 592 | cmd('foreColor', color); |
| 593 | } else { |
| 594 | bgColorPicker.value = color; |
| 595 | cmd('backColor', color); |
| 596 | } |
| 597 | hideAllHistoryPanels(); |
| 598 | }); |
| 599 | grid.appendChild(colorBlock); |
| 600 | }); |
| 601 | panel.appendChild(grid); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | function toggleHistoryPanel(panel, btn) { |
| 606 | const isVisible = panel.classList.contains('show'); |
no test coverage detected