Skip to content

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

Closed
@TCOTC

Description

@TCOTC
Contributor

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

Activity

changed the title [-]开启「文档树层级指示竖线」后,如果该文档在文档树上的层级大于2,无法「定位打开的文档」[/-] [+]文档树无法「定位打开的文档」[/+] on May 10, 2024
zxkmm

zxkmm commented on May 10, 2024

@zxkmm
Owner

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

forever765

forever765 commented on Nov 16, 2024

@forever765

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

zxkmm

zxkmm commented on Nov 16, 2024

@zxkmm
Owner

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

zxkmm

zxkmm commented on Nov 16, 2024

@zxkmm
Owner

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

zxkmm commented on Nov 16, 2024

@zxkmm
Owner
        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

zxkmm commented on Nov 16, 2024

@zxkmm
Owner

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

forever765

forever765 commented on Dec 14, 2024

@forever765

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

zxkmm

zxkmm commented on Dec 14, 2024

@zxkmm
Owner

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

zxkmm

zxkmm commented on Jan 1, 2025

@zxkmm
Owner

已推送修复读代码。一层一层写解决了

forever765

forever765 commented on Jan 2, 2025

@forever765

v0.4.0测试,有个很奇怪的现象:

  • 从上到下是 A/B/C 三个笔记本
  • 三个笔记本各打开两个文档
  • 目录树位于C笔记本,此时点击A笔记本的文档,可以正常定位
  • 再点击B笔记本的文档,文档树无反应

即:由下往上定位是正常的,由上往下定位失效

reopened this on Jan 3, 2025
zxkmm

zxkmm commented on Jan 3, 2025

@zxkmm
Owner

请问是开启竖线功能吗发生的吗?

forever765

forever765 commented on Jan 3, 2025

@forever765

是的

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @forever765@zxkmm@TCOTC

        Issue actions

          文档树无法「定位打开的文档」 · Issue #18 · zxkmm/siyuan_doctree_compress