gitmaps 1.1.18 → 1.1.19

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/app/analytics.db CHANGED
Binary file
@@ -76,6 +76,25 @@ describe('low zoom preview helpers', () => {
76
76
  expect(deleted[0]?.height).toBe(1);
77
77
  });
78
78
 
79
+ test('derives diff markers from hunks when line maps are absent', () => {
80
+ const markers = collectPreviewDiffMarkers({
81
+ hunks: [
82
+ {
83
+ newStart: 8,
84
+ lines: [
85
+ { type: 'ctx', content: 'a' },
86
+ { type: 'del', content: 'old-1' },
87
+ { type: 'del', content: 'old-2' },
88
+ { type: 'add', content: 'new-1' },
89
+ { type: 'ctx', content: 'b' },
90
+ ],
91
+ },
92
+ ],
93
+ }, 20);
94
+ expect(markers.some((m) => m.color === '#22c55e')).toBe(true);
95
+ expect(markers.some((m) => m.color === '#ef4444')).toBe(true);
96
+ });
97
+
79
98
  test('title typography is larger than body typography for readability', () => {
80
99
  const scale = getLowZoomScale(0.18);
81
100
  expect(scale.titleFont).toBeGreaterThan(scale.bodyFont);
@@ -137,8 +137,8 @@ export function getPreviewScrollMetrics(file: any, height: number, zoom: number,
137
137
  export function collectPreviewDiffMarkers(file: any, totalLines: number) {
138
138
  const markers: Array<{ ratio: number; color: string; height?: number }> = [];
139
139
  const safeTotal = Math.max(1, totalLines);
140
- const added = file?.addedLines instanceof Set ? Array.from(file.addedLines) : [];
141
- const deletedBefore = file?.deletedBeforeLine instanceof Map ? Array.from(file.deletedBeforeLine.keys()) : [];
140
+ let added = file?.addedLines instanceof Set ? Array.from(file.addedLines) : [];
141
+ let deletedBefore = file?.deletedBeforeLine instanceof Map ? Array.from(file.deletedBeforeLine.keys()) : [];
142
142
 
143
143
  if (file?.status === 'added') {
144
144
  markers.push({ ratio: 0, color: '#22c55e', height: 1 });
@@ -149,6 +149,38 @@ export function collectPreviewDiffMarkers(file: any, totalLines: number) {
149
149
  return markers;
150
150
  }
151
151
 
152
+ if ((added.length === 0 && deletedBefore.length === 0) && Array.isArray(file?.hunks)) {
153
+ const derivedAdded: number[] = [];
154
+ const derivedDeleted: number[] = [];
155
+ for (const hunk of file.hunks) {
156
+ let newLine = hunk?.newStart || 1;
157
+ let sawPendingDelete = false;
158
+ for (const line of hunk?.lines || []) {
159
+ if (line?.type === 'add') {
160
+ derivedAdded.push(newLine);
161
+ if (sawPendingDelete) {
162
+ derivedDeleted.push(newLine);
163
+ sawPendingDelete = false;
164
+ }
165
+ newLine += 1;
166
+ } else if (line?.type === 'del') {
167
+ sawPendingDelete = true;
168
+ } else {
169
+ if (sawPendingDelete) {
170
+ derivedDeleted.push(newLine);
171
+ sawPendingDelete = false;
172
+ }
173
+ newLine += 1;
174
+ }
175
+ }
176
+ if (sawPendingDelete) {
177
+ derivedDeleted.push(newLine);
178
+ }
179
+ }
180
+ added = derivedAdded;
181
+ deletedBefore = derivedDeleted;
182
+ }
183
+
152
184
  for (const line of added) {
153
185
  markers.push({ ratio: Math.max(0, Math.min(1, (line - 1) / safeTotal)), color: '#22c55e' });
154
186
  }
@@ -247,31 +279,6 @@ export function renderLowZoomPreviewCanvas(
247
279
  ctx.fillText(line, leftInset, y);
248
280
  });
249
281
 
250
- const trackX = width - scrollbarWidth - 5;
251
- const markerX = trackX - markerLaneWidth - 4;
252
- const trackY = scrollMetrics.trackPadding;
253
- const trackHeight = scrollMetrics.trackHeight;
254
-
255
- ctx.fillStyle = 'rgba(255,255,255,0.08)';
256
- roundRect(ctx, markerX, trackY, markerLaneWidth, trackHeight, 3);
257
- ctx.fill();
258
-
259
- ctx.fillStyle = 'rgba(255,255,255,0.12)';
260
- roundRect(ctx, trackX, trackY, scrollbarWidth, trackHeight, scrollbarWidth / 2);
261
- ctx.fill();
262
-
263
- const markers = collectPreviewDiffMarkers(file, scrollMetrics.totalLines);
264
- for (const marker of markers) {
265
- const markerHeight = marker.height === 1 ? trackHeight : 5;
266
- const y = marker.height === 1 ? trackY : trackY + marker.ratio * Math.max(0, trackHeight - markerHeight);
267
- ctx.fillStyle = marker.color;
268
- roundRect(ctx, markerX, Math.max(trackY, y), markerLaneWidth, markerHeight, 2);
269
- ctx.fill();
270
- }
271
-
272
- ctx.fillStyle = 'rgba(196,181,253,0.96)';
273
- roundRect(ctx, trackX, scrollMetrics.thumbY, scrollbarWidth, scrollMetrics.thumbHeight, scrollbarWidth / 2);
274
- ctx.fill();
275
282
  }
276
283
 
277
284
  function trimToWidth(ctx: CanvasRenderingContext2D, text: string, maxWidth: number) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitmaps",
3
- "version": "1.1.18",
3
+ "version": "1.1.19",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "gitmaps": "cli.ts"