pi-odd-worktree 3.11.0 → 3.11.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/extensions/odd-worktree-tools.ts +81 -39
- package/lib/gh-prs.js +4 -1
- package/lib/issue-preview.js +53 -10
- package/lib/issues-view.js +55 -21
- package/lib/pr-preview.js +36 -5
- package/lib/prs-view.js +398 -65
- package/package.json +1 -1
- package/tools/gh-prs.test.js +5 -1
- package/tools/issue-preview.test.js +113 -0
- package/tools/issues-command.test.js +8 -5
- package/tools/issues-view.test.js +130 -0
- package/tools/pr-preview.test.js +134 -0
- package/tools/prs-command.test.js +49 -0
- package/tools/prs-view.test.js +350 -5
package/lib/prs-view.js
CHANGED
|
@@ -53,6 +53,24 @@
|
|
|
53
53
|
// S10 (issues, kept): every write records and paints its busy state BEFORE the
|
|
54
54
|
// action is invoked and ignores every key until it settles, so a second save,
|
|
55
55
|
// a navigation or typing can never race it.
|
|
56
|
+
//
|
|
57
|
+
// T20: the linked-issues editor names every issue by NUMBER AND TITLE. `i` opens
|
|
58
|
+
// the pull request's current links as `[x] #61 TEMP: rail check 1` toggles, and
|
|
59
|
+
// `n` opens a LIST of the repository's open issues instead of a bare number
|
|
60
|
+
// field: the links already in the draft first (checked, real titles), then the
|
|
61
|
+
// rest hottest-updated first. The candidates arrive through ONE injected seam,
|
|
62
|
+
// `loadIssueCandidates({ after, pageSize })`, which answers the same cursor page
|
|
63
|
+
// shape the list uses (`{ok, rows, hasMore, cursor}` with rows
|
|
64
|
+
// `{number, title, state}`); the list scrolls with the panel's own scroll keys
|
|
65
|
+
// and reads the next page as it scrolls. `space` toggles the focused row, `enter`
|
|
66
|
+
// keeps the selection and returns to the toggles, `esc` discards it. A title the
|
|
67
|
+
// seam cannot answer leaves the row as `#N` instead of blocking the editor, and a
|
|
68
|
+
// failed read paints its error while the toggles stay.
|
|
69
|
+
//
|
|
70
|
+
// D27 stays the write rule: the applied add/remove delta still goes through the
|
|
71
|
+
// ONE existing linked-issues save (marker-only body edit, byte-exact own line,
|
|
72
|
+
// re-read with state), and a number the pull request already links is never
|
|
73
|
+
// added twice.
|
|
56
74
|
|
|
57
75
|
const layout = require('./view-layout.js');
|
|
58
76
|
const scrollKeys = require('./preview-scroll-keys.js');
|
|
@@ -184,7 +202,8 @@ const MERGE_KEYS = [
|
|
|
184
202
|
|
|
185
203
|
// S2: the Development relation editor. GitHub has no mutation for that panel,
|
|
186
204
|
// so the client rewrites the `Closes #N` lines of the body; this step only
|
|
187
|
-
// collects the delta.
|
|
205
|
+
// collects the delta. T20: `n` opens the candidate list instead of a number
|
|
206
|
+
// field.
|
|
188
207
|
const LINKED_EDITOR_KEYS = [
|
|
189
208
|
{ key: 'space', text: 'space toggle', short: 'space', priority: 70 },
|
|
190
209
|
{ key: 'n', text: 'n add', short: 'n', priority: 60 },
|
|
@@ -192,9 +211,14 @@ const LINKED_EDITOR_KEYS = [
|
|
|
192
211
|
{ key: 'esc', text: 'esc back', short: 'esc back', priority: 100 },
|
|
193
212
|
];
|
|
194
213
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
214
|
+
// T20: the candidate list `n` opens. Its scroll keys are the panel's own
|
|
215
|
+
// preview bindings, so the list pages exactly like the pane; `enter` keeps the
|
|
216
|
+
// selection and `esc` discards it.
|
|
217
|
+
const LINKED_CANDIDATE_KEYS = [
|
|
218
|
+
{ key: 'space', text: 'space toggle', short: 'space', priority: 70 },
|
|
219
|
+
...scrollKeys.previewScrollKeys(),
|
|
220
|
+
{ key: 'enter', text: 'enter keep', short: 'enter', priority: 90 },
|
|
221
|
+
{ key: 'esc', text: 'esc discard', short: 'esc discard', priority: 100 },
|
|
198
222
|
];
|
|
199
223
|
|
|
200
224
|
// S11: while an editor's own list is still in flight its handlers accept ONE
|
|
@@ -401,6 +425,33 @@ function normalizeDetail(result) {
|
|
|
401
425
|
return { ok: false, error: 'pull request unreadable' };
|
|
402
426
|
}
|
|
403
427
|
|
|
428
|
+
// T20: one candidate page from `loadIssueCandidates`. The list only ever shows
|
|
429
|
+
// OPEN issues by number and title, so a row without a usable number is dropped
|
|
430
|
+
// instead of painted, and a page that claims more without a cursor is honestly
|
|
431
|
+
// the end (a cursorless `hasMore` could never advance).
|
|
432
|
+
function normalizeIssueCandidatePage(result) {
|
|
433
|
+
if (!result || typeof result !== 'object') return { ok: false, error: 'issues unreadable' };
|
|
434
|
+
if (result.ok === false) return { ok: false, error: String(result.error || result.loadError || 'issues unreadable') };
|
|
435
|
+
if (!Array.isArray(result.rows)) return { ok: false, error: 'issues unreadable: unexpected result' };
|
|
436
|
+
const rows = [];
|
|
437
|
+
for (const row of result.rows) {
|
|
438
|
+
const number = Number(row && row.number);
|
|
439
|
+
if (!Number.isInteger(number) || number <= 0) continue;
|
|
440
|
+
const state = String((row && row.state) || 'open').toLowerCase();
|
|
441
|
+
if (state !== 'open') continue;
|
|
442
|
+
rows.push({ number, title: typeof row.title === 'string' ? row.title : '' });
|
|
443
|
+
}
|
|
444
|
+
const cursor = typeof result.cursor === 'string' && result.cursor !== '' ? result.cursor : null;
|
|
445
|
+
return { ok: true, rows, hasMore: result.hasMore === true && cursor !== null, cursor };
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// T20: one issue row, always `#<number>` and the title when the seam answered
|
|
449
|
+
// one — never a bare number in either the toggles or the candidate list.
|
|
450
|
+
function issueRowText(number, title) {
|
|
451
|
+
const text = typeof title === 'string' ? title.trim() : '';
|
|
452
|
+
return text === '' ? `#${number}` : `#${number} ${text}`;
|
|
453
|
+
}
|
|
454
|
+
|
|
404
455
|
// S2: the methods the repository actually allows, in the order the merge step
|
|
405
456
|
// offers them. Anything but a literal `true` allows nothing.
|
|
406
457
|
function allowedMergeMethods(pullRequest) {
|
|
@@ -465,6 +516,7 @@ function createPrsView(options = {}) {
|
|
|
465
516
|
loadPullRequestPage = null,
|
|
466
517
|
loadLabels = null,
|
|
467
518
|
loadAssignees = null,
|
|
519
|
+
loadIssueCandidates = null,
|
|
468
520
|
permissions: viewPermissions = null,
|
|
469
521
|
actions = {},
|
|
470
522
|
scheduleQuery = null,
|
|
@@ -472,6 +524,7 @@ function createPrsView(options = {}) {
|
|
|
472
524
|
} = options;
|
|
473
525
|
|
|
474
526
|
const pageLoaderFn = typeof loadPullRequestPage === 'function' ? loadPullRequestPage : null;
|
|
527
|
+
const candidateLoaderFn = typeof loadIssueCandidates === 'function' ? loadIssueCandidates : null;
|
|
475
528
|
const serverMode = pageLoaderFn !== null;
|
|
476
529
|
const scheduleFn = typeof scheduleQuery === 'function' ? scheduleQuery : (fn, delay) => setTimeout(fn, delay);
|
|
477
530
|
const cancelFn = typeof cancelSchedule === 'function' ? cancelSchedule : (handle) => clearTimeout(handle);
|
|
@@ -528,6 +581,9 @@ function createPrsView(options = {}) {
|
|
|
528
581
|
searchPending: false,
|
|
529
582
|
};
|
|
530
583
|
let bodyRows = 1;
|
|
584
|
+
// T20: the painted pane width, so the candidate list can measure the wrapped
|
|
585
|
+
// height of a row from a key handler and keep its focus inside the window.
|
|
586
|
+
let rightWidthCache = 20;
|
|
531
587
|
const prefetchBuckets = options.prefetchBuckets === true;
|
|
532
588
|
const details = new Map();
|
|
533
589
|
// S2/D25: how many detail reads each number has seen. Only the NEWEST read
|
|
@@ -558,6 +614,13 @@ function createPrsView(options = {}) {
|
|
|
558
614
|
// S6: the last painted frame and the click ranges it published, so a mouse
|
|
559
615
|
// event is answered against what the reader actually sees.
|
|
560
616
|
let frame = { width: 0, height: 0, ranges: [] };
|
|
617
|
+
// S6: the linked issue number the pointer is over, if any. It is set from the
|
|
618
|
+
// SAME hit test a click uses, so the pane can never highlight a cell it would
|
|
619
|
+
// not open, and it is cleared by a move that lands nowhere. `hoverPullRequest`
|
|
620
|
+
// is the item that pane painted, so navigating to another pull request cannot
|
|
621
|
+
// leave a highlight behind on a number the pointer never visited there.
|
|
622
|
+
let hoverNumber = null;
|
|
623
|
+
let hoverPullRequest = null;
|
|
561
624
|
|
|
562
625
|
const numOf = (row) => (row && row.number != null ? Number(row.number) : NaN);
|
|
563
626
|
|
|
@@ -1165,7 +1228,7 @@ function createPrsView(options = {}) {
|
|
|
1165
1228
|
|
|
1166
1229
|
// S6: the published ranges are the preview's own, so the click targets are the
|
|
1167
1230
|
// numbers it painted — never a search of the rendered text.
|
|
1168
|
-
function detailLines(row, width, links) {
|
|
1231
|
+
function detailLines(row, width, links, hover = null) {
|
|
1169
1232
|
const entry = ensurePullRequest(row);
|
|
1170
1233
|
if (!entry) return [paint(theme, 'muted', '(no pull request selected)')];
|
|
1171
1234
|
if (entry.status === 'error') return [paint(theme, 'error', `unreadable: ${entry.error}`)];
|
|
@@ -1190,6 +1253,9 @@ function createPrsView(options = {}) {
|
|
|
1190
1253
|
wrap,
|
|
1191
1254
|
links,
|
|
1192
1255
|
measure: (text) => measure(helpers, text),
|
|
1256
|
+
// S6: the hovered number is the same formatter's target, so the painted
|
|
1257
|
+
// highlight and the clickable cell are one answer.
|
|
1258
|
+
hover,
|
|
1193
1259
|
});
|
|
1194
1260
|
}
|
|
1195
1261
|
|
|
@@ -1202,7 +1268,11 @@ function createPrsView(options = {}) {
|
|
|
1202
1268
|
if (state.mode === 'assignees') return assigneesLoading ? BACK_KEYS : ASSIGNEE_EDITOR_KEYS;
|
|
1203
1269
|
if (state.mode === 'comment') return state.discardAsk ? COMMENT_DISCARD_KEYS : COMMENT_EDITOR_KEYS;
|
|
1204
1270
|
if (state.mode === 'merge') return MERGE_KEYS;
|
|
1205
|
-
if (state.mode === 'linkedIssues')
|
|
1271
|
+
if (state.mode === 'linkedIssues') {
|
|
1272
|
+
if (!linkedDraft || linkedDraft.view === 'toggles') return LINKED_EDITOR_KEYS;
|
|
1273
|
+
if (linkedDraft.candidatesLoading && linkedDraft.candidates.length === 0) return BACK_KEYS;
|
|
1274
|
+
return LINKED_CANDIDATE_KEYS;
|
|
1275
|
+
}
|
|
1206
1276
|
return null;
|
|
1207
1277
|
}
|
|
1208
1278
|
|
|
@@ -1235,6 +1305,7 @@ function createPrsView(options = {}) {
|
|
|
1235
1305
|
const listWidth = panes.left;
|
|
1236
1306
|
const rightWidth = panes.right;
|
|
1237
1307
|
listWidthCache = listWidth;
|
|
1308
|
+
rightWidthCache = rightWidth;
|
|
1238
1309
|
bodyRows = Math.max(1, height - 6);
|
|
1239
1310
|
const border = (text) => paint(theme, 'border', text);
|
|
1240
1311
|
const divider = border('│');
|
|
@@ -1360,7 +1431,8 @@ function createPrsView(options = {}) {
|
|
|
1360
1431
|
rightSource = [paint(theme, 'muted', 'no pull requests'), paint(theme, 'dim', 'nothing to show here')];
|
|
1361
1432
|
}
|
|
1362
1433
|
} else {
|
|
1363
|
-
|
|
1434
|
+
const paneHover = hoverPullRequest !== null && hoverPullRequest === numOf(focused) ? hoverNumber : null;
|
|
1435
|
+
rightSource = detailLines(focused, rightWidth, paneLinks, paneHover);
|
|
1364
1436
|
}
|
|
1365
1437
|
clampScroll(rightSource.length);
|
|
1366
1438
|
const visible = rightSource.slice(state.scroll, state.scroll + bodyRows);
|
|
@@ -1670,21 +1742,133 @@ function createPrsView(options = {}) {
|
|
|
1670
1742
|
state.mergeField = offered[(from + step + offered.length) % offered.length];
|
|
1671
1743
|
}
|
|
1672
1744
|
|
|
1745
|
+
// T20: the candidate rows, in the ONE order the list paints: the numbers the
|
|
1746
|
+
// draft already holds first (ascending, so the pull request's own links keep
|
|
1747
|
+
// their familiar order), then every other page row in the seam's own
|
|
1748
|
+
// hottest-updated order. A number that is already listed is never repeated.
|
|
1749
|
+
function linkedCandidateRows() {
|
|
1750
|
+
if (!linkedDraft) return [];
|
|
1751
|
+
const rows = [];
|
|
1752
|
+
const seen = new Set();
|
|
1753
|
+
const numbers = linkedDraft.numbers.slice().sort((left, right) => left - right);
|
|
1754
|
+
for (const number of numbers) {
|
|
1755
|
+
if (seen.has(number)) continue;
|
|
1756
|
+
seen.add(number);
|
|
1757
|
+
rows.push({ number, title: linkedDraft.titles.get(number) || '' });
|
|
1758
|
+
}
|
|
1759
|
+
for (const row of linkedDraft.candidates) {
|
|
1760
|
+
if (seen.has(row.number)) continue;
|
|
1761
|
+
seen.add(row.number);
|
|
1762
|
+
rows.push({ number: row.number, title: row.title });
|
|
1763
|
+
}
|
|
1764
|
+
return rows;
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
// T20: the candidate pane, built once for painting AND for the focus window so
|
|
1768
|
+
// the two can never disagree about how many lines a wrapped title costs.
|
|
1769
|
+
function linkedCandidateView(width) {
|
|
1770
|
+
const box = { lines: [], starts: [], heights: [] };
|
|
1771
|
+
const out = [emphasize(theme, 'Add issues')];
|
|
1772
|
+
const rows = linkedCandidateRows();
|
|
1773
|
+
if (linkedDraft.candidatesLoading && rows.length === 0) {
|
|
1774
|
+
out.push(paint(theme, 'muted', 'loading issues…'));
|
|
1775
|
+
box.lines = out;
|
|
1776
|
+
return box;
|
|
1777
|
+
}
|
|
1778
|
+
if (linkedDraft.candidatesError) out.push(paint(theme, 'error', `issues unreadable: ${linkedDraft.candidatesError}`));
|
|
1779
|
+
if (rows.length === 0) out.push(paint(theme, 'muted', 'no open issues'));
|
|
1780
|
+
rows.forEach((row, at) => {
|
|
1781
|
+
const on = linkedDraft.selected.has(row.number);
|
|
1782
|
+
const cursor = at === linkedDraft.candidateIndex ? '▸ ' : ' ';
|
|
1783
|
+
const painted = wrapText(`${cursor}[${on ? 'x' : ' '}] ${issueRowText(row.number, row.title)}`, width);
|
|
1784
|
+
box.starts.push(out.length);
|
|
1785
|
+
box.heights.push(painted.length);
|
|
1786
|
+
out.push(...painted);
|
|
1787
|
+
});
|
|
1788
|
+
if (linkedDraft.candidatesLoading && rows.length > 0) out.push(paint(theme, 'muted', 'loading more issues…'));
|
|
1789
|
+
box.lines = out;
|
|
1790
|
+
return box;
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1673
1793
|
function linkedIssuesLines(width) {
|
|
1794
|
+
if (!linkedDraft) return [emphasize(theme, 'Linked issues')];
|
|
1795
|
+
if (linkedDraft.view === 'candidates') return linkedCandidateView(width).lines;
|
|
1674
1796
|
const out = [emphasize(theme, 'Linked issues')];
|
|
1675
|
-
if (
|
|
1797
|
+
if (linkedDraft.candidatesError) out.push(paint(theme, 'error', `issues unreadable: ${linkedDraft.candidatesError}`));
|
|
1676
1798
|
if (linkedDraft.numbers.length === 0) out.push(paint(theme, 'muted', 'no linked issues'));
|
|
1677
1799
|
linkedDraft.numbers.forEach((number, at) => {
|
|
1678
1800
|
const on = linkedDraft.selected.has(number);
|
|
1679
1801
|
const cursor = at === linkedDraft.index ? '▸ ' : ' ';
|
|
1680
|
-
out.push(`${cursor}[${on ? 'x' : ' '}]
|
|
1802
|
+
out.push(...wrapText(`${cursor}[${on ? 'x' : ' '}] ${issueRowText(number, linkedDraft.titles.get(number) || '')}`, width));
|
|
1681
1803
|
});
|
|
1682
|
-
if (linkedDraft.adding) out.push(...fieldRows(`#${linkedDraft.input}`, true, width));
|
|
1683
1804
|
out.push(...wrapText('closes #N lines in the body', width));
|
|
1684
1805
|
if (actionError) out.push(paint(theme, 'error', actionError));
|
|
1685
1806
|
return out;
|
|
1686
1807
|
}
|
|
1687
1808
|
|
|
1809
|
+
// T20: ONE cursor page of the repository's open issues through the injected
|
|
1810
|
+
// seam, read once when the editor opens (for the titles of the links it
|
|
1811
|
+
// already holds) and again, appended, as the candidate list scrolls. Only the
|
|
1812
|
+
// newest read for the draft may paint. A page is the pane's row budget,
|
|
1813
|
+
// derived from the frame the same way `bodyRows` is, so the seam is asked for
|
|
1814
|
+
// a page the pane can actually show even before the first repaint.
|
|
1815
|
+
function candidatePageSize() {
|
|
1816
|
+
return Math.max(1, Math.min(100, availableRows() - 6));
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
function requestIssueCandidates(draft, requestOptions = {}) {
|
|
1820
|
+
if (!draft || candidateLoaderFn === null) return false;
|
|
1821
|
+
const append = Boolean(requestOptions) && requestOptions.append === true;
|
|
1822
|
+
if (append) {
|
|
1823
|
+
if (!draft.candidatesLoaded || draft.candidatesLoading || !draft.candidatesHasMore
|
|
1824
|
+
|| draft.candidatesCursor === null) return false;
|
|
1825
|
+
} else if (draft.candidatesLoading || draft.candidatesLoaded) {
|
|
1826
|
+
return false;
|
|
1827
|
+
}
|
|
1828
|
+
const after = append ? draft.candidatesCursor : null;
|
|
1829
|
+
const seq = draft.candidateSeq + 1;
|
|
1830
|
+
draft.candidateSeq = seq;
|
|
1831
|
+
draft.candidatesLoading = true;
|
|
1832
|
+
draft.candidatesError = null;
|
|
1833
|
+
repaint();
|
|
1834
|
+
let pending = null;
|
|
1835
|
+
try {
|
|
1836
|
+
pending = candidateLoaderFn({ after, pageSize: candidatePageSize() });
|
|
1837
|
+
} catch (err) {
|
|
1838
|
+
pending = { ok: false, error: (err && err.message) || 'issues unreadable' };
|
|
1839
|
+
}
|
|
1840
|
+
const settle = (result) => {
|
|
1841
|
+
if (!active || draft.candidateSeq !== seq) return;
|
|
1842
|
+
draft.candidatesLoading = false;
|
|
1843
|
+
const normalized = normalizeIssueCandidatePage(result);
|
|
1844
|
+
if (!normalized.ok) {
|
|
1845
|
+
draft.candidatesError = normalized.error;
|
|
1846
|
+
repaint();
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1849
|
+
for (const row of normalized.rows) {
|
|
1850
|
+
if (!draft.titles.has(row.number)) draft.titles.set(row.number, row.title);
|
|
1851
|
+
}
|
|
1852
|
+
const held = append ? draft.candidates.slice() : [];
|
|
1853
|
+
const seen = new Set(held.map((row) => row.number));
|
|
1854
|
+
for (const row of normalized.rows) {
|
|
1855
|
+
if (seen.has(row.number)) continue;
|
|
1856
|
+
seen.add(row.number);
|
|
1857
|
+
held.push(row);
|
|
1858
|
+
}
|
|
1859
|
+
draft.candidates = held;
|
|
1860
|
+
draft.candidatesHasMore = normalized.hasMore;
|
|
1861
|
+
draft.candidatesCursor = normalized.cursor;
|
|
1862
|
+
draft.candidatesLoaded = true;
|
|
1863
|
+
draft.candidatesError = null;
|
|
1864
|
+
repaint();
|
|
1865
|
+
};
|
|
1866
|
+
Promise.resolve(pending).then(settle).catch((err) => {
|
|
1867
|
+
settle({ ok: false, error: (err && err.message) || 'issues unreadable' });
|
|
1868
|
+
});
|
|
1869
|
+
return true;
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1688
1872
|
function openMerge() {
|
|
1689
1873
|
const row = selected();
|
|
1690
1874
|
if (!row) return;
|
|
@@ -1740,12 +1924,26 @@ function createPrsView(options = {}) {
|
|
|
1740
1924
|
index: 0,
|
|
1741
1925
|
selected: new Set(numbers),
|
|
1742
1926
|
original: new Set(numbers),
|
|
1743
|
-
|
|
1744
|
-
|
|
1927
|
+
// T20: the number→title answers the seam already gave, so the toggles and
|
|
1928
|
+
// the candidate list name every issue the same way.
|
|
1929
|
+
titles: new Map(),
|
|
1930
|
+
view: 'toggles',
|
|
1931
|
+
candidateIndex: 0,
|
|
1932
|
+
candidates: [],
|
|
1933
|
+
candidatesLoaded: false,
|
|
1934
|
+
candidatesLoading: false,
|
|
1935
|
+
candidatesError: null,
|
|
1936
|
+
candidatesHasMore: false,
|
|
1937
|
+
candidatesCursor: null,
|
|
1938
|
+
candidateSeq: 0,
|
|
1939
|
+
candidateBase: null,
|
|
1745
1940
|
};
|
|
1746
1941
|
state.mode = 'linkedIssues';
|
|
1747
1942
|
actionError = null;
|
|
1748
1943
|
state.scroll = 0;
|
|
1944
|
+
// T20: the links' titles are read ONCE, through the same candidate seam; a
|
|
1945
|
+
// failure paints its error and leaves the toggles exactly as they are.
|
|
1946
|
+
requestIssueCandidates(linkedDraft);
|
|
1749
1947
|
repaint();
|
|
1750
1948
|
}
|
|
1751
1949
|
|
|
@@ -2171,24 +2369,121 @@ function createPrsView(options = {}) {
|
|
|
2171
2369
|
);
|
|
2172
2370
|
}
|
|
2173
2371
|
|
|
2174
|
-
|
|
2372
|
+
// T20: the candidate list `n` opens. The draft's own links keep their place and
|
|
2373
|
+
// their checked state at the top, and `esc` restores this exact snapshot.
|
|
2374
|
+
function openCandidateList() {
|
|
2375
|
+
if (!linkedDraft || linkedDraft.view === 'candidates') return;
|
|
2376
|
+
linkedDraft.view = 'candidates';
|
|
2377
|
+
linkedDraft.candidateBase = {
|
|
2378
|
+
numbers: linkedDraft.numbers.slice(),
|
|
2379
|
+
selected: new Set(linkedDraft.selected),
|
|
2380
|
+
};
|
|
2381
|
+
linkedDraft.candidateIndex = 0;
|
|
2382
|
+
state.scroll = 0;
|
|
2383
|
+
actionError = null;
|
|
2384
|
+
// A failed first read is retried here instead of frozen: `candidatesLoaded`
|
|
2385
|
+
// only becomes true on a successful answer.
|
|
2386
|
+
requestIssueCandidates(linkedDraft);
|
|
2387
|
+
revealCandidate();
|
|
2388
|
+
repaint();
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
function closeCandidateList(keep) {
|
|
2175
2392
|
if (!linkedDraft) return;
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
if (!Number.isFinite(number) || number <= 0) {
|
|
2180
|
-
actionError = 'a linked issue needs a number';
|
|
2181
|
-
repaint();
|
|
2182
|
-
return;
|
|
2393
|
+
if (!keep && linkedDraft.candidateBase) {
|
|
2394
|
+
linkedDraft.numbers = linkedDraft.candidateBase.numbers.slice();
|
|
2395
|
+
linkedDraft.selected = new Set(linkedDraft.candidateBase.selected);
|
|
2183
2396
|
}
|
|
2184
|
-
|
|
2185
|
-
linkedDraft.
|
|
2186
|
-
linkedDraft.
|
|
2187
|
-
|
|
2397
|
+
linkedDraft.candidateBase = null;
|
|
2398
|
+
linkedDraft.view = 'toggles';
|
|
2399
|
+
linkedDraft.index = 0;
|
|
2400
|
+
state.scroll = 0;
|
|
2188
2401
|
actionError = null;
|
|
2189
2402
|
repaint();
|
|
2190
2403
|
}
|
|
2191
2404
|
|
|
2405
|
+
// The draft's numbers stay sorted and unique, so a number the pull request
|
|
2406
|
+
// already links is toggled in place and never added a second time.
|
|
2407
|
+
function toggleLinkedNumber(number) {
|
|
2408
|
+
if (!linkedDraft || !Number.isInteger(number)) return;
|
|
2409
|
+
if (linkedDraft.selected.has(number)) {
|
|
2410
|
+
linkedDraft.selected.delete(number);
|
|
2411
|
+
} else {
|
|
2412
|
+
linkedDraft.selected.add(number);
|
|
2413
|
+
if (!linkedDraft.numbers.includes(number)) {
|
|
2414
|
+
linkedDraft.numbers.push(number);
|
|
2415
|
+
linkedDraft.numbers.sort((left, right) => left - right);
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
if (linkedDraft.index >= linkedDraft.numbers.length) {
|
|
2419
|
+
linkedDraft.index = Math.max(0, linkedDraft.numbers.length - 1);
|
|
2420
|
+
}
|
|
2421
|
+
repaint();
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
function toggleCandidate() {
|
|
2425
|
+
const row = linkedCandidateRows()[linkedDraft.candidateIndex];
|
|
2426
|
+
if (!row) return;
|
|
2427
|
+
toggleLinkedNumber(row.number);
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
// The candidate focus and the painted window stay together: moving the focus
|
|
2431
|
+
// scrolls the pane to it, and scrolling the pane moves the focus to the first
|
|
2432
|
+
// row on screen.
|
|
2433
|
+
function revealCandidate() {
|
|
2434
|
+
if (!linkedDraft || linkedDraft.view !== 'candidates') return;
|
|
2435
|
+
const box = linkedCandidateView(Math.max(1, rightWidthCache));
|
|
2436
|
+
if (box.starts.length === 0) return;
|
|
2437
|
+
const at = Math.max(0, Math.min(linkedDraft.candidateIndex, box.starts.length - 1));
|
|
2438
|
+
const top = box.starts[at];
|
|
2439
|
+
const height = box.heights[at] || 1;
|
|
2440
|
+
const room = Math.max(1, bodyRows);
|
|
2441
|
+
if (top < state.scroll) state.scroll = top;
|
|
2442
|
+
else if (top + height > state.scroll + room) state.scroll = Math.max(0, top + height - room);
|
|
2443
|
+
}
|
|
2444
|
+
|
|
2445
|
+
function focusVisibleCandidate() {
|
|
2446
|
+
if (!linkedDraft || linkedDraft.view !== 'candidates') return;
|
|
2447
|
+
const box = linkedCandidateView(Math.max(1, rightWidthCache));
|
|
2448
|
+
if (box.starts.length === 0) return;
|
|
2449
|
+
const room = Math.max(1, bodyRows);
|
|
2450
|
+
const current = Math.max(0, Math.min(linkedDraft.candidateIndex, box.starts.length - 1));
|
|
2451
|
+
if (box.starts[current] >= state.scroll && box.starts[current] < state.scroll + room) {
|
|
2452
|
+
linkedDraft.candidateIndex = current;
|
|
2453
|
+
return;
|
|
2454
|
+
}
|
|
2455
|
+
let at = 0;
|
|
2456
|
+
for (let index = 0; index < box.starts.length; index += 1) {
|
|
2457
|
+
at = index;
|
|
2458
|
+
if (box.starts[index] >= state.scroll) break;
|
|
2459
|
+
}
|
|
2460
|
+
linkedDraft.candidateIndex = at;
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
function moveCandidate(step) {
|
|
2464
|
+
const rows = linkedCandidateRows();
|
|
2465
|
+
if (rows.length === 0) return;
|
|
2466
|
+
linkedDraft.candidateIndex = Math.max(0, Math.min(rows.length - 1, linkedDraft.candidateIndex + step));
|
|
2467
|
+
if (step > 0 && linkedDraft.candidateIndex === rows.length - 1) {
|
|
2468
|
+
requestIssueCandidates(linkedDraft, { append: true });
|
|
2469
|
+
}
|
|
2470
|
+
revealCandidate();
|
|
2471
|
+
repaint();
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
// The panel's own scroll keys move the candidate window exactly like they move
|
|
2475
|
+
// the pane, and a downward step asks the seam for the next page.
|
|
2476
|
+
function scrollCandidate(action) {
|
|
2477
|
+
if (!linkedDraft) return;
|
|
2478
|
+
const page = Math.max(1, bodyRows - 1);
|
|
2479
|
+
const half = action === scrollKeys.ACTIONS.HALF_DOWN || action === scrollKeys.ACTIONS.HALF_UP;
|
|
2480
|
+
const down = action === scrollKeys.ACTIONS.PAGE_DOWN || action === scrollKeys.ACTIONS.HALF_DOWN;
|
|
2481
|
+
state.scroll = Math.max(0, state.scroll + (down ? 1 : -1) * (half ? Math.max(1, Math.floor(page / 2)) : page));
|
|
2482
|
+
if (down) requestIssueCandidates(linkedDraft, { append: true });
|
|
2483
|
+
focusVisibleCandidate();
|
|
2484
|
+
repaint();
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2192
2487
|
// ---- search ------------------------------------------------------------
|
|
2193
2488
|
|
|
2194
2489
|
function scheduleQueryRead(query) {
|
|
@@ -2562,35 +2857,57 @@ function createPrsView(options = {}) {
|
|
|
2562
2857
|
return true;
|
|
2563
2858
|
}
|
|
2564
2859
|
|
|
2860
|
+
// T20: the candidate list's own keys — the panel's scroll bindings, `space` on
|
|
2861
|
+
// the focused row, `enter` to keep the selection and `esc` to discard it.
|
|
2862
|
+
function handleCandidateInput(data) {
|
|
2863
|
+
if (linkedDraft.candidatesLoading && linkedCandidateRows().length === 0) {
|
|
2864
|
+
if (keyMatches(helpers, data, ['escape'])) closeCandidateList(false);
|
|
2865
|
+
return true;
|
|
2866
|
+
}
|
|
2867
|
+
if (keyMatches(helpers, data, ['escape'])) {
|
|
2868
|
+
closeCandidateList(false);
|
|
2869
|
+
return true;
|
|
2870
|
+
}
|
|
2871
|
+
if (keyMatches(helpers, data, ['enter'])) {
|
|
2872
|
+
closeCandidateList(true);
|
|
2873
|
+
return true;
|
|
2874
|
+
}
|
|
2875
|
+
if (keyMatches(helpers, data, ['space', ' '])) {
|
|
2876
|
+
toggleCandidate();
|
|
2877
|
+
return true;
|
|
2878
|
+
}
|
|
2879
|
+
if (keyMatches(helpers, data, ['up', 'k'])) {
|
|
2880
|
+
moveCandidate(-1);
|
|
2881
|
+
return true;
|
|
2882
|
+
}
|
|
2883
|
+
if (keyMatches(helpers, data, ['down', 'j'])) {
|
|
2884
|
+
moveCandidate(1);
|
|
2885
|
+
return true;
|
|
2886
|
+
}
|
|
2887
|
+
const scrollAction = scrollKeys.resolveScrollAction(helpers, data);
|
|
2888
|
+
if (scrollAction) {
|
|
2889
|
+
scrollCandidate(scrollAction);
|
|
2890
|
+
return true;
|
|
2891
|
+
}
|
|
2892
|
+
// The list pane's own paging pair, so the candidate list scrolls with the
|
|
2893
|
+
// same keys even on a host with no scroll bindings.
|
|
2894
|
+
if (keyMatches(helpers, data, [']'])) {
|
|
2895
|
+
scrollCandidate(scrollKeys.ACTIONS.PAGE_DOWN);
|
|
2896
|
+
return true;
|
|
2897
|
+
}
|
|
2898
|
+
if (keyMatches(helpers, data, ['['])) {
|
|
2899
|
+
scrollCandidate(scrollKeys.ACTIONS.PAGE_UP);
|
|
2900
|
+
return true;
|
|
2901
|
+
}
|
|
2902
|
+
return true;
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2565
2905
|
function handleLinkedInput(data) {
|
|
2566
2906
|
if (!linkedDraft) {
|
|
2567
2907
|
state.mode = 'list';
|
|
2568
2908
|
return true;
|
|
2569
2909
|
}
|
|
2570
|
-
if (linkedDraft.
|
|
2571
|
-
if (keyMatches(helpers, data, ['enter'])) {
|
|
2572
|
-
commitLinkedInput();
|
|
2573
|
-
return true;
|
|
2574
|
-
}
|
|
2575
|
-
if (keyMatches(helpers, data, ['escape'])) {
|
|
2576
|
-
linkedDraft.adding = false;
|
|
2577
|
-
linkedDraft.input = '';
|
|
2578
|
-
actionError = null;
|
|
2579
|
-
repaint();
|
|
2580
|
-
return true;
|
|
2581
|
-
}
|
|
2582
|
-
if (keyMatches(helpers, data, ['backspace'])) {
|
|
2583
|
-
linkedDraft.input = linkedDraft.input.slice(0, -1);
|
|
2584
|
-
repaint();
|
|
2585
|
-
return true;
|
|
2586
|
-
}
|
|
2587
|
-
if (typeof data === 'string' && /^[0-9]$/.test(data)) {
|
|
2588
|
-
linkedDraft.input += data;
|
|
2589
|
-
repaint();
|
|
2590
|
-
return true;
|
|
2591
|
-
}
|
|
2592
|
-
return true;
|
|
2593
|
-
}
|
|
2910
|
+
if (linkedDraft.view === 'candidates') return handleCandidateInput(data);
|
|
2594
2911
|
if (keyMatches(helpers, data, ['ctrl+s'])) {
|
|
2595
2912
|
applyLinkedIssues();
|
|
2596
2913
|
return true;
|
|
@@ -2615,18 +2932,11 @@ function createPrsView(options = {}) {
|
|
|
2615
2932
|
}
|
|
2616
2933
|
if (keyMatches(helpers, data, ['space', ' ', 'enter'])) {
|
|
2617
2934
|
const number = linkedDraft.numbers[linkedDraft.index];
|
|
2618
|
-
if (number !== undefined)
|
|
2619
|
-
if (linkedDraft.selected.has(number)) linkedDraft.selected.delete(number);
|
|
2620
|
-
else linkedDraft.selected.add(number);
|
|
2621
|
-
}
|
|
2622
|
-
repaint();
|
|
2935
|
+
if (number !== undefined) toggleLinkedNumber(number);
|
|
2623
2936
|
return true;
|
|
2624
2937
|
}
|
|
2625
2938
|
if (keyMatches(helpers, data, ['n'])) {
|
|
2626
|
-
|
|
2627
|
-
linkedDraft.input = '';
|
|
2628
|
-
actionError = null;
|
|
2629
|
-
repaint();
|
|
2939
|
+
openCandidateList();
|
|
2630
2940
|
return true;
|
|
2631
2941
|
}
|
|
2632
2942
|
return true;
|
|
@@ -2850,18 +3160,39 @@ function createPrsView(options = {}) {
|
|
|
2850
3160
|
// S6: a click inside one published range opens exactly that linked issue in
|
|
2851
3161
|
// the other panel. Anything else — a wheel notch, a press, a cell between two
|
|
2852
3162
|
// numbers — stays unhandled, so the host keeps its own mouse behavior.
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
3163
|
+
// S6: the ONE hit test both the click and the hover answer with, mapped
|
|
3164
|
+
// against the frame the reader last painted (its columns, rows and scroll
|
|
3165
|
+
// offset included), so a number can never be hoverable without being
|
|
3166
|
+
// clickable — or the other way round.
|
|
3167
|
+
function hitRange(event) {
|
|
3168
|
+
if (!event || typeof event !== 'object') return null;
|
|
2857
3169
|
const width = Number(event.width);
|
|
2858
3170
|
const height = Number(event.height);
|
|
2859
|
-
if (Number.isFinite(width) && width !== frame.width) return
|
|
2860
|
-
if (Number.isFinite(height) && height !== frame.height) return
|
|
3171
|
+
if (Number.isFinite(width) && width !== frame.width) return null;
|
|
3172
|
+
if (Number.isFinite(height) && height !== frame.height) return null;
|
|
2861
3173
|
const x = Number(event.x);
|
|
2862
3174
|
const y = Number(event.y);
|
|
2863
|
-
if (!Number.isFinite(x) || !Number.isFinite(y)) return
|
|
2864
|
-
|
|
3175
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return null;
|
|
3176
|
+
return frame.ranges.find((range) => range.y === y && x >= range.startX && x < range.endX) || null;
|
|
3177
|
+
}
|
|
3178
|
+
|
|
3179
|
+
// A left click on one linked issue number opens `/issues` on it, and a `move`
|
|
3180
|
+
// over one highlights it (a move that lands nowhere clears it, repainting
|
|
3181
|
+
// only when the target changes).
|
|
3182
|
+
function handleMouse(event) {
|
|
3183
|
+
if (!active || !event || typeof event !== 'object') return undefined;
|
|
3184
|
+
if (event.type === 'move') {
|
|
3185
|
+
const hit = hitRange(event);
|
|
3186
|
+
const next = hit === null ? null : hit.number;
|
|
3187
|
+
const changed = next !== hoverNumber;
|
|
3188
|
+
hoverNumber = next;
|
|
3189
|
+
hoverPullRequest = next === null ? null : numOf(selected());
|
|
3190
|
+
if (changed) repaint();
|
|
3191
|
+
return { handled: true, render: changed };
|
|
3192
|
+
}
|
|
3193
|
+
if (event.type !== 'click' || event.button !== 'left') return undefined;
|
|
3194
|
+
if (frame.ranges.length === 0) return undefined;
|
|
3195
|
+
const hit = hitRange(event);
|
|
2865
3196
|
if (!hit) return undefined;
|
|
2866
3197
|
const openLinked = actionFor(['openLinked']);
|
|
2867
3198
|
if (openLinked === null) return undefined;
|
|
@@ -2875,6 +3206,8 @@ function createPrsView(options = {}) {
|
|
|
2875
3206
|
|
|
2876
3207
|
function invalidate() {
|
|
2877
3208
|
frame = { width: 0, height: 0, ranges: [] };
|
|
3209
|
+
hoverNumber = null;
|
|
3210
|
+
hoverPullRequest = null;
|
|
2878
3211
|
}
|
|
2879
3212
|
|
|
2880
3213
|
ensurePullRequest(selected());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.1",
|
|
4
4
|
"description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
package/tools/gh-prs.test.js
CHANGED
|
@@ -180,7 +180,11 @@ describe('the three buckets read through the repository search', () => {
|
|
|
180
180
|
});
|
|
181
181
|
|
|
182
182
|
test('the review and involved buckets carry their own qualifier', async () => {
|
|
183
|
-
|
|
183
|
+
// S1: `involved` excludes what you AUTHORED, exactly as the issues reader
|
|
184
|
+
// does (`involves:@me -author:@me`). GitHub's `involves:@me` includes your
|
|
185
|
+
// own pull requests, and repeating them under `Involved` hides the ones you
|
|
186
|
+
// are merely part of.
|
|
187
|
+
for (const [bucket, qualifier] of [['review', 'review-requested:@me'], ['involved', 'involves:@me -author:@me']]) {
|
|
184
188
|
const { runner, calls } = makeRunner(okJson(fixture('gh-pr-search-page.json')));
|
|
185
189
|
ghPrs.setGhRunner(runner);
|
|
186
190
|
|