opencode-scroll-mode 0.3.4 → 0.4.0
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/README.md +18 -7
- package/package.json +1 -1
- package/tui.ts +151 -4
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ opencode plugin add opencode-scroll-mode
|
|
|
13
13
|
`opencode plugin add` 会从 npm 安装并写入全局 `opencode.json(c)` 的 `plugins`。也可以锁定版本:
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
opencode plugin add opencode-scroll-mode@0.
|
|
16
|
+
opencode plugin add opencode-scroll-mode@0.4.0
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
升级 / 移除:
|
|
@@ -40,7 +40,7 @@ opencode plugin remove opencode-scroll-mode
|
|
|
40
40
|
|
|
41
41
|
## 功能
|
|
42
42
|
|
|
43
|
-
- `ctrl+
|
|
43
|
+
- `ctrl+s`(默认,可用 `toggleKey` 配置)在「编辑模式」与「滚动模式」之间切换。
|
|
44
44
|
- 编辑模式:输入框保留原生 readline 键位。
|
|
45
45
|
- 滚动模式:导航键位移动 transcript 中的行 / 字符游标;只有游标到达视口边缘时才让宿主滚动,并启用 vim 键位与搜索。
|
|
46
46
|
- 滚动模式会**锁定输入框**:进入时让编辑器失焦、隐藏编辑光标,并全局吞掉按键,避免滚动时误把字符打进 prompt;退出时恢复焦点、光标与输入。当其他组件(命令面板、搜索、选择等对话框)获得焦点时,滚动键位会**整体挂起**,把键盘交给对话框,避免在面板里打字时后台游标乱跳。
|
|
@@ -51,7 +51,7 @@ opencode plugin remove opencode-scroll-mode
|
|
|
51
51
|
|
|
52
52
|
| 键 | 动作 |
|
|
53
53
|
| --- | --- |
|
|
54
|
-
| `ctrl+
|
|
54
|
+
| `ctrl+s` | 开 / 关滚动模式(默认,可用 `toggleKey` 改) |
|
|
55
55
|
| `j` / `k` | 上 / 下移动行游标(到视口边缘时滚动一行) |
|
|
56
56
|
| `h` / `l`、`←` / `→` | 左 / 右移动字符游标 |
|
|
57
57
|
| `w` / `b` / `e` | 下一个词首 / 上一个词首 / 词尾 |
|
|
@@ -60,6 +60,7 @@ opencode plugin remove opencode-scroll-mode
|
|
|
60
60
|
| `ctrl+f` / `ctrl+b` | 下 / 上整页(游标保持屏幕行) |
|
|
61
61
|
| `gg` / `G` | 跳到首条 / 末条消息 |
|
|
62
62
|
| `[` / `]` | 上 / 下一条用户消息 |
|
|
63
|
+
| `enter` | 展开 / 收起光标所在行的工具详情(工具调用块、参数、输出) |
|
|
63
64
|
| `/` / `?` | 打开搜索(正 / 反向) |
|
|
64
65
|
| `n` / `N` | 下 / 上一个匹配 |
|
|
65
66
|
| `v` / `V` | 从当前游标位置进入 charwise / linewise visual 选区 |
|
|
@@ -88,6 +89,17 @@ opencode plugin remove opencode-scroll-mode
|
|
|
88
89
|
|
|
89
90
|
普通状态下 `y` 复制游标所在行,`Y` 按屏幕顺序复制当前视口内所有可复制行(代码块、软换行行都包含在内)——这就是「逐行取得显示内容」的入口。
|
|
90
91
|
|
|
92
|
+
### 展开 / 收起光标所在行
|
|
93
|
+
|
|
94
|
+
`enter` 会「点击」光标所在行对应的可展开块:宿主把每个工具调用(Read / Grep / Edit / Bash …)画成一行的头部,展开后显示参数与输出,但没有公开的命令可以切换它,所以插件直接向上找到该行最近的鼠标点击处理器并模拟一次左键抬起。效果与鼠标点那行完全一致:按一次展开,再按一次收起。
|
|
95
|
+
|
|
96
|
+
- 光标在**工具标题行**或其**展开后的参数 / 输出行**上都有效,因为处理挂在整块容器上。
|
|
97
|
+
- 活动分组(`+ 1 command, 1 thought` 这类折叠行)同样可以展开 / 收起。
|
|
98
|
+
- 不会冒泡到 transcript 之外,所以不会误触侧栏、状态栏等其他 UI。
|
|
99
|
+
- 用户消息行会被跳过(鼠标点它是「消息操作菜单」,不是展开),此时 toast 提示而不是弹出菜单。
|
|
100
|
+
- 模拟点击前会先清掉插件自己的行高亮(宿主把「已有选区」当成拖拽结束,会忽略这次点击),点击后立即按新布局恢复高亮。
|
|
101
|
+
- 该行没有可展开内容时会 toast 提示,不会静默失败。
|
|
102
|
+
|
|
91
103
|
### 精确到每一显示行
|
|
92
104
|
|
|
93
105
|
插件会在 transcript 的 ScrollBox 下遍历可选择文本节点,读取每个节点的 `lineInfo`:
|
|
@@ -128,7 +140,7 @@ yank 后写入系统剪贴板:优先 **OSC52**(iTerm2 需在设置里允许
|
|
|
128
140
|
"search": true,
|
|
129
141
|
"maxResults": 100,
|
|
130
142
|
"searchScope": "all",
|
|
131
|
-
"toggleKey": "ctrl+
|
|
143
|
+
"toggleKey": "ctrl+s",
|
|
132
144
|
"highlight": true,
|
|
133
145
|
"cursorColor": "#3d5a80",
|
|
134
146
|
"selectionColor": "#2f5d9e",
|
|
@@ -145,16 +157,15 @@ yank 后写入系统剪贴板:优先 **OSC52**(iTerm2 需在设置里允许
|
|
|
145
157
|
| `search` | boolean | `true` | 是否启用消息搜索 |
|
|
146
158
|
| `maxResults` | number | `100` | 搜索结果上限 |
|
|
147
159
|
| `searchScope` | `"all"` \| `"user"` | `"all"` | 搜索范围 |
|
|
148
|
-
| `toggleKey` | string | `"ctrl+
|
|
160
|
+
| `toggleKey` | string | `"ctrl+s"` | 切换滚动模式的按键(格式同 `bind`,如 `"ctrl+q"`、`"f9"`、`"ctrl+\\"`) |
|
|
149
161
|
| `highlight` | boolean | `true` | 行光标 / 选区高亮 |
|
|
150
162
|
| `cursorColor` | string | `"#3d5a80"` | 行光标背景色 |
|
|
151
163
|
| `selectionColor` | string | `"#2f5d9e"` | visual 选区背景色 |
|
|
152
164
|
| `barColor` | string | `"#7aa2f7"` | 字符游标竖线颜色 |
|
|
153
165
|
|
|
154
166
|
> 关于切换键的选择:
|
|
155
|
-
> -
|
|
167
|
+
> - `ctrl+s` 在很多终端里是 **XOFF 流控键**(`ctrl+q` 是 XON),可能被终端吞掉导致无法触发。如果遇到这种情况,可改用 `"toggleKey": "f9"` 或其他不冲突的按键。
|
|
156
168
|
> - `ctrl+[` 在多数终端里和 `Esc` 发送同一个字节(`0x1b`):只有终端开启 **kitty keyboard 协议**(kitty / WezTerm / Ghostty / 新版 iTerm2)时才能被识别成独立的 `Ctrl+[`;跑在 Neovim `:terminal` / sidekick.nvim 里时它就是纯 `Esc`,不会触发切换。
|
|
157
|
-
> - 如果在你的环境里 `ctrl+[` 没反应,改用 `"toggleKey": "f9"`(nvim / 终端都不拦截)最稳。
|
|
158
169
|
|
|
159
170
|
## 结构
|
|
160
171
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-scroll-mode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "OpenCode TUI scroll mode plugin — toggle edit/scroll states with vim keys, message search, and line-precise visual selection/copy",
|
|
6
6
|
"type": "module",
|
package/tui.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Plugin } from "@opencode/plugin/tui"
|
|
|
3
3
|
|
|
4
4
|
// Conversation scroll mode for the OpenCode TUI.
|
|
5
5
|
//
|
|
6
|
-
// - a toggle key (options.toggleKey, default ctrl+
|
|
6
|
+
// - a toggle key (options.toggleKey, default ctrl+s) switches between edit
|
|
7
7
|
// mode and scroll mode:
|
|
8
8
|
// * edit mode (default): the composer keeps its readline keys
|
|
9
9
|
// (ctrl+u delete-to-line-start, ctrl+d delete char, etc.).
|
|
@@ -22,7 +22,7 @@ import { Plugin } from "@opencode/plugin/tui"
|
|
|
22
22
|
// search boolean enable message search (default true)
|
|
23
23
|
// maxResults number max search results shown (default 100)
|
|
24
24
|
// searchScope string "all" | "user" (default "all")
|
|
25
|
-
// toggleKey string toggle key chord (default "ctrl+
|
|
25
|
+
// toggleKey string toggle key chord (default "ctrl+s")
|
|
26
26
|
//
|
|
27
27
|
// Cursor and visual mode (per rendered line): scroll mode always has a real
|
|
28
28
|
// cursor at an absolute screen row + character column. j/k move it by line
|
|
@@ -86,7 +86,7 @@ function readOptions(raw: unknown): Options {
|
|
|
86
86
|
search: o.search !== false,
|
|
87
87
|
maxResults: typeof maxRaw === "number" && maxRaw > 0 ? Math.floor(maxRaw) : 100,
|
|
88
88
|
searchScope: o.searchScope === "user" ? "user" : "all",
|
|
89
|
-
toggleKey: typeof o.toggleKey === "string" && o.toggleKey ? o.toggleKey : "ctrl+
|
|
89
|
+
toggleKey: typeof o.toggleKey === "string" && o.toggleKey ? o.toggleKey : "ctrl+s",
|
|
90
90
|
highlight: o.highlight !== false,
|
|
91
91
|
cursorColor: typeof o.cursorColor === "string" && o.cursorColor ? o.cursorColor : "#3d5a80",
|
|
92
92
|
selectionColor:
|
|
@@ -1475,6 +1475,145 @@ export default Plugin.define({
|
|
|
1475
1475
|
toast("Anchor and cursor swapped")
|
|
1476
1476
|
}
|
|
1477
1477
|
|
|
1478
|
+
// ---- expand / collapse the block under the cursor ----------------------
|
|
1479
|
+
// The host gives tool calls and other detail blocks a local `expanded`
|
|
1480
|
+
// signal toggled from an `onMouseUp` handler (there is no public command for
|
|
1481
|
+
// it). So Enter replays that click on the nearest clickable ancestor of the
|
|
1482
|
+
// line under the cursor: the tool header row for inline tools, or the
|
|
1483
|
+
// bordered container for block tools.
|
|
1484
|
+
const clickableAt = (node: RNode): { node: RNode; type: "up" | "down" } | null => {
|
|
1485
|
+
let cur: any = node
|
|
1486
|
+
let hops = 0
|
|
1487
|
+
while (cur && typeof cur === "object" && hops < 24) {
|
|
1488
|
+
// The transcript ScrollBox only handles wheel events, and everything
|
|
1489
|
+
// above it belongs to the surrounding UI: stop before leaving the
|
|
1490
|
+
// transcript so Enter can never "click" the sidebar or the status bar.
|
|
1491
|
+
if (visualBox && cur === visualBox) return null
|
|
1492
|
+
const listeners = (cur as any)._mouseListeners
|
|
1493
|
+
if (listeners && typeof listeners === "object") {
|
|
1494
|
+
if (typeof listeners.up === "function") return { node: cur as RNode, type: "up" }
|
|
1495
|
+
if (typeof listeners.down === "function") return { node: cur as RNode, type: "down" }
|
|
1496
|
+
}
|
|
1497
|
+
cur = (cur as any).parent
|
|
1498
|
+
hops++
|
|
1499
|
+
}
|
|
1500
|
+
return null
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
// The transcript also makes whole user messages clickable, and that click
|
|
1504
|
+
// opens the message actions menu. Enter means "expand details", so rows
|
|
1505
|
+
// inside a user message are left alone instead of popping a dialog over the
|
|
1506
|
+
// cursor.
|
|
1507
|
+
const insideUserMessage = (node: RNode): boolean => {
|
|
1508
|
+
const sid = currentSession()
|
|
1509
|
+
if (!sid) return false
|
|
1510
|
+
const boxes: any[] = []
|
|
1511
|
+
for (const m of listMessages(sid)) {
|
|
1512
|
+
if (!isUser(m)) continue
|
|
1513
|
+
const id = messageId(m)
|
|
1514
|
+
if (!id) continue
|
|
1515
|
+
const n = resolveNodeCached(id)
|
|
1516
|
+
if (n) boxes.push(n)
|
|
1517
|
+
}
|
|
1518
|
+
if (boxes.length === 0) return false
|
|
1519
|
+
let cur: any = node
|
|
1520
|
+
let hops = 0
|
|
1521
|
+
while (cur && typeof cur === "object" && hops < 24) {
|
|
1522
|
+
if (boxes.includes(cur)) return true
|
|
1523
|
+
if (visualBox && cur === visualBox) return false
|
|
1524
|
+
cur = (cur as any).parent
|
|
1525
|
+
hops++
|
|
1526
|
+
}
|
|
1527
|
+
return false
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
// Handlers expect a MouseEvent: some read button/x/y, some call
|
|
1531
|
+
// stopPropagation(). Nothing bubbles because we invoke the listener
|
|
1532
|
+
// directly instead of going through the renderer's hit-testing pass.
|
|
1533
|
+
const syntheticMouseEvent = (target: RNode, type: "up" | "down", x: number, y: number) => {
|
|
1534
|
+
const event: any = {
|
|
1535
|
+
type,
|
|
1536
|
+
button: 0,
|
|
1537
|
+
x,
|
|
1538
|
+
y,
|
|
1539
|
+
modifiers: 0,
|
|
1540
|
+
scroll: undefined,
|
|
1541
|
+
source: "keyboard",
|
|
1542
|
+
target,
|
|
1543
|
+
currentTarget: target,
|
|
1544
|
+
isDragging: false,
|
|
1545
|
+
propagationStopped: false,
|
|
1546
|
+
defaultPrevented: false,
|
|
1547
|
+
stopPropagation: () => {
|
|
1548
|
+
event.propagationStopped = true
|
|
1549
|
+
},
|
|
1550
|
+
preventDefault: () => {
|
|
1551
|
+
event.defaultPrevented = true
|
|
1552
|
+
},
|
|
1553
|
+
}
|
|
1554
|
+
return event
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
const toggleAtCursor = () => {
|
|
1558
|
+
if (!state.active) return
|
|
1559
|
+
const sid = currentSession()
|
|
1560
|
+
if (!sid) return
|
|
1561
|
+
const box = ensureVisualBox(listMessages(sid))
|
|
1562
|
+
if (!box) {
|
|
1563
|
+
toast("Nothing to toggle — the transcript is not mounted yet", "warning")
|
|
1564
|
+
return
|
|
1565
|
+
}
|
|
1566
|
+
const vis = lineIndex(box, true)
|
|
1567
|
+
if (vis.length === 0) {
|
|
1568
|
+
toast("Nothing to toggle on this screen", "warning")
|
|
1569
|
+
return
|
|
1570
|
+
}
|
|
1571
|
+
const row = typeof visual.cursorRow === "number" ? visual.cursorRow : vis[0].row
|
|
1572
|
+
const entry = entryAtRow(vis, row)
|
|
1573
|
+
if (!entry) return
|
|
1574
|
+
const target = clickableAt(entry.node)
|
|
1575
|
+
if (!target) {
|
|
1576
|
+
toast("Nothing to expand on this line", "warning")
|
|
1577
|
+
return
|
|
1578
|
+
}
|
|
1579
|
+
// A user-message row would open the actions menu instead of expanding
|
|
1580
|
+
// anything; refuse it (see insideUserMessage).
|
|
1581
|
+
if (insideUserMessage(target.node)) {
|
|
1582
|
+
toast("Nothing to expand on a user message", "warning")
|
|
1583
|
+
return
|
|
1584
|
+
}
|
|
1585
|
+
// The host's handler bails out while a selection exists (on mouse-up a
|
|
1586
|
+
// selection means "drag ended", not "click"), and our cursor highlight is
|
|
1587
|
+
// a real selection. Drop it, replay the click, then restore the cursor.
|
|
1588
|
+
clearLineSelection()
|
|
1589
|
+
let ok = false
|
|
1590
|
+
try {
|
|
1591
|
+
const handler = (target.node as any)._mouseListeners[target.type]
|
|
1592
|
+
handler.call(
|
|
1593
|
+
target.node,
|
|
1594
|
+
syntheticMouseEvent(target.node, target.type, nodeX(entry.node) + colOf(visual.cursorCol), entry.row),
|
|
1595
|
+
)
|
|
1596
|
+
ok = true
|
|
1597
|
+
} catch {
|
|
1598
|
+
ok = false
|
|
1599
|
+
}
|
|
1600
|
+
// Expansion changes the layout underneath us, so the old highlight key is
|
|
1601
|
+
// stale: rebuild after the host has re-laid out.
|
|
1602
|
+
lastKey = null
|
|
1603
|
+
applyHighlight()
|
|
1604
|
+
setTimeout(() => {
|
|
1605
|
+
if (!state.active) return
|
|
1606
|
+
lastKey = null
|
|
1607
|
+
applyHighlight()
|
|
1608
|
+
try {
|
|
1609
|
+
renderer?.requestRender?.()
|
|
1610
|
+
} catch {
|
|
1611
|
+
/* ignore */
|
|
1612
|
+
}
|
|
1613
|
+
}, 120)
|
|
1614
|
+
if (!ok) toast("This block did not accept the click", "warning")
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1478
1617
|
// ---- character cursor -----------------------------------------------
|
|
1479
1618
|
// The host's selection may not be visible in every build. This 1-cell bar
|
|
1480
1619
|
// is painted straight into the frame in the renderer's post-process pass
|
|
@@ -1931,7 +2070,7 @@ export default Plugin.define({
|
|
|
1931
2070
|
enterScroll()
|
|
1932
2071
|
if (options.vim) {
|
|
1933
2072
|
toast(
|
|
1934
|
-
"Scroll mode: editor disabled · j/k cursor · h/l column · w/b/e word · 0/$ ends · ctrl+d/u half · ctrl+f/b page · gg/G ends · [ ] user msgs · v/V select from cursor · y yank · Y visible lines · / ? search · n/N match · q exit",
|
|
2073
|
+
"Scroll mode: editor disabled · j/k cursor · h/l column · w/b/e word · 0/$ ends · ctrl+d/u half · ctrl+f/b page · gg/G ends · [ ] user msgs · enter expand · v/V select from cursor · y yank · Y visible lines · / ? search · n/N match · q exit",
|
|
1935
2074
|
)
|
|
1936
2075
|
} else {
|
|
1937
2076
|
toast(`Scroll mode: editor disabled · ctrl+u / ctrl+d scroll, ${options.toggleKey} back to edit`)
|
|
@@ -1958,6 +2097,14 @@ export default Plugin.define({
|
|
|
1958
2097
|
bind: "ctrl+d",
|
|
1959
2098
|
run: () => afterPageScroll(CMD.halfDown),
|
|
1960
2099
|
},
|
|
2100
|
+
{
|
|
2101
|
+
id: "scroll-mode.toggle.details",
|
|
2102
|
+
title: "Expand / collapse block at cursor",
|
|
2103
|
+
group: "Scroll mode",
|
|
2104
|
+
palette: true,
|
|
2105
|
+
bind: "enter",
|
|
2106
|
+
run: () => toggleAtCursor(),
|
|
2107
|
+
},
|
|
1961
2108
|
)
|
|
1962
2109
|
|
|
1963
2110
|
if (options.vim) {
|