@tooee/renderers 0.12.0 → 0.13.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/chooser/choose-filter.d.ts.map +1 -1
- package/dist/chooser/choose-filter.js.map +1 -1
- package/dist/chooser/choose-highlighted-text.d.ts.map +1 -1
- package/dist/chooser/choose-highlighted-text.js.map +1 -1
- package/dist/chooser/choose-list.d.ts.map +1 -1
- package/dist/chooser/choose-list.js.map +1 -1
- package/dist/chooser/choose-store.d.ts +3 -3
- package/dist/chooser/choose-store.d.ts.map +1 -1
- package/dist/chooser/choose-store.js.map +1 -1
- package/dist/chooser/chooser.d.ts.map +1 -1
- package/dist/chooser/chooser.js.map +1 -1
- package/dist/chooser/source.d.ts.map +1 -1
- package/dist/chooser/source.js.map +1 -1
- package/dist/chooser/use-choose.d.ts.map +1 -1
- package/dist/chooser/use-choose.js.map +1 -1
- package/dist/code-blocks.d.ts.map +1 -1
- package/dist/code-blocks.js.map +1 -1
- package/dist/command-palette.d.ts.map +1 -1
- package/dist/command-palette.js.map +1 -1
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/markdown/blocks/blockquote.d.ts.map +1 -1
- package/dist/markdown/blocks/blockquote.js.map +1 -1
- package/dist/markdown/blocks/flat-block.d.ts.map +1 -1
- package/dist/markdown/blocks/flat-block.js.map +1 -1
- package/dist/markdown/blocks/heading.d.ts.map +1 -1
- package/dist/markdown/blocks/heading.js.map +1 -1
- package/dist/markdown/blocks/list-line.d.ts.map +1 -1
- package/dist/markdown/blocks/list-line.js.map +1 -1
- package/dist/markdown/blocks/paragraph.d.ts.map +1 -1
- package/dist/markdown/blocks/paragraph.js.map +1 -1
- package/dist/markdown/blocks/table.d.ts.map +1 -1
- package/dist/markdown/blocks/table.js.map +1 -1
- package/dist/markdown/links.d.ts.map +1 -1
- package/dist/markdown/links.js.map +1 -1
- package/dist/markdown/plain-text.d.ts.map +1 -1
- package/dist/markdown/plain-text.js.map +1 -1
- package/dist/markdown/table-links.d.ts.map +1 -1
- package/dist/markdown/table-links.js.map +1 -1
- package/dist/markdown/tokens.d.ts.map +1 -1
- package/dist/markdown/tokens.js.map +1 -1
- package/dist/markdown/visit-inline.d.ts.map +1 -1
- package/dist/markdown/visit-inline.js.map +1 -1
- package/dist/markdown-blocks.d.ts.map +1 -1
- package/dist/markdown-blocks.js.map +1 -1
- package/dist/markdown-images.d.ts.map +1 -1
- package/dist/markdown-images.js.map +1 -1
- package/dist/markdown-view.d.ts.map +1 -1
- package/dist/markdown-view.js.map +1 -1
- package/dist/mermaid.d.ts.map +1 -1
- package/dist/mermaid.js +8 -4
- package/dist/mermaid.js.map +1 -1
- package/dist/parsers.d.ts.map +1 -1
- package/dist/parsers.js.map +1 -1
- package/dist/row-document-renderable.d.ts.map +1 -1
- package/dist/row-document-renderable.js.map +1 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js.map +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js.map +1 -1
- package/dist/text-table-internals.d.ts.map +1 -1
- package/dist/text-table-internals.js.map +1 -1
- package/package.json +6 -6
- package/src/chooser/choose-filter.tsx +1 -0
- package/src/chooser/choose-highlighted-text.tsx +2 -0
- package/src/chooser/choose-list.tsx +6 -0
- package/src/chooser/choose-store.ts +20 -3
- package/src/chooser/chooser.tsx +2 -0
- package/src/chooser/source.ts +5 -0
- package/src/chooser/use-choose.ts +44 -0
- package/src/code-blocks.tsx +14 -0
- package/src/command-palette.tsx +4 -0
- package/src/context-menu.tsx +13 -0
- package/src/index.ts +42 -0
- package/src/markdown/blocks/blockquote.tsx +2 -0
- package/src/markdown/blocks/flat-block.tsx +13 -0
- package/src/markdown/blocks/heading.tsx +1 -0
- package/src/markdown/blocks/list-line.tsx +3 -0
- package/src/markdown/blocks/paragraph.tsx +1 -0
- package/src/markdown/blocks/table.tsx +7 -0
- package/src/markdown/links.ts +26 -0
- package/src/markdown/plain-text.ts +5 -0
- package/src/markdown/table-links.ts +12 -0
- package/src/markdown/tokens.ts +2 -0
- package/src/markdown/visit-inline.ts +20 -0
- package/src/markdown-blocks.ts +31 -0
- package/src/markdown-images.ts +21 -0
- package/src/markdown-view.tsx +4 -0
- package/src/mermaid.ts +21 -4
- package/src/parsers.ts +39 -0
- package/src/row-document-renderable.ts +53 -0
- package/src/source.ts +18 -0
- package/src/table.tsx +32 -0
- package/src/text-table-internals.ts +12 -0
package/src/markdown-view.tsx
CHANGED
|
@@ -20,6 +20,7 @@ import "./row-document.js";
|
|
|
20
20
|
import "./text-table.js";
|
|
21
21
|
|
|
22
22
|
export { inlineLinkAtPosition } from "./markdown/links.js";
|
|
23
|
+
|
|
23
24
|
export type { InlineLinkPosition, MarkdownLinkHandler } from "./markdown/links.js";
|
|
24
25
|
|
|
25
26
|
type CodeBlockRendererRegistry = Record<string, CodeBlockRenderer>;
|
|
@@ -91,6 +92,7 @@ export const MarkdownView = function MarkdownView({
|
|
|
91
92
|
const { theme, syntax } = useTheme();
|
|
92
93
|
const palette = useGutterPalette();
|
|
93
94
|
const { width: terminalWidth } = useTerminalDimensions();
|
|
95
|
+
|
|
94
96
|
const blocks = useMemo(
|
|
95
97
|
() => providedBlocks ?? flattenMarkdown(content),
|
|
96
98
|
[providedBlocks, content]
|
|
@@ -110,9 +112,11 @@ export const MarkdownView = function MarkdownView({
|
|
|
110
112
|
|
|
111
113
|
const mergedCodeBlockRenderers = useMemo(() => {
|
|
112
114
|
const entries = new Map(Object.entries(DEFAULT_CODE_BLOCK_RENDERERS));
|
|
115
|
+
|
|
113
116
|
for (const [key, renderer] of Object.entries(codeBlockRenderers ?? {})) {
|
|
114
117
|
entries.set(key.trim().toLowerCase(), renderer);
|
|
115
118
|
}
|
|
119
|
+
|
|
116
120
|
return Object.fromEntries(entries);
|
|
117
121
|
}, [codeBlockRenderers]);
|
|
118
122
|
|
package/src/mermaid.ts
CHANGED
|
@@ -34,8 +34,11 @@ export interface AnsiStyledText {
|
|
|
34
34
|
// an edge cannot be routed. Keep synchronous work within a conservative budget;
|
|
35
35
|
// MarkdownView will visibly fall back to the original Mermaid source instead.
|
|
36
36
|
const MAX_SOURCE_LENGTH = 20_000;
|
|
37
|
+
|
|
37
38
|
const MAX_SOURCE_LINES = 300;
|
|
39
|
+
|
|
38
40
|
const MAX_FLOWCHART_EDGES = 32;
|
|
41
|
+
|
|
39
42
|
const MIN_UNSAFE_CYCLIC_FAN_DEGREE = 3;
|
|
40
43
|
|
|
41
44
|
// oxlint-disable-next-line no-control-regex -- ANSI SGR sequences start with the ESC control character
|
|
@@ -59,12 +62,15 @@ const hasDirectedPath = function hasDirectedPath(
|
|
|
59
62
|
|
|
60
63
|
while (pending.length > 0) {
|
|
61
64
|
const node = pending.pop();
|
|
65
|
+
|
|
62
66
|
if (node === undefined) {
|
|
63
67
|
continue;
|
|
64
68
|
}
|
|
69
|
+
|
|
65
70
|
if (node === target) {
|
|
66
71
|
return true;
|
|
67
72
|
}
|
|
73
|
+
|
|
68
74
|
if (visited.has(node)) {
|
|
69
75
|
continue;
|
|
70
76
|
}
|
|
@@ -91,12 +97,17 @@ const hasUnsafeCyclicFanTopology = function hasUnsafeCyclicFanTopology(
|
|
|
91
97
|
outgoingDegree.set(edge.source, (outgoingDegree.get(edge.source) ?? 0) + 1);
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
const fanInNodes =
|
|
100
|
+
const fanInNodes = incomingDegree
|
|
101
|
+
.entries()
|
|
95
102
|
.filter(([, degree]) => degree >= MIN_UNSAFE_CYCLIC_FAN_DEGREE)
|
|
96
|
-
.map(([node]) => node)
|
|
97
|
-
|
|
103
|
+
.map(([node]) => node)
|
|
104
|
+
.toArray();
|
|
105
|
+
|
|
106
|
+
const fanOutNodes = outgoingDegree
|
|
107
|
+
.entries()
|
|
98
108
|
.filter(([, degree]) => degree >= MIN_UNSAFE_CYCLIC_FAN_DEGREE)
|
|
99
|
-
.map(([node]) => node)
|
|
109
|
+
.map(([node]) => node)
|
|
110
|
+
.toArray();
|
|
100
111
|
|
|
101
112
|
return fanInNodes.some((fanIn) =>
|
|
102
113
|
fanOutNodes.some(
|
|
@@ -121,6 +132,7 @@ const exceedsSynchronousRenderBudget = function exceedsSynchronousRenderBudget(
|
|
|
121
132
|
}
|
|
122
133
|
|
|
123
134
|
const { edges } = parseMermaid(source);
|
|
135
|
+
|
|
124
136
|
return edges.length > MAX_FLOWCHART_EDGES || hasUnsafeCyclicFanTopology(edges);
|
|
125
137
|
};
|
|
126
138
|
|
|
@@ -134,9 +146,11 @@ const appendStyledChunk = function appendStyledChunk(
|
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
const chunk: TextChunk = { __isChunk: true, text };
|
|
149
|
+
|
|
137
150
|
if (fg !== undefined && fg !== "") {
|
|
138
151
|
chunk.fg = parseColor(fg);
|
|
139
152
|
}
|
|
153
|
+
|
|
140
154
|
chunks.push(chunk);
|
|
141
155
|
};
|
|
142
156
|
|
|
@@ -144,6 +158,7 @@ const sgrParams = function sgrParams(rawParams: string): number[] {
|
|
|
144
158
|
if (rawParams === "") {
|
|
145
159
|
return [0];
|
|
146
160
|
}
|
|
161
|
+
|
|
147
162
|
return rawParams.split(";").map((param) => (param === "" ? 0 : Number(param)));
|
|
148
163
|
};
|
|
149
164
|
|
|
@@ -232,10 +247,12 @@ export const renderMermaidForTerminal = function renderMermaidForTerminal(
|
|
|
232
247
|
}
|
|
233
248
|
|
|
234
249
|
const mode = options.mode ?? "plain";
|
|
250
|
+
|
|
235
251
|
const rendered = renderMermaidASCII(source, {
|
|
236
252
|
colorMode: mode === "ansi" ? "truecolor" : "none",
|
|
237
253
|
theme: options.theme,
|
|
238
254
|
}).trimEnd();
|
|
255
|
+
|
|
239
256
|
const { text, content } = ansiToStyledText(rendered);
|
|
240
257
|
|
|
241
258
|
if (text.trim().length === 0) {
|
package/src/parsers.ts
CHANGED
|
@@ -29,6 +29,7 @@ const jsonEntryKeys = function jsonEntryKeys(value: JsonValue): string[] {
|
|
|
29
29
|
if (value === null) {
|
|
30
30
|
throw new TypeError("A JSON table row cannot be null");
|
|
31
31
|
}
|
|
32
|
+
|
|
32
33
|
return Object.keys(value);
|
|
33
34
|
};
|
|
34
35
|
|
|
@@ -36,12 +37,15 @@ const readJsonEntry = function readJsonEntry(value: JsonValue, key: string): Jso
|
|
|
36
37
|
if (isJsonArray(value)) {
|
|
37
38
|
return value[Number(key)];
|
|
38
39
|
}
|
|
40
|
+
|
|
39
41
|
if (value instanceof Object) {
|
|
40
42
|
return value[key];
|
|
41
43
|
}
|
|
44
|
+
|
|
42
45
|
if (Object.prototype.toString.call(value) === "[object String]") {
|
|
43
46
|
return String.prototype.charAt.call(value, Number(key));
|
|
44
47
|
}
|
|
48
|
+
|
|
45
49
|
return undefined;
|
|
46
50
|
};
|
|
47
51
|
|
|
@@ -51,6 +55,7 @@ const splitLines = function splitLines(input: string): string[] {
|
|
|
51
55
|
|
|
52
56
|
const createColumnDefs = function createColumnDefs(rawHeaders: string[]): ColumnDef[] {
|
|
53
57
|
const seen = new Map<string, number>();
|
|
58
|
+
|
|
54
59
|
return rawHeaders.map((header, index) => {
|
|
55
60
|
const trimmed = header.trim();
|
|
56
61
|
const fallback = `column_${index + 1}`;
|
|
@@ -58,6 +63,7 @@ const createColumnDefs = function createColumnDefs(rawHeaders: string[]): Column
|
|
|
58
63
|
const count = seen.get(base) ?? 0;
|
|
59
64
|
seen.set(base, count + 1);
|
|
60
65
|
const key = count === 0 ? base : `${base}_${count + 1}`;
|
|
66
|
+
|
|
61
67
|
return {
|
|
62
68
|
header: trimmed || undefined,
|
|
63
69
|
key,
|
|
@@ -68,9 +74,11 @@ const createColumnDefs = function createColumnDefs(rawHeaders: string[]): Column
|
|
|
68
74
|
const buildRows = function buildRows(columns: ColumnDef[], rawRows: string[][]): TableRow[] {
|
|
69
75
|
return rawRows.map((row) => {
|
|
70
76
|
const record: TableRow = {};
|
|
77
|
+
|
|
71
78
|
for (const [index, column] of columns.entries()) {
|
|
72
79
|
record[column.key] = row[index] ?? "";
|
|
73
80
|
}
|
|
81
|
+
|
|
74
82
|
return record;
|
|
75
83
|
});
|
|
76
84
|
};
|
|
@@ -78,11 +86,13 @@ const buildRows = function buildRows(columns: ColumnDef[], rawRows: string[][]):
|
|
|
78
86
|
const parseCSVLine = function parseCSVLine(line: string): string[] {
|
|
79
87
|
const fields: string[] = [];
|
|
80
88
|
let i = 0;
|
|
89
|
+
|
|
81
90
|
while (i < line.length) {
|
|
82
91
|
if (line[i] === '"') {
|
|
83
92
|
// Quoted field
|
|
84
93
|
i += 1;
|
|
85
94
|
let field = "";
|
|
95
|
+
|
|
86
96
|
while (i < line.length) {
|
|
87
97
|
if (line[i] === '"') {
|
|
88
98
|
if (i + 1 < line.length && line[i + 1] === '"') {
|
|
@@ -97,13 +107,16 @@ const parseCSVLine = function parseCSVLine(line: string): string[] {
|
|
|
97
107
|
i += 1;
|
|
98
108
|
}
|
|
99
109
|
}
|
|
110
|
+
|
|
100
111
|
fields.push(field);
|
|
112
|
+
|
|
101
113
|
// Skip the comma after a quoted field.
|
|
102
114
|
if (i < line.length && line[i] === ",") {
|
|
103
115
|
i += 1;
|
|
104
116
|
}
|
|
105
117
|
} else {
|
|
106
118
|
const nextComma = line.indexOf(",", i);
|
|
119
|
+
|
|
107
120
|
if (nextComma === -1) {
|
|
108
121
|
fields.push(line.slice(i));
|
|
109
122
|
break;
|
|
@@ -113,46 +126,60 @@ const parseCSVLine = function parseCSVLine(line: string): string[] {
|
|
|
113
126
|
}
|
|
114
127
|
}
|
|
115
128
|
}
|
|
129
|
+
|
|
116
130
|
return fields;
|
|
117
131
|
};
|
|
118
132
|
|
|
119
133
|
export const parseCSV = function parseCSV(input: string): TableData {
|
|
120
134
|
const lines = splitLines(input);
|
|
135
|
+
|
|
121
136
|
if (lines.length === 0) {
|
|
122
137
|
return { columns: [], rows: [] };
|
|
123
138
|
}
|
|
139
|
+
|
|
124
140
|
const columns = createColumnDefs(parseCSVLine(lines[0]));
|
|
125
141
|
const rows = buildRows(columns, lines.slice(1).map(parseCSVLine));
|
|
142
|
+
|
|
126
143
|
return { columns, rows };
|
|
127
144
|
};
|
|
128
145
|
|
|
129
146
|
export const parseTSV = function parseTSV(input: string): TableData {
|
|
130
147
|
const lines = splitLines(input);
|
|
148
|
+
|
|
131
149
|
if (lines.length === 0) {
|
|
132
150
|
return { columns: [], rows: [] };
|
|
133
151
|
}
|
|
152
|
+
|
|
134
153
|
const columns = createColumnDefs(lines[0].split("\t"));
|
|
154
|
+
|
|
135
155
|
const rows = buildRows(
|
|
136
156
|
columns,
|
|
137
157
|
lines.slice(1).map((line) => line.split("\t"))
|
|
138
158
|
);
|
|
159
|
+
|
|
139
160
|
return { columns, rows };
|
|
140
161
|
};
|
|
141
162
|
|
|
142
163
|
export const parseJSON = function parseJSON(input: string): TableData {
|
|
143
164
|
const data = parseJsonDocument(input);
|
|
165
|
+
|
|
144
166
|
if (!isJsonArray(data) || data.length === 0) {
|
|
145
167
|
return { columns: [], rows: [] };
|
|
146
168
|
}
|
|
169
|
+
|
|
147
170
|
const keys = [...new Set(data.flatMap(jsonEntryKeys))];
|
|
148
171
|
const columns: ColumnDef[] = keys.map((key) => ({ header: key, key }));
|
|
172
|
+
|
|
149
173
|
const rows = data.map((item) => {
|
|
150
174
|
const row: TableRow = {};
|
|
175
|
+
|
|
151
176
|
for (const column of columns) {
|
|
152
177
|
row[column.key] = readJsonEntry(item, column.key) ?? "";
|
|
153
178
|
}
|
|
179
|
+
|
|
154
180
|
return row;
|
|
155
181
|
});
|
|
182
|
+
|
|
156
183
|
return { columns, rows };
|
|
157
184
|
};
|
|
158
185
|
|
|
@@ -160,9 +187,11 @@ export type Format = "csv" | "tsv" | "json" | "unknown";
|
|
|
160
187
|
|
|
161
188
|
export const detectFormat = function detectFormat(input: string): Format {
|
|
162
189
|
const trimmed = input.trimStart();
|
|
190
|
+
|
|
163
191
|
if (trimmed.startsWith("[")) {
|
|
164
192
|
try {
|
|
165
193
|
const parsed = parseJsonDocument(trimmed);
|
|
194
|
+
|
|
166
195
|
if (isJsonArray(parsed)) {
|
|
167
196
|
return "json";
|
|
168
197
|
}
|
|
@@ -170,13 +199,17 @@ export const detectFormat = function detectFormat(input: string): Format {
|
|
|
170
199
|
// Not valid JSON — fall through to the delimiter sniffing below.
|
|
171
200
|
}
|
|
172
201
|
}
|
|
202
|
+
|
|
173
203
|
const firstLine = input.split("\n")[0] ?? "";
|
|
204
|
+
|
|
174
205
|
if (firstLine.includes("\t")) {
|
|
175
206
|
return "tsv";
|
|
176
207
|
}
|
|
208
|
+
|
|
177
209
|
if (firstLine.includes(",")) {
|
|
178
210
|
return "csv";
|
|
179
211
|
}
|
|
212
|
+
|
|
180
213
|
return "unknown";
|
|
181
214
|
};
|
|
182
215
|
|
|
@@ -184,28 +217,34 @@ export const parseAuto = function parseAuto(input: string): ParsedTable {
|
|
|
184
217
|
const format = detectFormat(input);
|
|
185
218
|
let columns: ColumnDef[];
|
|
186
219
|
let rows: TableRow[];
|
|
220
|
+
|
|
187
221
|
switch (format) {
|
|
188
222
|
case "csv": {
|
|
189
223
|
({ columns, rows } = parseCSV(input));
|
|
190
224
|
break;
|
|
191
225
|
}
|
|
226
|
+
|
|
192
227
|
case "tsv": {
|
|
193
228
|
({ columns, rows } = parseTSV(input));
|
|
194
229
|
break;
|
|
195
230
|
}
|
|
231
|
+
|
|
196
232
|
case "json": {
|
|
197
233
|
({ columns, rows } = parseJSON(input));
|
|
198
234
|
break;
|
|
199
235
|
}
|
|
236
|
+
|
|
200
237
|
case "unknown": {
|
|
201
238
|
// Fall back to CSV
|
|
202
239
|
({ columns, rows } = parseCSV(input));
|
|
203
240
|
break;
|
|
204
241
|
}
|
|
242
|
+
|
|
205
243
|
default: {
|
|
206
244
|
({ columns, rows } = parseCSV(input));
|
|
207
245
|
break;
|
|
208
246
|
}
|
|
209
247
|
}
|
|
248
|
+
|
|
210
249
|
return { columns, format, rows };
|
|
211
250
|
};
|
|
@@ -71,10 +71,12 @@ const colorCache = new Map<string, RGBA>();
|
|
|
71
71
|
|
|
72
72
|
const cachedColor = function cachedColor(hex: string): RGBA {
|
|
73
73
|
let c = colorCache.get(hex);
|
|
74
|
+
|
|
74
75
|
if (!c) {
|
|
75
76
|
c = RGBA.fromHex(hex);
|
|
76
77
|
colorCache.set(hex, c);
|
|
77
78
|
}
|
|
79
|
+
|
|
78
80
|
return c;
|
|
79
81
|
};
|
|
80
82
|
|
|
@@ -93,6 +95,7 @@ const normalizeDecorationLayers = function normalizeDecorationLayers(
|
|
|
93
95
|
if (!layers || layers.length === 0) {
|
|
94
96
|
return [];
|
|
95
97
|
}
|
|
98
|
+
|
|
96
99
|
return [...layers].toSorted((a, b) => a.priority - b.priority);
|
|
97
100
|
};
|
|
98
101
|
|
|
@@ -105,6 +108,7 @@ const maxGutterNumber = function maxGutterNumber(opts: {
|
|
|
105
108
|
if (opts.rowNumbers && opts.rowNumbers.length > 0) {
|
|
106
109
|
return Math.max(...opts.rowNumbers);
|
|
107
110
|
}
|
|
111
|
+
|
|
108
112
|
return (opts.lineNumberStart ?? 1) + opts.rowCount - 1;
|
|
109
113
|
};
|
|
110
114
|
|
|
@@ -117,11 +121,14 @@ export const computeRowDocumentGutterWidth = function computeRowDocumentGutterWi
|
|
|
117
121
|
gutterPaddingRight?: number;
|
|
118
122
|
}): number {
|
|
119
123
|
let width = 0;
|
|
124
|
+
|
|
120
125
|
if (opts.showLineNumbers) {
|
|
121
126
|
width += Math.max(String(maxGutterNumber(opts)).length, 1);
|
|
122
127
|
}
|
|
128
|
+
|
|
123
129
|
width += opts.signColumnWidth ?? 0;
|
|
124
130
|
width += opts.gutterPaddingRight ?? 1;
|
|
131
|
+
|
|
125
132
|
return width;
|
|
126
133
|
};
|
|
127
134
|
|
|
@@ -248,6 +255,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
248
255
|
if (row < 0 || row >= this._rowCount) {
|
|
249
256
|
return null;
|
|
250
257
|
}
|
|
258
|
+
|
|
251
259
|
return {
|
|
252
260
|
row,
|
|
253
261
|
virtualHeight: this._rowVirtualHeights[row],
|
|
@@ -258,16 +266,20 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
258
266
|
getRowAtVirtualY(y: number): number {
|
|
259
267
|
const clamped = Math.max(0, Math.min(y, this._virtualRowToRow.length - 1));
|
|
260
268
|
const row = this._virtualRowToRow[clamped];
|
|
269
|
+
|
|
261
270
|
if (row >= 0) {
|
|
262
271
|
return row;
|
|
263
272
|
}
|
|
273
|
+
|
|
264
274
|
// Gap row — search backward for nearest valid row
|
|
265
275
|
for (let i = clamped - 1; i >= 0; i -= 1) {
|
|
266
276
|
const r = this._virtualRowToRow[i];
|
|
277
|
+
|
|
267
278
|
if (r >= 0) {
|
|
268
279
|
return r;
|
|
269
280
|
}
|
|
270
281
|
}
|
|
282
|
+
|
|
271
283
|
return 0;
|
|
272
284
|
}
|
|
273
285
|
|
|
@@ -285,22 +297,28 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
285
297
|
*/
|
|
286
298
|
getRowAtScreenY(screenY: number): number | null {
|
|
287
299
|
const localY = screenY - this.viewport.y;
|
|
300
|
+
|
|
288
301
|
if (localY < 0 || localY >= this.viewport.height) {
|
|
289
302
|
return null;
|
|
290
303
|
}
|
|
304
|
+
|
|
291
305
|
const virtualY = Math.floor(this.scrollTop) + localY;
|
|
306
|
+
|
|
292
307
|
if (virtualY < 0 || virtualY >= this._virtualRowToRow.length) {
|
|
293
308
|
return null;
|
|
294
309
|
}
|
|
310
|
+
|
|
295
311
|
if (virtualY >= this._contentVirtualEnd) {
|
|
296
312
|
return null;
|
|
297
313
|
}
|
|
314
|
+
|
|
298
315
|
return this.getRowAtVirtualY(virtualY);
|
|
299
316
|
}
|
|
300
317
|
|
|
301
318
|
getVisibleRange(): VisibleRowRange {
|
|
302
319
|
const top = Math.floor(this.scrollTop);
|
|
303
320
|
const bottom = top + this.viewport.height;
|
|
321
|
+
|
|
304
322
|
return {
|
|
305
323
|
firstRow: this.getRowAtVirtualY(top),
|
|
306
324
|
lastRow: this.getRowAtVirtualY(bottom - 1),
|
|
@@ -331,6 +349,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
331
349
|
*/
|
|
332
350
|
scrollToRow(row: number, align: RowScrollAlign = "nearest", margin = 0): void {
|
|
333
351
|
const metrics = this.getRowMetrics(row);
|
|
352
|
+
|
|
334
353
|
if (!metrics) {
|
|
335
354
|
return;
|
|
336
355
|
}
|
|
@@ -346,22 +365,27 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
346
365
|
target = virtualTop - gap;
|
|
347
366
|
break;
|
|
348
367
|
}
|
|
368
|
+
|
|
349
369
|
case "center": {
|
|
350
370
|
target = virtualTop - (vpHeight - virtualHeight) / 2;
|
|
351
371
|
break;
|
|
352
372
|
}
|
|
373
|
+
|
|
353
374
|
case "end": {
|
|
354
375
|
target = virtualTop + virtualHeight - vpHeight + gap;
|
|
355
376
|
break;
|
|
356
377
|
}
|
|
378
|
+
|
|
357
379
|
case "nearest": {
|
|
358
380
|
if (virtualTop - gap < this.scrollTop) {
|
|
359
381
|
target = virtualTop - gap;
|
|
360
382
|
} else if (virtualTop + virtualHeight + gap > this.scrollTop + vpHeight) {
|
|
361
383
|
target = virtualTop + virtualHeight - vpHeight + gap;
|
|
362
384
|
}
|
|
385
|
+
|
|
363
386
|
break;
|
|
364
387
|
}
|
|
388
|
+
|
|
365
389
|
default: {
|
|
366
390
|
break;
|
|
367
391
|
}
|
|
@@ -376,8 +400,10 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
376
400
|
// extend the scroll to include it
|
|
377
401
|
if (row + 1 === this._rowCount - 1) {
|
|
378
402
|
const next = this.getRowMetrics(row + 1);
|
|
403
|
+
|
|
379
404
|
if (next) {
|
|
380
405
|
const bottomEdge = next.virtualTop + next.virtualHeight;
|
|
406
|
+
|
|
381
407
|
if (bottomEdge > target + vpHeight) {
|
|
382
408
|
target = bottomEdge - vpHeight;
|
|
383
409
|
}
|
|
@@ -403,6 +429,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
403
429
|
|
|
404
430
|
// Paint decorations and gutter on top
|
|
405
431
|
this._paintDecorations(buffer);
|
|
432
|
+
|
|
406
433
|
if (this._showGutter) {
|
|
407
434
|
this._paintGutter(buffer);
|
|
408
435
|
}
|
|
@@ -416,20 +443,24 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
416
443
|
if (this._mode === "multi") {
|
|
417
444
|
return "multi";
|
|
418
445
|
}
|
|
446
|
+
|
|
419
447
|
if (this._mode === "provider") {
|
|
420
448
|
return "provider";
|
|
421
449
|
}
|
|
422
450
|
|
|
423
451
|
// Auto-detect: single child with LineInfoProvider → provider mode
|
|
424
452
|
const children = this.getChildren();
|
|
453
|
+
|
|
425
454
|
if (children.length === 1 && isRowContentProvider(children[0])) {
|
|
426
455
|
return "provider";
|
|
427
456
|
}
|
|
457
|
+
|
|
428
458
|
return "multi";
|
|
429
459
|
}
|
|
430
460
|
|
|
431
461
|
private _computeGeometry(): void {
|
|
432
462
|
const mode = this._detectMode();
|
|
463
|
+
|
|
433
464
|
if (mode === "provider") {
|
|
434
465
|
this._computeFromProvider();
|
|
435
466
|
} else {
|
|
@@ -445,6 +476,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
445
476
|
|
|
446
477
|
if (totalHeight === 0 || children.length <= offset) {
|
|
447
478
|
this._finishGeometry([], [], [], [], 0);
|
|
479
|
+
|
|
448
480
|
return;
|
|
449
481
|
}
|
|
450
482
|
|
|
@@ -465,6 +497,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
465
497
|
|
|
466
498
|
for (let r = 0; r < h; r += 1) {
|
|
467
499
|
const vRow = childStart + r;
|
|
500
|
+
|
|
468
501
|
if (vRow >= 0 && vRow < totalHeight) {
|
|
469
502
|
virtualRowToRow[vRow] = row;
|
|
470
503
|
virtualRowWraps[vRow] = r === 0 ? 0 : 1;
|
|
@@ -483,11 +516,13 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
483
516
|
|
|
484
517
|
private _computeFromProvider(): void {
|
|
485
518
|
const children = this.getChildren();
|
|
519
|
+
|
|
486
520
|
if (children.length === 0) {
|
|
487
521
|
return;
|
|
488
522
|
}
|
|
489
523
|
|
|
490
524
|
const [provider] = children;
|
|
525
|
+
|
|
491
526
|
if (!isRowContentProvider(provider)) {
|
|
492
527
|
return;
|
|
493
528
|
}
|
|
@@ -513,6 +548,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
513
548
|
if (currentRow >= 0) {
|
|
514
549
|
rowVirtualHeights[currentRow] = v - rowVirtualStarts[currentRow];
|
|
515
550
|
}
|
|
551
|
+
|
|
516
552
|
rowVirtualStarts[row] = v;
|
|
517
553
|
currentRow = row;
|
|
518
554
|
rowCount = Math.max(rowCount, row + 1);
|
|
@@ -541,16 +577,20 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
541
577
|
rowCount: number
|
|
542
578
|
): void {
|
|
543
579
|
let contentVirtualEnd = 0;
|
|
580
|
+
|
|
544
581
|
for (let row = 0; row < rowCount; row += 1) {
|
|
545
582
|
const end = rowVirtualStarts[row] + rowVirtualHeights[row];
|
|
583
|
+
|
|
546
584
|
if (end > contentVirtualEnd) {
|
|
547
585
|
contentVirtualEnd = end;
|
|
548
586
|
}
|
|
549
587
|
}
|
|
588
|
+
|
|
550
589
|
this._contentVirtualEnd = contentVirtualEnd;
|
|
551
590
|
|
|
552
591
|
// Change detection via hash
|
|
553
592
|
const hash = rowVirtualStarts.join(",");
|
|
593
|
+
|
|
554
594
|
if (hash !== this._lastGeometryHash) {
|
|
555
595
|
this._rowVirtualStarts = rowVirtualStarts;
|
|
556
596
|
this._rowVirtualHeights = rowVirtualHeights;
|
|
@@ -614,9 +654,11 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
614
654
|
if (deco.background !== undefined && deco.background !== "") {
|
|
615
655
|
rowBgs.set(deco.row, deco.background);
|
|
616
656
|
}
|
|
657
|
+
|
|
617
658
|
if (deco.gutterBackground !== undefined && deco.gutterBackground !== "") {
|
|
618
659
|
rowGutterBgs.set(deco.row, deco.gutterBackground);
|
|
619
660
|
}
|
|
661
|
+
|
|
620
662
|
if (deco.sign) {
|
|
621
663
|
rowSigns.set(deco.row, deco.sign);
|
|
622
664
|
}
|
|
@@ -625,18 +667,23 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
625
667
|
|
|
626
668
|
for (let screenY = 0; screenY < vpHeight; screenY += 1) {
|
|
627
669
|
const vRow = top + screenY;
|
|
670
|
+
|
|
628
671
|
if (vRow >= this._virtualRowToRow.length) {
|
|
629
672
|
break;
|
|
630
673
|
}
|
|
631
674
|
|
|
632
675
|
const row = this._virtualRowToRow[vRow];
|
|
676
|
+
|
|
633
677
|
if (row < 0) {
|
|
634
678
|
continue;
|
|
635
679
|
}
|
|
680
|
+
|
|
636
681
|
const bg = rowBgs.get(row);
|
|
682
|
+
|
|
637
683
|
if (bg === undefined || bg === "") {
|
|
638
684
|
continue;
|
|
639
685
|
}
|
|
686
|
+
|
|
640
687
|
buffer.fillRect(vpX, vpY + screenY, vpWidth, 1, cachedColor(bg));
|
|
641
688
|
}
|
|
642
689
|
|
|
@@ -650,6 +697,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
650
697
|
|
|
651
698
|
private _paintGutter(buffer: OptimizedBuffer): void {
|
|
652
699
|
const gutterWidth = this._computeGutterWidth();
|
|
700
|
+
|
|
653
701
|
if (gutterWidth === 0) {
|
|
654
702
|
return;
|
|
655
703
|
}
|
|
@@ -680,14 +728,17 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
680
728
|
|
|
681
729
|
for (let screenY = 0; screenY < vpHeight; screenY += 1) {
|
|
682
730
|
const vRow = top + screenY;
|
|
731
|
+
|
|
683
732
|
if (vRow >= this._virtualRowToRow.length) {
|
|
684
733
|
break;
|
|
685
734
|
}
|
|
686
735
|
|
|
687
736
|
const row = this._virtualRowToRow[vRow];
|
|
737
|
+
|
|
688
738
|
if (row < 0) {
|
|
689
739
|
continue;
|
|
690
740
|
}
|
|
741
|
+
|
|
691
742
|
const isFirstLine = this._virtualRowWraps[vRow] === 0;
|
|
692
743
|
|
|
693
744
|
if (!isFirstLine) {
|
|
@@ -698,8 +749,10 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
|
|
|
698
749
|
let col = 0;
|
|
699
750
|
|
|
700
751
|
const rowGutterHex = this._layerGutterBgs.get(row);
|
|
752
|
+
|
|
701
753
|
const effectiveGutterBg =
|
|
702
754
|
rowGutterHex !== undefined && rowGutterHex !== "" ? cachedColor(rowGutterHex) : gutterBg;
|
|
755
|
+
|
|
703
756
|
if (rowGutterHex !== undefined && rowGutterHex !== "") {
|
|
704
757
|
buffer.fillRect(drawX, vpY + screenY, gutterWidth, 1, effectiveGutterBg);
|
|
705
758
|
}
|