解决富文本工具栏单击按钮失效的问题

This commit is contained in:
枫谷剑仙 2025-05-13 19:19:25 +08:00
parent e1d1f0c48a
commit b8044df1ae
2 changed files with 9 additions and 9 deletions

View File

@ -1315,7 +1315,7 @@ function richTextCardNClick(){
this.querySelector(".monster").onclick();
}
//创建序号类图标
function createIndexedIcon(type, index) {
function createIndexedIcon(type, index, noFocus = false) {
const className = "drag-able-icon";
let icon;
if (type == 'card') {//卡片头像
@ -1351,7 +1351,7 @@ function createIndexedIcon(type, index) {
icon.draggable = true;
//icon.tabIndex = 0; // 为了让 :focus 生效
icon.ondragstart = indexedIconOnDragStart;
icon.addEventListener("click", indexedIconFocusSelf);
if (!noFocus) icon.addEventListener("click", indexedIconFocusSelf);
icon.indexedIcon = {type, index}; //拖拽用的
return icon;
}
@ -1364,7 +1364,7 @@ function indexedIconOnDragStart(event){
}
function indexedIconFocusSelf(event){
const selectRange = document.createRange();
const selection = window.getSelection();
const selection = document.getSelection();
if (!event?.ctrlKey) {
//调整为只选中节点开始的部位
selectRange.setEndBefore(this);

View File

@ -3364,7 +3364,7 @@ function initialize() {
}
}
let docSelection = document.getSelection();
const docSelection = document.getSelection();
//标题和介绍文本框
const titleBox = formationBox.querySelector(".title-box");
const detailBox = formationBox.querySelector(".detail-box");
@ -3398,25 +3398,25 @@ function initialize() {
for (let id of official_awoken_sorting) {
const li = document.createElement("li");
const icon = li.appendChild(createIndexedIcon('awoken', id));
const icon = li.appendChild(createIndexedIcon('awoken', id, true));
icon.onclick = insertIconToText;
insertAwokenIconList.appendChild(li);
}
for (let id of Array.from(editBox.querySelectorAll(".setting-box .row-mon-latent details .m-latent-allowable-ul .latent-icon")).map(li=>li.getAttribute("data-latent-icon"))) {
const li = document.createElement("li");
const icon = li.appendChild(createIndexedIcon('latent', id));
const icon = li.appendChild(createIndexedIcon('latent', id, true));
icon.onclick = insertIconToText;
insertLatentIconList.appendChild(li);
}
for (let obj of typekiller_for_type) {
const li = document.createElement("li");
const icon = li.appendChild(createIndexedIcon('type', obj.type));
const icon = li.appendChild(createIndexedIcon('type', obj.type, true));
icon.onclick = insertIconToText;
insertTypeIconList.appendChild(li);
}
for (let i=0;i<10;i++) {
const li = document.createElement("li");
const icon = li.appendChild(createIndexedIcon('orb', i));
const icon = li.appendChild(createIndexedIcon('orb', i, true));
icon.onclick = insertIconToText;
insertOrbList.appendChild(li);
}
@ -5754,7 +5754,7 @@ function initialize() {
}
else
{
let selection = window.getSelection(), selectNodes = selection?.focusNode?.childNodes;
let selection = docSelection, selectNodes = selection?.focusNode?.childNodes;
//如果正在编辑文本,则不执行快捷键操作
if (selectNodes && Array.from(selectNodes).some(node=>node?.nodeName === "TEXTAREA" || node?.nodeName === "INPUT"))
return;