Discover Packages
github.com/CarlOpenLab/Gloss
internal
filetree
package
Version:
v0.3.38
Opens a new window with list of versions in this module.
Published: Nov 16, 2026
License: MIT
Opens a new window with license information.
Imports: 2
Opens a new window with list of imports.
Imported by: 0 modules, 0 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
Documentation
Documentation
¶
Package filetree 把文件变更列表拼成目录树,供侧边栏渲染。
算法移植自 Web 版(web/src/fileTree.ts),最关键的一条是:只含单个子目录的
目录链会合并成一行(internal/server/handler 显示成一行而不是三层),
否则深路径会把侧边栏横向撑爆。
FuzzyMatch 做大小写不敏感的子序列匹配,和 godiff 的 Filter files 行为一致:
输入 "inmh" 能匹配 "internal/model/handler.go"。
Node 是文件树里的一个节点。
Build 把文件列表拼成树。
files 的顺序决定同层内的先后。git status 的输出本身按路径排序,
所以传进来就是有序的。
BuildAt 和 Build 一样建树,但 FileIdx 从 base 开始数、节点 Key 带 keyPrefix。
文件列表分成「已暂存 / 未暂存」两段、各建一棵树时用:base 把 FileIdx 对回
扁平列表(两段共用同一份切片的拼接),keyPrefix 让两段的折叠状态互不干扰
—— 同一个路径可以同时在两段里(暂存之后又改了),Key 不带前缀就会串。
Filter 返回只包含匹配文件的树(保留匹配文件的所有祖先目录)。
query 为空时返回原树。匹配的是完整路径而不是单层文件名 —— 用户
输入 "srv" 时希望找到 internal/server/x.go,而不是只筛当前层的名字。
type Row struct {
Node *Node
Depth int
}
Row 是树展开成一维列表后的一行,带缩进深度。
Flatten 把树展开成一维列表,跳过折叠目录里的内容。
flat 为 true 时忽略 collapsed(用于「全部展开」和筛选态 —— 筛选时
必须无视折叠状态,否则搜到的文件可能藏在收起的目录里看不见)。
FlattenFunc 和 Flatten 一样摊平,但「某个目录是否收起」交给调用方判断。
两种默认值靠这个回调区分:改动列表那棵树默认展开、只记用户收起过哪些;
编辑器栏的工作区树反过来 —— 默认全收起、只认用户展开过的那几个。树本身
不必知道自己是哪一种,也就不会再有人把两份折叠状态混成一个 map。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.