Skip to content

Commit 3cb78d0

Browse files
author
SqlRush
committed
Fix scroll region defaults
1 parent 3cac578 commit 3cb78d0

5 files changed

Lines changed: 19 additions & 2 deletions

File tree

docs/cc-100-roadmap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ M7 补充:terminal CSI parser 现在把 TBC tab-clear (`CSI g`/`CSI 3g`) 解
124124

125125
M7 补充:terminal CSI parser 现在把 REP repeat-preceding-character (`CSI b`/`CSI 4b`) 解析成 edit action,visible-text/snapshot pipeline 和 ANSI message wrapping/trim 会按重复次数展开前一个可重复 grapheme。
126126

127+
M7 补充:terminal CSI parser 现在按 ANSI 默认参数解析 scroll-region (`CSI r`/`CSI ;10r`),缺失 top 默认为 1,缺失 bottom 保持为 0 表示 reset/full-height,避免把 reset 误判为单行区域。
128+
127129
M7 补充:terminal CSI parser 现在把 DECSTR soft reset (`CSI !p`) 解析成 reset action,terminal parser 会复用现有 reset 流程清理 SGR/link 状态,避免软复位序列落入 generic unknown。
128130

129131
M7 补充:prompt history 写入现在按官方 `history.ts` 过滤 image pasted content,不再把 image base64/filename/mediaType 写入 `history.jsonl`;历史读取仍兼容旧 image metadata。

docs/claude-code-go-rewrite-plan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ test/parity/ # golden tests against TS/official behavior
242242
- 本轮补充:terminal CSI parser 把 xterm window manipulation/report (`CSI t`) 归入 report action,覆盖常见 `CSI 14t`/`CSI 18t` 窗口/文本区尺寸查询。
243243
- 本轮补充:terminal CSI parser 把 TBC tab-clear (`CSI g`/`CSI 3g`) 归入 cursor action,保留 clear-current/all code。
244244
- 本轮补充:terminal CSI parser 把 REP repeat-preceding-character (`CSI b`) 归入 edit action,visible-text/snapshot pipeline 和 ANSI message wrapping/trim 会按重复次数展开前一个可重复 grapheme。
245+
- 本轮补充:terminal CSI parser 按 ANSI 默认参数解析 scroll-region (`CSI r`/`CSI ;10r`),缺失 top 默认为 1,缺失 bottom 保持 0 表示 reset/full-height,避免 reset scroll region 被误判为单行区域。
245246
- 本轮补充:terminal CSI parser 把 DECSTR soft reset (`CSI !p`) 归入 reset action,并在 terminal parser 中清理 SGR/link 状态。
246247
- 本轮补充:prompt history 写入按官方 `history.ts` 跳过 image pasted content,避免把 image base64/filename/mediaType 存入 `history.jsonl`,读取路径仍兼容旧 image metadata。
247248
- 本轮补充:paste-cache 增加按 cutoff mtime 清理旧 `.txt` paste 文件的 best-effort 入口,忽略缺失目录、非 `.txt` 文件和单文件错误,和官方 `cleanupOldPastes` 语义对齐。

docs/first-second-parity-audit.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ M7 progress now includes:
183183
- `internal/tui`: terminal OSC helpers now expose a lightweight `ParseOSCContent` covering title, hyperlink, tab-status, and unknown action branches.
184184
- `internal/tui`: terminal OSC helpers now parse complete BEL- or ST-terminated OSC sequences into `ParseOSCContent` actions.
185185
- `internal/tui`: terminal OSC parsing now dispatches clipboard, progress, and common notification sequences as structured actions while keeping visible-text stripping behavior intact.
186+
- `internal/tui`: terminal CSI scroll-region parsing now preserves ANSI default semantics for reset/omitted parameters instead of treating `CSI r` as a one-line region.
186187
- `internal/tui`: terminal renderer constants now include clear-scrollback and legacy Windows cursor-home helpers for official clear-terminal sequence parity without platform auto-detection.
187188
- `internal/tui`: terminal CSI helpers now generate cursor movement/position and erase sequences with official zero-move and horizontal-first cursorMove semantics.
188189
- `internal/tui`: terminal CSI helpers now generate scroll up/down and scroll-region sequences with official zero-scroll behavior.

internal/tui/terminal_csi.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func ParseCSISequence(sequence string) (CSIAction, bool) {
372372
case CSICommandScrollDown:
373373
return CSIAction{Type: CSIActionScroll, Scroll: CSIScrollAction{Type: CSIScrollActionDown, Count: p0}}, true
374374
case CSICommandScrollRegion:
375-
return CSIAction{Type: CSIActionScroll, Scroll: CSIScrollAction{Type: CSIScrollActionSetRegion, Top: p0, Bottom: p1}}, true
375+
return csiScrollRegion(params), true
376376
case CSICommandSaveCursor:
377377
return CSIAction{Type: CSIActionCursor, Cursor: CSICursorAction{Type: CSICursorActionSave}}, true
378378
case CSICommandWindowReport:
@@ -477,6 +477,18 @@ func csiWindowReport(code int, privateMode byte) CSIAction {
477477
}
478478
}
479479

480+
func csiScrollRegion(params []int) CSIAction {
481+
top := 1
482+
if len(params) > 0 && params[0] > 0 {
483+
top = params[0]
484+
}
485+
bottom := 0
486+
if len(params) > 1 && params[1] > 0 {
487+
bottom = params[1]
488+
}
489+
return CSIAction{Type: CSIActionScroll, Scroll: CSIScrollAction{Type: CSIScrollActionSetRegion, Top: top, Bottom: bottom}}
490+
}
491+
480492
func csiEraseDisplayRegion(index int) CSIEraseRegion {
481493
switch index {
482494
case 1:

internal/tui/tui_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3616,7 +3616,8 @@ func TestParseCSISequenceActions(t *testing.T) {
36163616
{seq: CSISequence(2, "S"), want: CSIScrollAction{Type: CSIScrollActionUp, Count: 2}},
36173617
{seq: CSISequence(3, "T"), want: CSIScrollAction{Type: CSIScrollActionDown, Count: 3}},
36183618
{seq: CSISequence(4, 10, "r"), want: CSIScrollAction{Type: CSIScrollActionSetRegion, Top: 4, Bottom: 10}},
3619-
{seq: ResetScrollRegion, want: CSIScrollAction{Type: CSIScrollActionSetRegion, Top: 1, Bottom: 1}},
3619+
{seq: ResetScrollRegion, want: CSIScrollAction{Type: CSIScrollActionSetRegion, Top: 1}},
3620+
{seq: CSISequence(";10r"), want: CSIScrollAction{Type: CSIScrollActionSetRegion, Top: 1, Bottom: 10}},
36203621
}
36213622
for _, tc := range scrollCases {
36223623
action, ok := ParseCSISequence(tc.seq)

0 commit comments

Comments
 (0)