You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Terminal-based diff viewer built with [Ink](https://github.com/vadimdemedes/ink). Supports Split/Unified views, syntax highlighting, and fixed-height viewport scrolling.
height={20}// viewport height in visual rows (optional)
118
+
onScrollChange={console.log}
119
+
/>
120
+
```
121
+
122
+
`CodeView` renders a single file; both components expose scroll ref methods (`scrollToTop`, `scrollDown`, `getScrollState`, etc.) when `height` is set.
@@ -26,12 +26,12 @@ A logical line may span multiple visual rows when content exceeds `contentWidth`
26
26
27
27
```typescript
28
28
typeScrollState= {
29
-
totalLines:number;// logical line count
30
-
totalRows:number;// visual row count after wrap
31
-
viewportHeight:number;// fixed height prop, or totalRows when unset
32
-
scrollOffset:number;// top visual row (0-based)
33
-
startLine:number;// first visible logical line (includes clipped lines)
34
-
endLine:number;// last visible logical line (includes clipped lines)
29
+
totalLines:number;
30
+
totalRows:number;
31
+
viewportHeight:number;
32
+
scrollOffset:number;
33
+
startLine:number;
34
+
endLine:number;
35
35
canScrollUp:boolean;
36
36
canScrollDown:boolean;
37
37
};
@@ -41,32 +41,12 @@ type ScrollState = {
41
41
42
42
---
43
43
44
-
## CodeView (done)
44
+
## CodeView
45
45
46
46
### Line semantics
47
47
48
48
-`line` = source file line number (`File.rawFile`, 1..`rawLength`).
49
-
- Layout built in `buildCodeViewLayout()` alongside existing ANSI rendering.
50
-
51
-
### Props
52
-
53
-
| Prop | Type | Description |
54
-
|------|------|-------------|
55
-
|`height`|`number`| Viewport height in visual rows |
56
-
|`onScrollChange`|`(state: ScrollState) => void`| Fires when scroll state changes |
57
-
58
-
### Ref (`CodeViewRef`)
59
-
60
-
Extends `ScrollViewRef`:
61
-
62
-
| Method | Description |
63
-
|--------|-------------|
64
-
|`getScrollState()`| Current snapshot |
65
-
|`scrollToTop(line)`| Align logical line's first visual row to viewport top |
66
-
|`scrollToBottom(line)`| Align logical line's last visual row to viewport bottom |
67
-
|`scrollUp({ unit?, step? })`| Scroll up one visual or logical step |
68
-
|`scrollDown({ unit?, step? })`| Scroll down one visual or logical step |
69
-
|`getFileInstance()`| Existing API |
49
+
- Layout built in `buildCodeViewLayout()` alongside ANSI rendering.
70
50
71
51
### Rendering
72
52
@@ -76,96 +56,71 @@ When `height` is set:
76
56
2.`useScrollView` maintains `scrollOffset` and slices `layout.rows`.
77
57
3. Render sliced ANSI string in `<Box height={height} overflow="hidden">`.
78
58
79
-
When `height` is unset, all rows render (backward compatible). DiffView skips `buildDiffViewScrollLayout` entirely in that case (uses `EMPTY_SCROLL_LAYOUT`); only the original full render path runs.
80
-
81
-
### Width / layout changes
82
-
83
-
When render width (`columns`) changes, wrap counts change and row indices no longer match the previous layout. Both CodeView and DiffView pass a `resetKey` into `useScrollView` so **scroll offset resets to 0** on width change. DiffView also includes `mode` in the reset key (split ↔ unified).
59
+
When `height` is unset, all rows render.
84
60
85
61
---
86
62
87
-
## DiffView (TODO)
88
-
89
-
### Line semantics (方案 1 — confirmed)
90
-
91
-
`line` = **1-based index in the flattened display sequence**, including:
0 commit comments