pi-vim-tree 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -9
- package/README.md +16 -2
- package/extensions/vim-tree.ts +74 -23
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [
|
|
3
|
+
## [0.1.1] - 2026-11-16
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
5
|
+
- The preview pane now renders the selected entry with Pi's own `Markdown` component and `getMarkdownTheme()`, so headings, lists, quotes and fenced code blocks look like they do in the conversation, including syntax highlighting. It follows the active theme, custom themes included, and adds no new dependency: the renderer and highlight.js come from Pi itself.
|
|
6
|
+
- Preview scrolling is a one-line window over the rendered lines (`ctrl+e` / `ctrl+y`). Plain wrapped text remains as the fallback when no theme is available.
|
|
7
|
+
- Search-term highlighting in the preview now only applies to that plain-text fallback; recolouring Markdown lines would corrupt their ANSI styling.
|
|
8
|
+
- The changelog now lists what 0.1.0 shipped instead of leaving it under `Unreleased`.
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-11-15
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
First published release.
|
|
12
13
|
|
|
13
|
-
- Initial release.
|
|
14
14
|
- Vim folding: `zc` / `zo` / `za` / `zC` / `zO` / `zA` / `zm` / `zr` / `zM` / `zR` / `zj` / `zk` / `zv`.
|
|
15
15
|
- Stable line numbers: folding never renumbers rows, so `G`, `{n}G`, `gg` and `%` always mean the same row.
|
|
16
|
-
- Logical cursor row, jump list (`ctrl+o` / `ctrl+i`), marks (`m{x}`, `` ` ``{x}
|
|
16
|
+
- Logical cursor row, jump list (`ctrl+o` / `ctrl+i`), marks (`m{x}`, `` ` ``{x}), and a showcmd-style status bar.
|
|
17
17
|
- Fixed-height list with a side preview.
|
|
18
18
|
- `/vim-tree on|off` restores Pi's native tree exactly.
|
|
19
|
+
- Branch motion on `h` / `l` (next / previous branch head), matching `ctrl+j` / `ctrl+k`. Branch-head jumps also enter the jump list, so `ctrl+o` walks back through the branches you visited.
|
|
20
|
+
- Half-page scroll on `u` / `d`, matching `ctrl+u` / `ctrl+d`.
|
|
21
|
+
- Label editing and label timestamps are on uppercase keys only: `L` / `T`. Lowercase `l` is branch motion, lowercase `t` is unbound.
|
|
22
|
+
- `q` closes the tree (native `esc` behaviour is unchanged; `ctrl+l` stays the way to clear a pending command or the search highlight).
|
|
23
|
+
- No single-mark delete: `d` is half-page scroll, so a mark is cleared with `M` or overwritten by setting it again.
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ The extension patches the native tree in place. It never replaces `/tree`, never
|
|
|
14
14
|
- **Marks** - `m` plus a letter or digit sets a mark, backtick plus the same name jumps back to it
|
|
15
15
|
- **Showcmd status bar** - pending prefixes and executed commands echo the way Vim's `showcmd` does
|
|
16
16
|
- **Fixed-height layout** - the list never resizes, so filtering or folding never makes the panel jump
|
|
17
|
-
- **Side preview** - the selected message body is shown next to the tree, fzf `--preview-window` style
|
|
17
|
+
- **Side preview** - the selected message body is shown next to the tree, rendered as Markdown with syntax highlighting, fzf `--preview-window` style
|
|
18
18
|
|
|
19
19
|
**Example use cases:**
|
|
20
20
|
- Navigating long sessions without losing your place
|
|
@@ -152,6 +152,10 @@ Native tree keys (`j`/`k`, `enter`, `L` label, `T` label time, `/` search) keep
|
|
|
152
152
|
| `ctrl+h` (or `F4`) | Toggle the side preview |
|
|
153
153
|
| `ctrl+e` / `ctrl+y` | Scroll the preview by one line |
|
|
154
154
|
|
|
155
|
+
The body is rendered with Pi's own `Markdown` component and `getMarkdownTheme()`, so headings, lists, quotes and fenced code blocks look exactly like they do in the conversation - including syntax highlighting (same theme tokens, same highlight.js grammars, custom themes included). It scrolls as a one-line window over the rendered lines: `ctrl+e` / `ctrl+y`. `ctrl+d` / `ctrl+u` (and `d` / `u`) move the list cursor by half a page instead.
|
|
156
|
+
|
|
157
|
+
The preview needs no theme of its own: it borrows the active one. If the theme is unavailable, it falls back to plain wrapped text; search-term highlighting is only applied in that fallback, because recolouring Markdown lines would corrupt their ANSI styling. The tree rows still mark the matches either way.
|
|
158
|
+
|
|
155
159
|
## Folding Model
|
|
156
160
|
|
|
157
161
|
Pi's native tree marks the rows that can be folded with `⊟`, and shows `⊞` once a fold is closed. pi-vim-tree folds exactly those rows, and nothing else:
|
|
@@ -254,7 +258,7 @@ Session Tree Fold 2/5 · Match 1/3 · Jump 4/9 · Mark a,b
|
|
|
254
258
|
|
|
255
259
|
The list keeps a fixed height - 60% of the available space, capped at 30 rows - so folding, filtering, or a shorter session never resizes the panel and never makes surrounding UI shift.
|
|
256
260
|
|
|
257
|
-
The preview occupies the right 55% of the width, fzf `--preview-window right:55%` style. Because the list height is fixed and the preview only takes horizontal space, toggling the preview causes no reflow at all.
|
|
261
|
+
The preview occupies the right 55% of the width, fzf `--preview-window right:55%` style. Because the list height is fixed and the preview only takes horizontal space, toggling the preview causes no reflow at all. The body itself is rendered as Markdown, like the conversation - see [Preview](#preview).
|
|
258
262
|
|
|
259
263
|
## Compatibility
|
|
260
264
|
|
|
@@ -272,6 +276,8 @@ Because it relies on private fields, it self-checks on startup. If Pi's internal
|
|
|
272
276
|
|
|
273
277
|
**The tree shows a lot of `remote-pi` rows.** Those are custom messages the remote-pi package appends to the session history, one per rename. Pi's tree filter has no way to hide custom messages.
|
|
274
278
|
|
|
279
|
+
**The preview shows raw Markdown** (`#` headings, `**asterisks**`, no colours). The preview fell back to plain text because Pi's theme was not available at render time. Restarting Pi re-initialises the theme; if it still happens, `/vim-tree` and the Pi log will show why.
|
|
280
|
+
|
|
275
281
|
## Releasing
|
|
276
282
|
|
|
277
283
|
The package is published from this directory:
|
|
@@ -284,6 +290,14 @@ Publishing needs a second factor. Use the code from your authenticator app, or t
|
|
|
284
290
|
|
|
285
291
|
For unattended releases, configure **trusted publishing** (OpenID Connect) on the npm package and point it at a GitHub Actions workflow. That removes the need for tokens entirely.
|
|
286
292
|
|
|
293
|
+
Publishing from a directory without a git repository is fine - npm does not require one. There is then no `gitHead` in the metadata, no provenance attestation, and no repository link on the npm page, and every release is a manual `npm login` plus 2FA. The TypeScript source ships in the tarball, so users can still read exactly what runs.
|
|
294
|
+
|
|
295
|
+
Verify the published artifact without installing it:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
pi -e npm:pi-vim-tree
|
|
299
|
+
```
|
|
300
|
+
|
|
287
301
|
## Differences from Vim
|
|
288
302
|
|
|
289
303
|
These are deliberate:
|
package/extensions/vim-tree.ts
CHANGED
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
* 2. 布局:列表高度固定(fzf 风格 `height: 0.6`,上限 30 行),
|
|
23
23
|
* 内容变少/折叠/过滤都只在框内变化,**整个框不伸缩、不跳**。
|
|
24
24
|
* 3. 预览:fzf `--preview-window right:55%` 风格——树在左,选中项的完整正文在右;
|
|
25
|
+
* 正文交给 pi 自己的 `Markdown` 组件 + `getMarkdownTheme()` 渲染,所以标题、列表、
|
|
26
|
+
* 引用、代码块的**语法高亮**跟消息正文一模一样(同一套主题 token、同一个 highlight.js)。
|
|
27
|
+
* 预览只滑窗(ctrl+e/y 逐行),不整框滚动;
|
|
25
28
|
* 因为列表高度固定、预览只占右半,所以开关预览不产生任何高度重排。
|
|
26
29
|
*
|
|
27
30
|
* 界面上全是英文;折叠层级(Fold x/y)和匹配计数(Match x/y)紧跟在
|
|
@@ -73,12 +76,13 @@
|
|
|
73
76
|
* (类原型上的 handleInput/render、树实例上的 applyFilter、搜索状态),不留残留。
|
|
74
77
|
*/
|
|
75
78
|
|
|
76
|
-
import { Container, Input, decodeKittyPrintable, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
79
|
+
import { Container, Input, Markdown, decodeKittyPrintable, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
77
80
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
78
81
|
import { homedir } from "node:os";
|
|
79
82
|
import { dirname, join } from "node:path";
|
|
80
83
|
import { pathToFileURL } from "node:url";
|
|
81
84
|
|
|
85
|
+
import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
82
86
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
83
87
|
|
|
84
88
|
// ---------------------------------------------------------------- 布局常量
|
|
@@ -936,35 +940,81 @@ function gotoRow(treeList: any, row: number): void {
|
|
|
936
940
|
|
|
937
941
|
// ---------------------------------------------------------------- 预览
|
|
938
942
|
|
|
939
|
-
/**
|
|
940
|
-
function
|
|
943
|
+
/** 纯文本换行(没有 markdown 可用时的退路;也可能是 pi 已经染好色的单行摘要) */
|
|
944
|
+
function wrapPlain(text: string, width: number): string[] {
|
|
945
|
+
const lines: string[] = [];
|
|
946
|
+
if (!text) return lines;
|
|
947
|
+
for (const rawLine of text.split("\n")) {
|
|
948
|
+
const line = rawLine.trimEnd();
|
|
949
|
+
lines.push(...(line ? wrapTextWithAnsi(line, width) : [""]));
|
|
950
|
+
}
|
|
951
|
+
return lines;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* 预览走 pi 自己的 Markdown 渲染器:主题、代码块语法高亮(highlight.js)都跟消息正文一模一样。
|
|
956
|
+
* 每个 treeList 只留一个实例,选中项变了才 setText,宽度变化由组件内部重排。
|
|
957
|
+
* 主题没初始化(裸 node 之类)时返回 undefined,由调用方退回纯文本。
|
|
958
|
+
*/
|
|
959
|
+
function renderMarkdown(
|
|
960
|
+
treeList: any,
|
|
961
|
+
node: any,
|
|
962
|
+
text: string,
|
|
963
|
+
width: number,
|
|
964
|
+
): { lines: string[]; total: number; plain: boolean } | undefined {
|
|
965
|
+
const holder = (treeList.__vtMd ??= { failed: false, key: undefined, md: undefined });
|
|
966
|
+
if (holder.failed) return undefined;
|
|
967
|
+
if (!holder.md) {
|
|
968
|
+
try {
|
|
969
|
+
holder.md = new Markdown("", 0, 0, getMarkdownTheme());
|
|
970
|
+
} catch {
|
|
971
|
+
holder.failed = true;
|
|
972
|
+
return undefined;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
const key = `${node?.entry?.id ?? ""}:${text.length}`;
|
|
976
|
+
if (holder.key !== key) {
|
|
977
|
+
holder.md.setText(text);
|
|
978
|
+
holder.key = key;
|
|
979
|
+
}
|
|
980
|
+
const lines: string[] = holder.md.render(Math.max(1, width));
|
|
981
|
+
return { lines, total: lines.length, plain: false };
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* 选中项的完整内容;返回总行数便于翻页。
|
|
986
|
+
* `plain=true` 表示内容已经是带 ANSI 的纯文本(此时才值得再染搜索词)。
|
|
987
|
+
*/
|
|
988
|
+
function wrapPreview(treeList: any, width: number): { lines: string[]; total: number; plain: boolean } {
|
|
941
989
|
const node = treeList.filteredNodes?.[treeList.selectedIndex]?.node;
|
|
942
|
-
if (!node) return { lines: [], total: 0 };
|
|
990
|
+
if (!node) return { lines: [], total: 0, plain: true };
|
|
943
991
|
|
|
944
|
-
|
|
992
|
+
// 1) 正文(markdown 原文)→ 交给 pi 的 Markdown 渲染
|
|
993
|
+
let raw = "";
|
|
945
994
|
try {
|
|
946
|
-
if (typeof treeList.getEntryCopyText === "function")
|
|
995
|
+
if (typeof treeList.getEntryCopyText === "function") raw = String(treeList.getEntryCopyText(node) ?? "");
|
|
947
996
|
} catch {
|
|
948
|
-
|
|
997
|
+
raw = "";
|
|
949
998
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
text = "";
|
|
957
|
-
}
|
|
999
|
+
raw = raw.replace(/\r/g, "").trim();
|
|
1000
|
+
if (raw) {
|
|
1001
|
+
const rendered = renderMarkdown(treeList, node, raw, width);
|
|
1002
|
+
if (rendered) return rendered;
|
|
1003
|
+
const lines = wrapPlain(raw, width);
|
|
1004
|
+
return { lines, total: lines.length, plain: true };
|
|
958
1005
|
}
|
|
959
|
-
text = text.replace(/\r/g, "").trim();
|
|
960
|
-
if (!text) return { lines: [], total: 0 };
|
|
961
1006
|
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1007
|
+
// 2) 没有正文 → 退回原生的一行摘要(已经带 ANSI,不再二次渲染)
|
|
1008
|
+
let text = "";
|
|
1009
|
+
try {
|
|
1010
|
+
if (typeof treeList.getEntryDisplayText === "function") {
|
|
1011
|
+
text = String(treeList.getEntryDisplayText(node, false) ?? "");
|
|
1012
|
+
}
|
|
1013
|
+
} catch {
|
|
1014
|
+
text = "";
|
|
966
1015
|
}
|
|
967
|
-
|
|
1016
|
+
const lines = wrapPlain(text.replace(/\r/g, "").trim(), width);
|
|
1017
|
+
return { lines, total: lines.length, plain: true };
|
|
968
1018
|
}
|
|
969
1019
|
|
|
970
1020
|
/** 预览翻页状态:选中项变化时归零,偏移在渲染时按内容长度夹紧 */
|
|
@@ -2035,9 +2085,10 @@ function layoutScreen(component: any, lines: string[], width: number, hardMax: n
|
|
|
2035
2085
|
treeList.__vtPreviewInfo = { page, total: wrapped.total };
|
|
2036
2086
|
|
|
2037
2087
|
const previewTokens = activeSearch(treeList).query.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
2088
|
+
// 搜索词染色只对纯文本做:markdown 行里已经有主题色,再塞 ANSI 会把标记打乱
|
|
2038
2089
|
const visible = wrapped.lines
|
|
2039
2090
|
.slice(state.offset, state.offset + page)
|
|
2040
|
-
.map((line) => (previewTokens.length > 0 ? highlightTokens(line, previewTokens, false) : line));
|
|
2091
|
+
.map((line) => (wrapped.plain && previewTokens.length > 0 ? highlightTokens(line, previewTokens, false) : line));
|
|
2041
2092
|
const label =
|
|
2042
2093
|
wrapped.total > page
|
|
2043
2094
|
? `preview ${state.offset + 1}-${Math.min(wrapped.total, state.offset + page)}/${wrapped.total} ctrl+d/u half · ctrl+e/y line`
|