Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.1 KB
Raw Blame
import {isHiddenTabContent} from "../render/tabsVisibility";

// 点击空正文时,浏览器可能保留隐藏页签中的选区,先将失效的光标放到当前编辑区域。
export const repairHiddenTabSelection = (root: HTMLElement, target: Element) => {
    const selection = window.getSelection();
    const anchor = selection?.anchorNode;
    const anchorElement = anchor instanceof Element ? anchor : anchor?.parentElement;
    const editable = target.closest<HTMLElement>('[contenteditable="true"]');
    if (!anchor || !root.contains(anchor) || !isHiddenTabContent(anchorElement) ||
        !editable || !root.contains(editable) || !editable.closest(".tab-item-content") ||
        isHiddenTabContent(editable) || target.closest('[contenteditable="false"]') ||
        editable.textContent !== "" || editable.querySelector("[data-node-id], img, input, video, audio, iframe")) {
        return;
    }
    const range = document.createRange();
    range.selectNodeContents(editable);
    range.collapse(true);
    selection.removeAllRanges();
    selection.addRange(range);
};