@tooee/renderers 0.2.4 → 0.3.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/dist/code-blocks.d.ts +6 -6
- package/dist/code-blocks.d.ts.map +1 -1
- package/dist/code-blocks.js +52 -42
- package/dist/code-blocks.js.map +1 -1
- package/dist/{CodeView.d.ts → code-view.d.ts} +3 -3
- package/dist/code-view.d.ts.map +1 -0
- package/dist/{CodeView.js → code-view.js} +5 -5
- package/dist/code-view.js.map +1 -0
- package/dist/{CommandPalette.d.ts → command-palette.d.ts} +2 -2
- package/dist/command-palette.d.ts.map +1 -0
- package/dist/{CommandPalette.js → command-palette.js} +27 -24
- package/dist/command-palette.js.map +1 -0
- package/dist/{ContextMenu.d.ts → context-menu.d.ts} +2 -2
- package/dist/context-menu.d.ts.map +1 -0
- package/dist/{ContextMenu.js → context-menu.js} +24 -14
- package/dist/context-menu.js.map +1 -0
- package/dist/{DecorationLayer.d.ts → decoration-layer.d.ts} +2 -2
- package/dist/decoration-layer.d.ts.map +1 -0
- package/dist/decoration-layer.js +2 -0
- package/dist/decoration-layer.js.map +1 -0
- package/dist/{DocumentBindings.d.ts → document-bindings.d.ts} +4 -4
- package/dist/document-bindings.d.ts.map +1 -0
- package/dist/document-bindings.js +2 -0
- package/dist/document-bindings.js.map +1 -0
- package/dist/index.d.ts +16 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/markdown-blocks.d.ts +9 -13
- package/dist/markdown-blocks.d.ts.map +1 -1
- package/dist/markdown-blocks.js +98 -79
- package/dist/markdown-blocks.js.map +1 -1
- package/dist/{MarkdownView.d.ts → markdown-view.d.ts} +13 -13
- package/dist/markdown-view.d.ts.map +1 -0
- package/dist/markdown-view.js +455 -0
- package/dist/markdown-view.js.map +1 -0
- package/dist/mermaid.d.ts +5 -5
- package/dist/mermaid.d.ts.map +1 -1
- package/dist/mermaid.js +33 -25
- package/dist/mermaid.js.map +1 -1
- package/dist/parsers.d.ts +5 -5
- package/dist/parsers.d.ts.map +1 -1
- package/dist/parsers.js +64 -44
- package/dist/parsers.js.map +1 -1
- package/dist/{RowDocumentRenderable.d.ts → row-document-renderable.d.ts} +15 -11
- package/dist/row-document-renderable.d.ts.map +1 -0
- package/dist/{RowDocumentRenderable.js → row-document-renderable.js} +110 -62
- package/dist/row-document-renderable.js.map +1 -0
- package/dist/row-document.d.ts +1 -1
- package/dist/row-document.d.ts.map +1 -1
- package/dist/row-document.js +1 -1
- package/dist/row-document.js.map +1 -1
- package/dist/source.d.ts +6 -6
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +35 -26
- package/dist/source.js.map +1 -1
- package/dist/table-types.d.ts.map +1 -1
- package/dist/{Table.d.ts → table.d.ts} +6 -6
- package/dist/table.d.ts.map +1 -0
- package/dist/{Table.js → table.js} +65 -35
- package/dist/table.js.map +1 -0
- package/dist/text-table.d.ts.map +1 -1
- package/dist/text-table.js.map +1 -1
- package/dist/use-gutter-palette.d.ts +3 -0
- package/dist/use-gutter-palette.d.ts.map +1 -0
- package/dist/{useGutterPalette.js → use-gutter-palette.js} +4 -4
- package/dist/use-gutter-palette.js.map +1 -0
- package/package.json +5 -5
- package/src/code-blocks.tsx +122 -106
- package/src/{CodeView.tsx → code-view.tsx} +19 -14
- package/src/command-palette.tsx +163 -0
- package/src/context-menu.tsx +157 -0
- package/src/decoration-layer.ts +11 -0
- package/src/document-bindings.ts +16 -0
- package/src/index.ts +24 -23
- package/src/markdown-blocks.ts +178 -138
- package/src/markdown-view.tsx +853 -0
- package/src/mermaid.ts +94 -71
- package/src/parsers.ts +141 -103
- package/src/row-document-renderable.ts +672 -0
- package/src/row-document.ts +4 -4
- package/src/source.ts +92 -72
- package/src/table-types.ts +4 -4
- package/src/table.tsx +346 -0
- package/src/text-table.ts +4 -4
- package/src/use-gutter-palette.ts +15 -0
- package/dist/CodeView.d.ts.map +0 -1
- package/dist/CodeView.js.map +0 -1
- package/dist/CommandPalette.d.ts.map +0 -1
- package/dist/CommandPalette.js.map +0 -1
- package/dist/ContextMenu.d.ts.map +0 -1
- package/dist/ContextMenu.js.map +0 -1
- package/dist/DecorationLayer.d.ts.map +0 -1
- package/dist/DecorationLayer.js +0 -2
- package/dist/DecorationLayer.js.map +0 -1
- package/dist/DocumentBindings.d.ts.map +0 -1
- package/dist/DocumentBindings.js +0 -2
- package/dist/DocumentBindings.js.map +0 -1
- package/dist/MarkdownView.d.ts.map +0 -1
- package/dist/MarkdownView.js +0 -360
- package/dist/MarkdownView.js.map +0 -1
- package/dist/RowDocumentRenderable.d.ts.map +0 -1
- package/dist/RowDocumentRenderable.js.map +0 -1
- package/dist/Table.d.ts.map +0 -1
- package/dist/Table.js.map +0 -1
- package/dist/useGutterPalette.d.ts +0 -3
- package/dist/useGutterPalette.d.ts.map +0 -1
- package/dist/useGutterPalette.js.map +0 -1
- package/src/CommandPalette.tsx +0 -147
- package/src/ContextMenu.tsx +0 -132
- package/src/DecorationLayer.ts +0 -11
- package/src/DocumentBindings.ts +0 -16
- package/src/MarkdownView.tsx +0 -738
- package/src/RowDocumentRenderable.ts +0 -593
- package/src/Table.tsx +0 -300
- package/src/useGutterPalette.ts +0 -15
|
@@ -1,593 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type RenderContext,
|
|
3
|
-
type LineInfoProvider,
|
|
4
|
-
ScrollBoxRenderable,
|
|
5
|
-
type ScrollBoxOptions,
|
|
6
|
-
RGBA,
|
|
7
|
-
} from "@opentui/core"
|
|
8
|
-
import type { OptimizedBuffer } from "@opentui/core"
|
|
9
|
-
import type { DecorationLayer, RowDecoration } from "./DecorationLayer.js"
|
|
10
|
-
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
// Types
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
|
|
15
|
-
export const DEFAULT_SIGN_COLUMN_WIDTH = 3
|
|
16
|
-
|
|
17
|
-
export interface RowDocumentPalette {
|
|
18
|
-
gutterFg?: string
|
|
19
|
-
gutterBg?: string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface RowDocumentOptions extends ScrollBoxOptions {
|
|
23
|
-
mode?: "auto" | "multi" | "provider"
|
|
24
|
-
|
|
25
|
-
// Gutter
|
|
26
|
-
showGutter?: boolean
|
|
27
|
-
showLineNumbers?: boolean
|
|
28
|
-
lineNumberStart?: number
|
|
29
|
-
signColumnWidth?: number
|
|
30
|
-
gutterPaddingRight?: number
|
|
31
|
-
|
|
32
|
-
// Multi-child: skip N leading children that aren't logical rows
|
|
33
|
-
rowChildOffset?: number
|
|
34
|
-
|
|
35
|
-
// Colors
|
|
36
|
-
palette?: RowDocumentPalette
|
|
37
|
-
decorations?: readonly DecorationLayer[]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// ---------------------------------------------------------------------------
|
|
41
|
-
// Provider detection
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
|
|
44
|
-
function isRowContentProvider(x: unknown): x is LineInfoProvider {
|
|
45
|
-
return (
|
|
46
|
-
!!x && typeof x === "object" && "lineInfo" in x && "lineCount" in x && "virtualLineCount" in x
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ---------------------------------------------------------------------------
|
|
51
|
-
// Color cache — avoids re-parsing hex strings every frame
|
|
52
|
-
// ---------------------------------------------------------------------------
|
|
53
|
-
|
|
54
|
-
const colorCache = new Map<string, RGBA>()
|
|
55
|
-
|
|
56
|
-
function cachedColor(hex: string): RGBA {
|
|
57
|
-
let c = colorCache.get(hex)
|
|
58
|
-
if (!c) {
|
|
59
|
-
c = RGBA.fromHex(hex)
|
|
60
|
-
colorCache.set(hex, c)
|
|
61
|
-
}
|
|
62
|
-
return c
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function normalizePalette(palette: RowDocumentPalette = {}): Required<RowDocumentPalette> {
|
|
66
|
-
return {
|
|
67
|
-
gutterFg: palette.gutterFg ?? "#6e7681",
|
|
68
|
-
gutterBg: palette.gutterBg ?? "#0d1117",
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function normalizeDecorationLayers(
|
|
73
|
-
layers: readonly DecorationLayer[] | undefined,
|
|
74
|
-
): readonly DecorationLayer[] {
|
|
75
|
-
if (!layers || layers.length === 0) return []
|
|
76
|
-
return [...layers].sort((a, b) => a.priority - b.priority)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function computeRowDocumentGutterWidth(opts: {
|
|
80
|
-
showLineNumbers: boolean
|
|
81
|
-
rowCount: number
|
|
82
|
-
lineNumberStart?: number
|
|
83
|
-
signColumnWidth?: number
|
|
84
|
-
gutterPaddingRight?: number
|
|
85
|
-
}): number {
|
|
86
|
-
let width = 0
|
|
87
|
-
if (opts.showLineNumbers) {
|
|
88
|
-
const maxLineNum = (opts.lineNumberStart ?? 1) + opts.rowCount - 1
|
|
89
|
-
width += Math.max(String(maxLineNum).length, 1)
|
|
90
|
-
}
|
|
91
|
-
width += opts.signColumnWidth ?? 0
|
|
92
|
-
width += opts.gutterPaddingRight ?? 1
|
|
93
|
-
return width
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// ---------------------------------------------------------------------------
|
|
97
|
-
// RowDocumentRenderable
|
|
98
|
-
// ---------------------------------------------------------------------------
|
|
99
|
-
|
|
100
|
-
export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
101
|
-
// -- Options --
|
|
102
|
-
private _mode: "auto" | "multi" | "provider"
|
|
103
|
-
private _showGutter: boolean
|
|
104
|
-
private _showLineNumbers: boolean
|
|
105
|
-
private _lineNumberStart: number
|
|
106
|
-
private _signColumnWidth: number
|
|
107
|
-
private _gutterPaddingRight: number
|
|
108
|
-
private _rowChildOffset: number
|
|
109
|
-
private _palette: Required<RowDocumentPalette>
|
|
110
|
-
private _layers: readonly DecorationLayer[] = []
|
|
111
|
-
private _layerGutterBgs = new Map<number, string>()
|
|
112
|
-
private _layerSigns = new Map<number, NonNullable<RowDecoration["sign"]>>()
|
|
113
|
-
|
|
114
|
-
// -- Geometry arrays --
|
|
115
|
-
private _rowVirtualStarts: number[] = []
|
|
116
|
-
private _rowVirtualHeights: number[] = []
|
|
117
|
-
private _virtualRowToRow: number[] = []
|
|
118
|
-
private _virtualRowWraps: number[] = []
|
|
119
|
-
private _rowCount = 0
|
|
120
|
-
/** Virtual Y one past the last content row; the rest of the scroll area is empty. */
|
|
121
|
-
private _contentVirtualEnd = 0
|
|
122
|
-
private _lastGeometryHash = ""
|
|
123
|
-
|
|
124
|
-
constructor(ctx: RenderContext, options: RowDocumentOptions) {
|
|
125
|
-
super(ctx, options)
|
|
126
|
-
|
|
127
|
-
this._mode = options.mode ?? "auto"
|
|
128
|
-
this._showGutter = options.showGutter ?? true
|
|
129
|
-
this._showLineNumbers = options.showLineNumbers ?? true
|
|
130
|
-
this._lineNumberStart = options.lineNumberStart ?? 1
|
|
131
|
-
this._signColumnWidth = options.signColumnWidth ?? 0
|
|
132
|
-
this._gutterPaddingRight = options.gutterPaddingRight ?? 1
|
|
133
|
-
this._rowChildOffset = options.rowChildOffset ?? 0
|
|
134
|
-
|
|
135
|
-
this._palette = normalizePalette(options.palette)
|
|
136
|
-
this._layers = normalizeDecorationLayers(options.decorations)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// -----------------------------------------------------------------------
|
|
140
|
-
// Decorations
|
|
141
|
-
// -----------------------------------------------------------------------
|
|
142
|
-
|
|
143
|
-
set decorations(layers: readonly DecorationLayer[] | undefined) {
|
|
144
|
-
this._layers = normalizeDecorationLayers(layers)
|
|
145
|
-
this.requestRender()
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
set palette(palette: RowDocumentPalette | undefined) {
|
|
149
|
-
this._palette = normalizePalette(palette)
|
|
150
|
-
this.requestRender()
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// -----------------------------------------------------------------------
|
|
154
|
-
// Gutter config setters
|
|
155
|
-
// -----------------------------------------------------------------------
|
|
156
|
-
|
|
157
|
-
set showGutter(value: boolean) {
|
|
158
|
-
if (this._showGutter !== value) {
|
|
159
|
-
this._showGutter = value
|
|
160
|
-
this._applyGutterPadding()
|
|
161
|
-
this.requestRender()
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
set showLineNumbers(value: boolean) {
|
|
166
|
-
if (this._showLineNumbers !== value) {
|
|
167
|
-
this._showLineNumbers = value
|
|
168
|
-
this._applyGutterPadding()
|
|
169
|
-
this.requestRender()
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// -----------------------------------------------------------------------
|
|
174
|
-
// Geometry — public API
|
|
175
|
-
// -----------------------------------------------------------------------
|
|
176
|
-
|
|
177
|
-
get rowCount(): number {
|
|
178
|
-
return this._rowCount
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
get virtualRowCount(): number {
|
|
182
|
-
return this._virtualRowToRow.length
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
getRowMetrics(row: number): { row: number; virtualTop: number; virtualHeight: number } | null {
|
|
186
|
-
if (row < 0 || row >= this._rowCount) return null
|
|
187
|
-
return {
|
|
188
|
-
row,
|
|
189
|
-
virtualTop: this._rowVirtualStarts[row],
|
|
190
|
-
virtualHeight: this._rowVirtualHeights[row],
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
getRowAtVirtualY(y: number): number {
|
|
195
|
-
const clamped = Math.max(0, Math.min(y, this._virtualRowToRow.length - 1))
|
|
196
|
-
const row = this._virtualRowToRow[clamped]
|
|
197
|
-
if (row != null && row >= 0) return row
|
|
198
|
-
// Gap row — search backward for nearest valid row
|
|
199
|
-
for (let i = clamped - 1; i >= 0; i--) {
|
|
200
|
-
const r = this._virtualRowToRow[i]
|
|
201
|
-
if (r != null && r >= 0) return r
|
|
202
|
-
}
|
|
203
|
-
return 0
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Map an absolute terminal Y coordinate (as delivered on a `MouseEvent`) to a
|
|
208
|
-
* logical row index. Returns `null` when the Y is above/below the scroll
|
|
209
|
-
* viewport or past the last rendered content row, so callers can ignore clicks
|
|
210
|
-
* that land on empty space. Clicks that land in an inter-row margin gap resolve
|
|
211
|
-
* to the nearest row above (via `getRowAtVirtualY`).
|
|
212
|
-
*
|
|
213
|
-
* Works for both multi-child mode (row = child index, e.g. a markdown block)
|
|
214
|
-
* and provider mode (row = source line, e.g. a code line): geometry is
|
|
215
|
-
* recomputed every frame in `renderSelf`, so `_virtualRowToRow` is current by
|
|
216
|
-
* the time a click is processed.
|
|
217
|
-
*/
|
|
218
|
-
getRowAtScreenY(screenY: number): number | null {
|
|
219
|
-
const localY = screenY - this.viewport.y
|
|
220
|
-
if (localY < 0 || localY >= this.viewport.height) return null
|
|
221
|
-
const virtualY = Math.floor(this.scrollTop) + localY
|
|
222
|
-
if (virtualY < 0 || virtualY >= this._virtualRowToRow.length) return null
|
|
223
|
-
if (virtualY >= this._contentVirtualEnd) return null
|
|
224
|
-
return this.getRowAtVirtualY(virtualY)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
getVisibleRange(): {
|
|
228
|
-
virtualTop: number
|
|
229
|
-
virtualBottom: number
|
|
230
|
-
firstRow: number
|
|
231
|
-
lastRow: number
|
|
232
|
-
} {
|
|
233
|
-
const top = Math.floor(this.scrollTop)
|
|
234
|
-
const bottom = top + this.viewport.height
|
|
235
|
-
return {
|
|
236
|
-
virtualTop: top,
|
|
237
|
-
virtualBottom: bottom,
|
|
238
|
-
firstRow: this.getRowAtVirtualY(top),
|
|
239
|
-
lastRow: this.getRowAtVirtualY(bottom - 1),
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// -----------------------------------------------------------------------
|
|
244
|
-
// scrollToRow
|
|
245
|
-
// -----------------------------------------------------------------------
|
|
246
|
-
|
|
247
|
-
scrollToRow(row: number, align: "nearest" | "start" | "center" | "end" = "nearest"): void {
|
|
248
|
-
const metrics = this.getRowMetrics(row)
|
|
249
|
-
if (!metrics) return
|
|
250
|
-
|
|
251
|
-
const vpHeight = this.viewport.height
|
|
252
|
-
const { virtualTop, virtualHeight } = metrics
|
|
253
|
-
|
|
254
|
-
let target = this.scrollTop
|
|
255
|
-
|
|
256
|
-
switch (align) {
|
|
257
|
-
case "start":
|
|
258
|
-
target = virtualTop
|
|
259
|
-
break
|
|
260
|
-
case "center":
|
|
261
|
-
target = virtualTop - (vpHeight - virtualHeight) / 2
|
|
262
|
-
break
|
|
263
|
-
case "end":
|
|
264
|
-
target = virtualTop + virtualHeight - vpHeight
|
|
265
|
-
break
|
|
266
|
-
case "nearest": {
|
|
267
|
-
if (virtualTop < this.scrollTop) {
|
|
268
|
-
target = virtualTop
|
|
269
|
-
} else if (virtualTop + virtualHeight > this.scrollTop + vpHeight) {
|
|
270
|
-
target = virtualTop + virtualHeight - vpHeight
|
|
271
|
-
}
|
|
272
|
-
break
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// When scrolling to the first row, include header content (pre-offset children)
|
|
277
|
-
if (row === 0 && this._rowChildOffset > 0) {
|
|
278
|
-
target = Math.min(target, 0)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// When the next row is the last logical row (e.g. bottom border),
|
|
282
|
-
// extend the scroll to include it
|
|
283
|
-
if (row + 1 === this._rowCount - 1) {
|
|
284
|
-
const next = this.getRowMetrics(row + 1)
|
|
285
|
-
if (next) {
|
|
286
|
-
const bottomEdge = next.virtualTop + next.virtualHeight
|
|
287
|
-
if (bottomEdge > target + vpHeight) {
|
|
288
|
-
target = bottomEdge - vpHeight
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
this.scrollTop = Math.max(0, Math.round(target))
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// -----------------------------------------------------------------------
|
|
297
|
-
// Rendering
|
|
298
|
-
// -----------------------------------------------------------------------
|
|
299
|
-
|
|
300
|
-
protected renderSelf(buffer: OptimizedBuffer): void {
|
|
301
|
-
// Let ScrollBox do its own rendering first
|
|
302
|
-
super.renderSelf(buffer)
|
|
303
|
-
|
|
304
|
-
// Recompute geometry every frame (cheap — just iterating children)
|
|
305
|
-
this._computeGeometry()
|
|
306
|
-
|
|
307
|
-
// Apply gutter padding to content area
|
|
308
|
-
this._applyGutterPadding()
|
|
309
|
-
|
|
310
|
-
// Paint decorations and gutter on top
|
|
311
|
-
this._paintDecorations(buffer)
|
|
312
|
-
if (this._showGutter) {
|
|
313
|
-
this._paintGutter(buffer)
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// -----------------------------------------------------------------------
|
|
318
|
-
// Geometry computation
|
|
319
|
-
// -----------------------------------------------------------------------
|
|
320
|
-
|
|
321
|
-
private _detectMode(): "multi" | "provider" {
|
|
322
|
-
if (this._mode === "multi") return "multi"
|
|
323
|
-
if (this._mode === "provider") return "provider"
|
|
324
|
-
|
|
325
|
-
// Auto-detect: single child with LineInfoProvider → provider mode
|
|
326
|
-
const children = this.getChildren()
|
|
327
|
-
if (children.length === 1 && isRowContentProvider(children[0])) {
|
|
328
|
-
return "provider"
|
|
329
|
-
}
|
|
330
|
-
return "multi"
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
private _computeGeometry(): void {
|
|
334
|
-
const mode = this._detectMode()
|
|
335
|
-
if (mode === "provider") {
|
|
336
|
-
this._computeFromProvider()
|
|
337
|
-
} else {
|
|
338
|
-
this._computeFromChildren()
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
private _computeFromChildren(): void {
|
|
343
|
-
const children = this.getChildren()
|
|
344
|
-
const offset = this._rowChildOffset
|
|
345
|
-
const contentY = this.content.y
|
|
346
|
-
const totalHeight = this.scrollHeight
|
|
347
|
-
|
|
348
|
-
if (totalHeight === 0 || children.length <= offset) {
|
|
349
|
-
this._finishGeometry([], [], [], [], 0)
|
|
350
|
-
return
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const rowCount = children.length - offset
|
|
354
|
-
const rowVirtualStarts: number[] = []
|
|
355
|
-
const rowVirtualHeights: number[] = []
|
|
356
|
-
const virtualRowToRow = Array.from({ length: totalHeight }, () => -1)
|
|
357
|
-
const virtualRowWraps = Array.from({ length: totalHeight }, () => 0)
|
|
358
|
-
|
|
359
|
-
for (let i = offset; i < children.length; i++) {
|
|
360
|
-
const row = i - offset
|
|
361
|
-
const child = children[i]
|
|
362
|
-
const childStart = child.y - contentY
|
|
363
|
-
const h = Math.max(1, child.height)
|
|
364
|
-
|
|
365
|
-
rowVirtualStarts[row] = childStart
|
|
366
|
-
rowVirtualHeights[row] = h
|
|
367
|
-
|
|
368
|
-
for (let r = 0; r < h; r++) {
|
|
369
|
-
const vRow = childStart + r
|
|
370
|
-
if (vRow >= 0 && vRow < totalHeight) {
|
|
371
|
-
virtualRowToRow[vRow] = row
|
|
372
|
-
virtualRowWraps[vRow] = r === 0 ? 0 : 1
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
this._finishGeometry(
|
|
378
|
-
rowVirtualStarts,
|
|
379
|
-
rowVirtualHeights,
|
|
380
|
-
virtualRowToRow,
|
|
381
|
-
virtualRowWraps,
|
|
382
|
-
rowCount,
|
|
383
|
-
)
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
private _computeFromProvider(): void {
|
|
387
|
-
const children = this.getChildren()
|
|
388
|
-
if (children.length === 0) return
|
|
389
|
-
|
|
390
|
-
const provider = children[0] as unknown as LineInfoProvider
|
|
391
|
-
if (!isRowContentProvider(provider)) return
|
|
392
|
-
|
|
393
|
-
const info = provider.lineInfo
|
|
394
|
-
const { lineSources, lineWraps } = info
|
|
395
|
-
|
|
396
|
-
const rowVirtualStarts: number[] = []
|
|
397
|
-
const rowVirtualHeights: number[] = []
|
|
398
|
-
const virtualRowToRow: number[] = []
|
|
399
|
-
const virtualRowWraps: number[] = []
|
|
400
|
-
|
|
401
|
-
let currentRow = -1
|
|
402
|
-
let rowCount = 0
|
|
403
|
-
|
|
404
|
-
for (let v = 0; v < lineSources.length; v++) {
|
|
405
|
-
const row = lineSources[v]
|
|
406
|
-
virtualRowToRow[v] = row
|
|
407
|
-
virtualRowWraps[v] = lineWraps[v]
|
|
408
|
-
|
|
409
|
-
if (row !== currentRow) {
|
|
410
|
-
// New logical row
|
|
411
|
-
if (currentRow >= 0) {
|
|
412
|
-
rowVirtualHeights[currentRow] = v - rowVirtualStarts[currentRow]
|
|
413
|
-
}
|
|
414
|
-
rowVirtualStarts[row] = v
|
|
415
|
-
currentRow = row
|
|
416
|
-
rowCount = Math.max(rowCount, row + 1)
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// Finalize last row
|
|
421
|
-
if (currentRow >= 0) {
|
|
422
|
-
rowVirtualHeights[currentRow] = lineSources.length - rowVirtualStarts[currentRow]
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
this._finishGeometry(
|
|
426
|
-
rowVirtualStarts,
|
|
427
|
-
rowVirtualHeights,
|
|
428
|
-
virtualRowToRow,
|
|
429
|
-
virtualRowWraps,
|
|
430
|
-
rowCount,
|
|
431
|
-
)
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
private _finishGeometry(
|
|
435
|
-
rowVirtualStarts: number[],
|
|
436
|
-
rowVirtualHeights: number[],
|
|
437
|
-
virtualRowToRow: number[],
|
|
438
|
-
virtualRowWraps: number[],
|
|
439
|
-
rowCount: number,
|
|
440
|
-
): void {
|
|
441
|
-
let contentVirtualEnd = 0
|
|
442
|
-
for (let row = 0; row < rowCount; row++) {
|
|
443
|
-
const end = rowVirtualStarts[row] + rowVirtualHeights[row]
|
|
444
|
-
if (end > contentVirtualEnd) contentVirtualEnd = end
|
|
445
|
-
}
|
|
446
|
-
this._contentVirtualEnd = contentVirtualEnd
|
|
447
|
-
|
|
448
|
-
// Change detection via hash
|
|
449
|
-
const hash = rowVirtualStarts.join(",")
|
|
450
|
-
if (hash !== this._lastGeometryHash) {
|
|
451
|
-
this._rowVirtualStarts = rowVirtualStarts
|
|
452
|
-
this._rowVirtualHeights = rowVirtualHeights
|
|
453
|
-
this._virtualRowToRow = virtualRowToRow
|
|
454
|
-
this._virtualRowWraps = virtualRowWraps
|
|
455
|
-
this._rowCount = rowCount
|
|
456
|
-
this._lastGeometryHash = hash
|
|
457
|
-
this.emit("row-geometry-change")
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// -----------------------------------------------------------------------
|
|
462
|
-
// Gutter width calculation and padding
|
|
463
|
-
// -----------------------------------------------------------------------
|
|
464
|
-
|
|
465
|
-
private _computeGutterWidth(): number {
|
|
466
|
-
if (!this._showGutter) return 0
|
|
467
|
-
|
|
468
|
-
return computeRowDocumentGutterWidth({
|
|
469
|
-
showLineNumbers: this._showLineNumbers,
|
|
470
|
-
rowCount: this._rowCount,
|
|
471
|
-
lineNumberStart: this._lineNumberStart,
|
|
472
|
-
signColumnWidth: this._signColumnWidth,
|
|
473
|
-
gutterPaddingRight: this._gutterPaddingRight,
|
|
474
|
-
})
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
private _applyGutterPadding(): void {
|
|
478
|
-
const gutterWidth = this._computeGutterWidth()
|
|
479
|
-
this.content.paddingLeft = gutterWidth
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
// -----------------------------------------------------------------------
|
|
483
|
-
// Decoration painting (row backgrounds)
|
|
484
|
-
// -----------------------------------------------------------------------
|
|
485
|
-
|
|
486
|
-
private _paintDecorations(buffer: OptimizedBuffer): void {
|
|
487
|
-
this._layerGutterBgs = new Map()
|
|
488
|
-
this._layerSigns = new Map()
|
|
489
|
-
|
|
490
|
-
if (this._layers.length === 0) return
|
|
491
|
-
|
|
492
|
-
const vpX = this.viewport.x
|
|
493
|
-
const vpY = this.viewport.y
|
|
494
|
-
const vpHeight = this.viewport.height
|
|
495
|
-
const vpWidth = this.viewport.width
|
|
496
|
-
const top = Math.floor(this.scrollTop)
|
|
497
|
-
|
|
498
|
-
const { firstRow, lastRow } = this.getVisibleRange()
|
|
499
|
-
const rowBgs = new Map<number, string>()
|
|
500
|
-
const rowGutterBgs = new Map<number, string>()
|
|
501
|
-
const rowSigns = new Map<number, NonNullable<RowDecoration["sign"]>>()
|
|
502
|
-
|
|
503
|
-
for (const layer of this._layers) {
|
|
504
|
-
for (const deco of layer.forVisibleRows(firstRow, lastRow)) {
|
|
505
|
-
if (deco.background) rowBgs.set(deco.row, deco.background)
|
|
506
|
-
if (deco.gutterBackground) rowGutterBgs.set(deco.row, deco.gutterBackground)
|
|
507
|
-
if (deco.sign) rowSigns.set(deco.row, deco.sign)
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
for (let screenY = 0; screenY < vpHeight; screenY++) {
|
|
512
|
-
const vRow = top + screenY
|
|
513
|
-
if (vRow >= this._virtualRowToRow.length) break
|
|
514
|
-
|
|
515
|
-
const row = this._virtualRowToRow[vRow]
|
|
516
|
-
if (row < 0) continue // Skip gap rows (margins)
|
|
517
|
-
const bg = rowBgs.get(row)
|
|
518
|
-
if (!bg) continue
|
|
519
|
-
buffer.fillRect(vpX, vpY + screenY, vpWidth, 1, cachedColor(bg))
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
this._layerGutterBgs = rowGutterBgs
|
|
523
|
-
this._layerSigns = rowSigns
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
// -----------------------------------------------------------------------
|
|
527
|
-
// Gutter painting
|
|
528
|
-
// -----------------------------------------------------------------------
|
|
529
|
-
|
|
530
|
-
private _paintGutter(buffer: OptimizedBuffer): void {
|
|
531
|
-
const gutterWidth = this._computeGutterWidth()
|
|
532
|
-
if (gutterWidth === 0) return
|
|
533
|
-
|
|
534
|
-
const vpX = this.viewport.x
|
|
535
|
-
const vpY = this.viewport.y
|
|
536
|
-
const vpHeight = this.viewport.height
|
|
537
|
-
const top = Math.floor(this.scrollTop)
|
|
538
|
-
|
|
539
|
-
const gutterBg = cachedColor(this._palette.gutterBg)
|
|
540
|
-
const gutterFg = cachedColor(this._palette.gutterFg)
|
|
541
|
-
|
|
542
|
-
// Fill gutter background
|
|
543
|
-
buffer.fillRect(vpX, vpY, gutterWidth, vpHeight, gutterBg)
|
|
544
|
-
|
|
545
|
-
const lineNumWidth = this._showLineNumbers
|
|
546
|
-
? Math.max(String(this._lineNumberStart + this._rowCount - 1).length, 1)
|
|
547
|
-
: 0
|
|
548
|
-
|
|
549
|
-
for (let screenY = 0; screenY < vpHeight; screenY++) {
|
|
550
|
-
const vRow = top + screenY
|
|
551
|
-
if (vRow >= this._virtualRowToRow.length) break
|
|
552
|
-
|
|
553
|
-
const row = this._virtualRowToRow[vRow]
|
|
554
|
-
if (row < 0) continue // Skip gap rows (margins)
|
|
555
|
-
const isFirstLine = this._virtualRowWraps[vRow] === 0
|
|
556
|
-
|
|
557
|
-
if (!isFirstLine) continue
|
|
558
|
-
|
|
559
|
-
const drawX = vpX
|
|
560
|
-
let col = 0
|
|
561
|
-
|
|
562
|
-
const rowGutterHex = this._layerGutterBgs.get(row)
|
|
563
|
-
const effectiveGutterBg = rowGutterHex ? cachedColor(rowGutterHex) : gutterBg
|
|
564
|
-
if (rowGutterHex) {
|
|
565
|
-
buffer.fillRect(drawX, vpY + screenY, gutterWidth, 1, effectiveGutterBg)
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
// Line number
|
|
569
|
-
if (this._showLineNumbers) {
|
|
570
|
-
const lineNum = String(this._lineNumberStart + row)
|
|
571
|
-
const padded = lineNum.padStart(lineNumWidth, " ")
|
|
572
|
-
buffer.drawText(padded, drawX + col, vpY + screenY, gutterFg, effectiveGutterBg)
|
|
573
|
-
col += lineNumWidth
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// Sign column
|
|
577
|
-
if (this._signColumnWidth > 0) {
|
|
578
|
-
const sign = this._layerSigns.get(row)
|
|
579
|
-
|
|
580
|
-
if (sign) {
|
|
581
|
-
const signFg = sign.fg ? cachedColor(sign.fg) : gutterFg
|
|
582
|
-
buffer.drawText(
|
|
583
|
-
sign.text.slice(0, this._signColumnWidth),
|
|
584
|
-
drawX + col,
|
|
585
|
-
vpY + screenY,
|
|
586
|
-
signFg,
|
|
587
|
-
effectiveGutterBg,
|
|
588
|
-
)
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|