Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文档树无法「定位打开的文档」 #18

Open
TCOTC opened this issue May 10, 2024 · 9 comments
Open

文档树无法「定位打开的文档」 #18

TCOTC opened this issue May 10, 2024 · 9 comments

Comments

@TCOTC
Copy link
Contributor

TCOTC commented May 10, 2024

开启「文档树层级指示竖线」后,如果该文档在文档树上的层级大于2,无法「定位打开的文档」

@TCOTC TCOTC changed the title 开启「文档树层级指示竖线」后,如果该文档在文档树上的层级大于2,无法「定位打开的文档」 文档树无法「定位打开的文档」 May 10, 2024
@zxkmm
Copy link
Owner

zxkmm commented May 10, 2024

感谢汇报。我刚才复现了,这个可能不太好解决,因为大部分的实现是在思源那边。如果思源那边实现没有考虑伪元素的话,这个用纯css伪元素的方案确实会带来很多问题。但是比较可惜我目前想不到稳定高性能的除了伪元素的竖线方案。等我问问GPT。

@forever765
Copy link

forever765 commented Nov 16, 2024

@zxkmm 相同问题+1,给日常使用带来了很大的不便,望修复

@zxkmm
Copy link
Owner

zxkmm commented Nov 16, 2024

我有空读一下思源的定位文档的代码,然后从思源那边解决这个问题。

@zxkmm
Copy link
Owner

zxkmm commented Nov 16, 2024

notes

const selectOpenTab = () => {
    /// #if MOBILE
    if (window.siyuan.mobile.editor?.protyle) {
        openDock("file");
        window.siyuan.mobile.files.selectItem(window.siyuan.mobile.editor.protyle.notebookId, window.siyuan.mobile.editor.protyle.path);
    }
    /// #else
    const dockFile = getDockByType("file");
    if (!dockFile) {
        return false;
    }
    const files = dockFile.data.file as Files;
    const element = document.querySelector(".layout__wnd--active > .fn__flex > .layout-tab-bar > .item--focus") ||
        document.querySelector("ul.layout-tab-bar > .item--focus");
    if (element) {
        const tab = getInstanceById(element.getAttribute("data-id")) as Tab;
        if (tab && tab.model instanceof Editor) {
            tab.model.editor.protyle.wysiwyg.element.blur();
            tab.model.editor.protyle.title.editElement.blur();
            files.selectItem(tab.model.editor.protyle.notebookId, tab.model.editor.protyle.path);
        }
    }
    dockFile.toggleModel("file", true);
    /// #endif
};
    public selectItem(notebookId: string, filePath: string, data?: {
        files: IFile[],
        box: string,
        path: string
    }, setStorage = true) {
        const treeElement = this.element.querySelector(`[data-url="${notebookId}"]`);
        if (!treeElement) {
            // 有文件树和编辑器的布局初始化时,文件树还未挂载
            return;
        }
        let currentPath = filePath;
        let liElement: HTMLElement;
        while (!liElement) {
            liElement = treeElement.querySelector(`[data-path="${currentPath}"]`);
            if (!liElement) {
                const dirname = pathPosix().dirname(currentPath);
                if (dirname === "/") {
                    currentPath = dirname;
                } else {
                    currentPath = dirname + ".sy";
                }
            }
        }

        if (liElement.getAttribute("data-path") === filePath) {
            if (setStorage) {
                this.setCurrent(liElement);
                this.getOpenPaths();
            } else {
                this.element.querySelector(".b3-list-item--focus")?.classList.remove("b3-list-item--focus");
            }
            return;
        }

        if (data && data.path === currentPath) {
            this.onLsSelect(data, filePath, setStorage);
        } else {
            fetchPost("/api/filetree/listDocsByPath", {
                notebook: notebookId,
                path: currentPath
            }, response => {
                this.onLsSelect(response.data, filePath, setStorage);
            });
        }
    }

@zxkmm
Copy link
Owner

zxkmm commented Nov 16, 2024

        if (liElement.getAttribute("data-path") === filePath) {
            if (setStorage) {
                this.setCurrent(liElement);
                this.getOpenPaths();
            } else {
                this.element.querySelector(".b3-list-item--focus")?.classList.remove("b3-list-item--focus");
            }
            return;
        }
    private setCurrent(target: HTMLElement, isScroll = true) {
        if (!target) {
            return;
        }
        this.element.querySelectorAll("li").forEach((liItem) => {
            liItem.classList.remove("b3-list-item--focus");
        });
        target.classList.add("b3-list-item--focus");
        if (isScroll) {
            let offsetTop = target.offsetTop;
            // https://github.com/siyuan-note/siyuan/issues/8749
            if (target.parentElement.classList.contains("file-tree__sliderDown") && target.offsetParent) {
                offsetTop = (target.offsetParent as HTMLElement).offsetTop;
            }
            this.element.scrollTop = offsetTop - this.element.clientHeight / 2 - this.actionsElement.clientHeight;
        }
    }

@zxkmm
Copy link
Owner

zxkmm commented Nov 16, 2024

应该是找到问题了,和所有其他文档树的问题一样, 计算滚动数量的时候被伪元素干扰了。
这个是思源的问题,只能从思源那边修复。
this.element.scrollTop = offsetTop - this.element.clientHeight / 2 - this.actionsElement.clientHeight;

@forever765
Copy link

@zxkmm 大佬,请问思源那边有什么反馈或者进展么?如果有issue地址的话也可以发下,我也去帮一嘴

@zxkmm
Copy link
Owner

zxkmm commented Dec 14, 2024

您好, 抱歉, 我没有去发issue, 因为我估计按V的风格, 这个她不打算改

@zxkmm
Copy link
Owner

zxkmm commented Dec 14, 2024

我明年有空的话直接发PR到那边

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants