diffstalker 0.2.0 → 0.2.1
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/.github/workflows/release.yml +8 -0
- package/bun.lock +23 -0
- package/dist/App.js +225 -471
- package/dist/FollowMode.js +85 -0
- package/dist/KeyBindings.js +178 -0
- package/dist/MouseHandlers.js +156 -0
- package/dist/core/ExplorerStateManager.js +444 -78
- package/dist/core/GitStateManager.js +169 -93
- package/dist/git/diff.js +4 -0
- package/dist/index.js +54 -53
- package/dist/state/UIState.js +17 -4
- package/dist/ui/PaneRenderers.js +56 -0
- package/dist/ui/modals/FileFinder.js +232 -0
- package/dist/ui/widgets/CompareListView.js +86 -64
- package/dist/ui/widgets/DiffView.js +19 -17
- package/dist/ui/widgets/ExplorerContent.js +15 -28
- package/dist/ui/widgets/ExplorerView.js +140 -31
- package/dist/ui/widgets/Footer.js +6 -2
- package/dist/ui/widgets/Header.js +3 -46
- package/dist/utils/fileCategories.js +37 -0
- package/dist/utils/fileTree.js +148 -0
- package/eslint.metrics.js +16 -0
- package/metrics/.gitkeep +0 -0
- package/metrics/v0.2.1.json +268 -0
- package/package.json +4 -1
- package/dist/utils/ansiToBlessed.js +0 -125
- package/dist/utils/mouseCoordinates.js +0 -165
- package/dist/utils/rowCalculations.js +0 -246
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { isDisplayableDiffLine } from './diffFilters.js';
|
|
2
|
-
import { formatDateAbsolute } from './formatDate.js';
|
|
3
|
-
import { getDiffTotalRows, getDiffLineRowCount } from './diffRowCalculations.js';
|
|
4
|
-
// ============================================================================
|
|
5
|
-
// History View Row Calculations
|
|
6
|
-
// ============================================================================
|
|
7
|
-
/**
|
|
8
|
-
* Map a visual row index to the commit index in HistoryView.
|
|
9
|
-
* Since each commit takes 1 row, this is simply visualRow + scrollOffset.
|
|
10
|
-
*/
|
|
11
|
-
export function getCommitIndexFromRow(visualRow, commits, _terminalWidth, scrollOffset = 0) {
|
|
12
|
-
const index = visualRow + scrollOffset;
|
|
13
|
-
if (index < 0 || index >= commits.length) {
|
|
14
|
-
return -1;
|
|
15
|
-
}
|
|
16
|
-
return index;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Get the total number of visual rows for all commits in HistoryView.
|
|
20
|
-
* Since each commit takes 1 row, this equals commits.length.
|
|
21
|
-
*/
|
|
22
|
-
export function getHistoryTotalRows(commits, _terminalWidth) {
|
|
23
|
-
return commits.length;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Get the visual row offset for a given commit index in HistoryView.
|
|
27
|
-
* Since each commit takes 1 row, this equals commitIndex.
|
|
28
|
-
*/
|
|
29
|
-
export function getHistoryRowOffset(_commits, commitIndex, _terminalWidth) {
|
|
30
|
-
return commitIndex;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Build all displayable rows for the history diff view.
|
|
34
|
-
* This includes commit metadata, message, and diff lines.
|
|
35
|
-
* Single source of truth for both rendering and row counting.
|
|
36
|
-
*/
|
|
37
|
-
export function buildHistoryDiffRows(commit, diff) {
|
|
38
|
-
const rows = [];
|
|
39
|
-
if (commit) {
|
|
40
|
-
// Commit header: hash, author, date
|
|
41
|
-
rows.push({
|
|
42
|
-
type: 'commit-header',
|
|
43
|
-
content: `commit ${commit.hash}`,
|
|
44
|
-
});
|
|
45
|
-
rows.push({
|
|
46
|
-
type: 'commit-header',
|
|
47
|
-
content: `Author: ${commit.author}`,
|
|
48
|
-
});
|
|
49
|
-
rows.push({
|
|
50
|
-
type: 'commit-header',
|
|
51
|
-
content: `Date: ${formatDateAbsolute(commit.date)}`,
|
|
52
|
-
});
|
|
53
|
-
// Blank line before message
|
|
54
|
-
rows.push({ type: 'spacer' });
|
|
55
|
-
// Commit message (can be multi-line)
|
|
56
|
-
const messageLines = commit.message.split('\n');
|
|
57
|
-
for (const line of messageLines) {
|
|
58
|
-
rows.push({
|
|
59
|
-
type: 'commit-message',
|
|
60
|
-
content: ` ${line}`,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
// Blank line after message, before diff
|
|
64
|
-
rows.push({ type: 'spacer' });
|
|
65
|
-
}
|
|
66
|
-
// Diff lines (filter same as DiffView)
|
|
67
|
-
if (diff) {
|
|
68
|
-
for (const line of diff.lines) {
|
|
69
|
-
if (isDisplayableDiffLine(line)) {
|
|
70
|
-
rows.push({ type: 'diff-line', diffLine: line });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return rows;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Get the visual row count for a single HistoryDiffRow.
|
|
78
|
-
* Headers, spacers, and commit messages are always 1 row.
|
|
79
|
-
* Diff lines may wrap based on terminal width.
|
|
80
|
-
*/
|
|
81
|
-
export function getHistoryDiffRowHeight(row, lineNumWidth, terminalWidth) {
|
|
82
|
-
if (row.type !== 'diff-line' || !row.diffLine) {
|
|
83
|
-
return 1; // Headers, spacers, commit messages don't wrap
|
|
84
|
-
}
|
|
85
|
-
return getDiffLineRowCount(row.diffLine, lineNumWidth, terminalWidth);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Get total displayable rows for history diff scroll calculation.
|
|
89
|
-
* Uses getDiffTotalRows for the diff portion to account for line wrapping.
|
|
90
|
-
*/
|
|
91
|
-
export function getHistoryDiffTotalRows(commit, diff, terminalWidth) {
|
|
92
|
-
// Count header rows (these don't wrap - they're short metadata)
|
|
93
|
-
let headerRows = 0;
|
|
94
|
-
if (commit) {
|
|
95
|
-
headerRows += 3; // hash, author, date
|
|
96
|
-
headerRows += 1; // spacer before message
|
|
97
|
-
headerRows += commit.message.split('\n').length; // message lines
|
|
98
|
-
headerRows += 1; // spacer after message
|
|
99
|
-
}
|
|
100
|
-
// Use getDiffTotalRows for diff portion (handles line wrapping)
|
|
101
|
-
const diffRows = getDiffTotalRows(diff, terminalWidth);
|
|
102
|
-
return headerRows + diffRows;
|
|
103
|
-
}
|
|
104
|
-
// ============================================================================
|
|
105
|
-
// Compare View Row Calculations
|
|
106
|
-
// ============================================================================
|
|
107
|
-
/**
|
|
108
|
-
* Build a combined DiffResult from all compare files.
|
|
109
|
-
* This is the single source of truth for compare diff content.
|
|
110
|
-
*/
|
|
111
|
-
export function buildCombinedCompareDiff(compareDiff) {
|
|
112
|
-
if (!compareDiff || compareDiff.files.length === 0) {
|
|
113
|
-
return { raw: '', lines: [] };
|
|
114
|
-
}
|
|
115
|
-
const allLines = [];
|
|
116
|
-
const rawParts = [];
|
|
117
|
-
for (const file of compareDiff.files) {
|
|
118
|
-
// Include all lines from each file's diff (including headers)
|
|
119
|
-
for (const line of file.diff.lines) {
|
|
120
|
-
allLines.push(line);
|
|
121
|
-
}
|
|
122
|
-
rawParts.push(file.diff.raw);
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
raw: rawParts.join('\n'),
|
|
126
|
-
lines: allLines,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Calculate the total number of displayable lines in the compare diff.
|
|
131
|
-
* This accounts for header filtering done by DiffView.
|
|
132
|
-
*/
|
|
133
|
-
export function getCompareDiffTotalRows(compareDiff) {
|
|
134
|
-
const combined = buildCombinedCompareDiff(compareDiff);
|
|
135
|
-
return combined.lines.filter(isDisplayableDiffLine).length;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Calculate the row offset to scroll to a specific file in the compare diff.
|
|
139
|
-
* Returns the row index where the file's diff --git header starts.
|
|
140
|
-
*/
|
|
141
|
-
export function getFileScrollOffset(compareDiff, fileIndex) {
|
|
142
|
-
if (!compareDiff || fileIndex < 0 || fileIndex >= compareDiff.files.length)
|
|
143
|
-
return 0;
|
|
144
|
-
const combined = buildCombinedCompareDiff(compareDiff);
|
|
145
|
-
let displayableRow = 0;
|
|
146
|
-
let currentFileIndex = 0;
|
|
147
|
-
for (const line of combined.lines) {
|
|
148
|
-
// Check if this is a file boundary
|
|
149
|
-
if (line.type === 'header' && line.content.startsWith('diff --git')) {
|
|
150
|
-
if (currentFileIndex === fileIndex) {
|
|
151
|
-
return displayableRow;
|
|
152
|
-
}
|
|
153
|
-
currentFileIndex++;
|
|
154
|
-
}
|
|
155
|
-
// Skip lines that DiffView filters out
|
|
156
|
-
if (!isDisplayableDiffLine(line)) {
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
displayableRow++;
|
|
160
|
-
}
|
|
161
|
-
return 0;
|
|
162
|
-
}
|
|
163
|
-
// ============================================================================
|
|
164
|
-
// Compare List View Row Calculations
|
|
165
|
-
// ============================================================================
|
|
166
|
-
/**
|
|
167
|
-
* Map a visual row index to the item index in CompareListView.
|
|
168
|
-
* Returns the commit index for commits, or commitCount + fileIndex for files.
|
|
169
|
-
* Returns -1 if the row is a header, spacer, or out of bounds.
|
|
170
|
-
*
|
|
171
|
-
* Row structure (when both commits and files exist, both expanded):
|
|
172
|
-
* Row 0: "▼ Commits" header
|
|
173
|
-
* Row 1..N: commits
|
|
174
|
-
* Row N+1: spacer
|
|
175
|
-
* Row N+2: "▼ Files" header
|
|
176
|
-
* Rows N+3..: files
|
|
177
|
-
*/
|
|
178
|
-
export function getCompareItemIndexFromRow(row, commitCount, fileCount, commitsExpanded = true, filesExpanded = true) {
|
|
179
|
-
let currentRow = 0;
|
|
180
|
-
// Commits section
|
|
181
|
-
if (commitCount > 0) {
|
|
182
|
-
if (row === currentRow)
|
|
183
|
-
return -1; // "▼ Commits" header
|
|
184
|
-
currentRow++;
|
|
185
|
-
if (commitsExpanded) {
|
|
186
|
-
if (row < currentRow + commitCount) {
|
|
187
|
-
return row - currentRow; // Commit index
|
|
188
|
-
}
|
|
189
|
-
currentRow += commitCount;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// Files section
|
|
193
|
-
if (fileCount > 0) {
|
|
194
|
-
if (commitCount > 0) {
|
|
195
|
-
if (row === currentRow)
|
|
196
|
-
return -1; // Spacer
|
|
197
|
-
currentRow++;
|
|
198
|
-
}
|
|
199
|
-
if (row === currentRow)
|
|
200
|
-
return -1; // "▼ Files" header
|
|
201
|
-
currentRow++;
|
|
202
|
-
if (filesExpanded) {
|
|
203
|
-
if (row < currentRow + fileCount) {
|
|
204
|
-
return commitCount + (row - currentRow); // File index (offset by commit count)
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return -1; // Out of bounds
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Map an item index to its row position in CompareListView.
|
|
212
|
-
* This is the inverse of getCompareItemIndexFromRow.
|
|
213
|
-
*
|
|
214
|
-
* For itemIndex in 0..(commitCount-1): row = 1 + itemIndex
|
|
215
|
-
* For itemIndex in commitCount..(commitCount+fileCount-1): row = 1 + commitCount + 1 + 1 + (itemIndex - commitCount)
|
|
216
|
-
*/
|
|
217
|
-
export function getCompareRowFromItemIndex(itemIndex, commitCount, fileCount, commitsExpanded = true, filesExpanded = true) {
|
|
218
|
-
if (itemIndex < 0)
|
|
219
|
-
return 0;
|
|
220
|
-
// Handle commit items
|
|
221
|
-
if (itemIndex < commitCount) {
|
|
222
|
-
// Row 0 is commits header, so commit i is at row 1 + i
|
|
223
|
-
return commitsExpanded ? 1 + itemIndex : 0;
|
|
224
|
-
}
|
|
225
|
-
// Handle file items
|
|
226
|
-
const fileIndex = itemIndex - commitCount;
|
|
227
|
-
if (fileIndex >= fileCount)
|
|
228
|
-
return 0;
|
|
229
|
-
// Calculate row for file:
|
|
230
|
-
// - commits header (1 row if commits exist)
|
|
231
|
-
// - commits (commitCount rows if expanded)
|
|
232
|
-
// - spacer (1 row if commits exist)
|
|
233
|
-
// - files header (1 row)
|
|
234
|
-
// - file items
|
|
235
|
-
let row = 0;
|
|
236
|
-
if (commitCount > 0) {
|
|
237
|
-
row += 1; // commits header
|
|
238
|
-
if (commitsExpanded)
|
|
239
|
-
row += commitCount;
|
|
240
|
-
row += 1; // spacer
|
|
241
|
-
}
|
|
242
|
-
row += 1; // files header
|
|
243
|
-
if (filesExpanded)
|
|
244
|
-
row += fileIndex;
|
|
245
|
-
return row;
|
|
246
|
-
}
|