@cueloop/client 0.1.0-alpha.7 → 0.1.0-alpha.70
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/native/build-pty.sh +51 -0
- package/native/build.sh +82 -0
- package/native/darwin-arm64/libcuelooppty.dylib +0 -0
- package/native/darwin-arm64/libcueloopvt.dylib +0 -0
- package/native/src/pty.zig +193 -0
- package/native/src/shim.zig +114 -0
- package/package.json +39 -32
- package/src/App.appearance.test.tsx +53 -0
- package/src/App.autoclose.test.tsx +76 -50
- package/src/App.diff.test.tsx +156 -42
- package/src/App.export.test.tsx +58 -40
- package/src/App.plan-review.test.tsx +363 -0
- package/src/App.prototype-markdown.test.tsx +92 -0
- package/src/App.prototype.test.tsx +176 -0
- package/src/App.readonly.test.tsx +128 -67
- package/src/App.rendering.test.tsx +61 -35
- package/src/App.submit-confirm.test.tsx +191 -0
- package/src/App.test.tsx +310 -114
- package/src/App.toast.test.tsx +89 -0
- package/src/App.tsx +1039 -799
- package/src/App.walk.test.tsx +298 -0
- package/src/App.workbench.test.tsx +461 -0
- package/src/__snapshots__/view-plan.regression.test.ts.snap +100 -0
- package/src/annotation-palette.ts +61 -0
- package/src/app-key-state.ts +61 -0
- package/src/app-screens.tsx +432 -0
- package/src/app-view-model.ts +159 -0
- package/src/attribution.test.ts +31 -0
- package/src/attribution.ts +42 -0
- package/src/clipboard.test.ts +23 -0
- package/src/clipboard.ts +33 -0
- package/src/components/AnnotatableFileView.stories.tsx +42 -0
- package/src/components/AnnotatableFileView.test.tsx +102 -0
- package/src/components/AnnotatableFileView.tsx +126 -0
- package/src/components/AnnotationCards.stories.tsx +87 -0
- package/src/components/AnnotationCards.tsx +303 -0
- package/src/components/AppHeader.stories.tsx +50 -0
- package/src/components/AppHeader.tsx +83 -0
- package/src/components/AppShell.stories.tsx +89 -0
- package/src/components/AppShell.tsx +286 -0
- package/src/components/AppShell.zoom.test.tsx +94 -0
- package/src/components/BareWorkbenchFileView.stories.tsx +27 -0
- package/src/components/BareWorkbenchFileView.tsx +64 -0
- package/src/components/Breadcrumb.stories.tsx +19 -0
- package/src/components/Breadcrumb.tsx +45 -0
- package/src/components/ChangesColumn.stories.tsx +39 -0
- package/src/components/ChangesColumn.tsx +171 -0
- package/src/components/CodeBlock.stories.tsx +42 -0
- package/src/components/CodeBlock.tsx +84 -0
- package/src/components/CompletionOverlay.stories.tsx +23 -0
- package/src/components/CompletionOverlay.tsx +60 -0
- package/src/components/ConfirmCard.stories.tsx +35 -0
- package/src/components/ConfirmCard.tsx +128 -0
- package/src/components/ConfirmDialog.stories.tsx +21 -0
- package/src/components/ConfirmDialog.tsx +66 -0
- package/src/components/DiffContentView.scroll.test.tsx +121 -0
- package/src/components/DiffContentView.split.test.tsx +140 -0
- package/src/components/DiffContentView.stories.tsx +80 -0
- package/src/components/DiffContentView.syntax.test.tsx +82 -0
- package/src/components/DiffContentView.tsx +859 -0
- package/src/components/DiscussionMarkerRail.stories.tsx +54 -0
- package/src/components/DiscussionMarkerRail.tsx +181 -0
- package/src/components/EditorGrid.stories.tsx +59 -0
- package/src/components/EditorGrid.tabs.test.tsx +118 -0
- package/src/components/EditorGrid.tsx +368 -0
- package/src/components/EditorGrid.zoom.test.tsx +68 -0
- package/src/components/FileContentsView.stories.tsx +16 -0
- package/src/components/FileContentsView.test.tsx +29 -0
- package/src/components/FileContentsView.tsx +98 -0
- package/src/components/KeybindsDialog.stories.tsx +31 -0
- package/src/components/KeybindsDialog.tsx +103 -0
- package/src/components/MenuBar.stories.tsx +28 -0
- package/src/components/MenuBar.tsx +44 -0
- package/src/components/OverlayScrollbar.stories.tsx +33 -0
- package/src/components/OverlayScrollbar.test.tsx +139 -0
- package/src/components/OverlayScrollbar.tsx +129 -0
- package/src/components/PaneGrid.stories.tsx +84 -0
- package/src/components/PaneGrid.tsx +128 -0
- package/src/components/PanelColumn.stories.tsx +25 -0
- package/src/components/PanelColumn.tsx +95 -0
- package/src/components/ProjectTreeView.stories.tsx +25 -0
- package/src/components/ProjectTreeView.test.tsx +32 -0
- package/src/components/ProjectTreeView.tsx +83 -0
- package/src/components/PromptDialog.stories.tsx +36 -0
- package/src/components/PromptDialog.tsx +87 -0
- package/src/components/PrototypeContentView.stories.tsx +19 -0
- package/src/components/PrototypeContentView.tsx +446 -0
- package/src/components/RootOverlay.stories.tsx +44 -0
- package/src/components/RootOverlay.tsx +35 -0
- package/src/components/ScrollArea.stories.tsx +20 -0
- package/src/components/ScrollArea.tsx +44 -0
- package/src/components/SettingsDialog.stories.tsx +117 -0
- package/src/components/SettingsDialog.tsx +195 -0
- package/src/components/SettingsRows.stories.tsx +18 -0
- package/src/components/SettingsRows.tsx +112 -0
- package/src/components/ShellHeader.stories.tsx +50 -0
- package/src/components/ShellHeader.tsx +137 -0
- package/src/components/ThreadFooter.stories.tsx +30 -0
- package/src/components/ThreadFooter.test.tsx +31 -0
- package/src/components/ThreadFooter.tsx +54 -0
- package/src/components/ThreadTree.stories.tsx +46 -0
- package/src/components/ThreadTree.tsx +219 -0
- package/src/components/ThreadView.selection.test.tsx +812 -0
- package/src/components/ThreadView.slash.test.tsx +158 -0
- package/src/components/ThreadView.stories.tsx +26 -0
- package/src/components/ThreadView.tsx +330 -0
- package/src/components/ThreadsSidebar.stories.tsx +36 -0
- package/src/components/ThreadsSidebar.tsx +71 -0
- package/src/components/Toast.stories.tsx +12 -0
- package/src/components/Toast.tsx +45 -0
- package/src/components/Tooltip.stories.tsx +26 -0
- package/src/components/Tooltip.tsx +72 -0
- package/src/components/TreePane.stories.tsx +106 -0
- package/src/components/TreePane.tsx +157 -0
- package/src/components/WalkWizard.stories.tsx +100 -0
- package/src/components/WalkWizard.tsx +152 -0
- package/src/components/WelcomePlayground.stories.tsx +12 -0
- package/src/components/WelcomePlayground.test.tsx +47 -0
- package/src/components/WelcomePlayground.tsx +140 -0
- package/src/components/__snapshots__/stories.test.tsx.snap +1845 -0
- package/src/components/agent-launcher.stories.tsx +26 -0
- package/src/components/agent-launcher.test.tsx +50 -0
- package/src/components/agent-launcher.tsx +149 -0
- package/src/components/diff-content-view-layout.test.ts +198 -0
- package/src/components/diff-content-view-layout.ts +84 -0
- package/src/components/editor-grid.test.ts +86 -0
- package/src/components/editor-grid.ts +138 -0
- package/src/components/fade-title.test.ts +49 -0
- package/src/components/fade-title.ts +61 -0
- package/src/components/file-tree.test.ts +60 -0
- package/src/components/file-tree.ts +112 -0
- package/src/components/pages/Workspace.stories.tsx +181 -0
- package/src/components/primitives/Button.stories.tsx +32 -0
- package/src/components/primitives/Button.tsx +52 -0
- package/src/components/primitives/Card.stories.tsx +25 -0
- package/src/components/primitives/Card.tsx +60 -0
- package/src/components/primitives/Dialog.stories.tsx +24 -0
- package/src/components/primitives/Dialog.tsx +66 -0
- package/src/components/primitives/IconButton.stories.tsx +36 -0
- package/src/components/primitives/IconButton.tsx +62 -0
- package/src/components/primitives/StatusBar.stories.tsx +11 -0
- package/src/components/primitives/StatusBar.tsx +23 -0
- package/src/components/primitives/Tabs.stories.tsx +29 -0
- package/src/components/primitives/Tabs.tsx +102 -0
- package/src/components/primitives/Toolbar.stories.tsx +17 -0
- package/src/components/primitives/Toolbar.tsx +14 -0
- package/src/components/primitives/Tree.stories.tsx +124 -0
- package/src/components/primitives/Tree.tsx +96 -0
- package/src/components/primitives/frame.test.ts +12 -0
- package/src/components/primitives/frame.ts +14 -0
- package/src/components/primitives/icons.ts +61 -0
- package/src/components/primitives/tree-model.test.ts +99 -0
- package/src/components/primitives/tree-model.ts +137 -0
- package/src/components/quick-actions-editor.stories.tsx +54 -0
- package/src/components/quick-actions-editor.test.tsx +49 -0
- package/src/components/quick-actions-editor.tsx +150 -0
- package/src/components/session-tree.test.ts +134 -0
- package/src/components/session-tree.ts +108 -0
- package/src/components/stories-app.tsx +184 -0
- package/src/components/stories.test.tsx +66 -0
- package/src/components/story-fixtures.ts +102 -0
- package/src/components/story-tree.test.ts +100 -0
- package/src/components/story.ts +142 -0
- package/src/components/syntax-highlight.ts +110 -0
- package/src/components/terminal-pane.test.tsx +40 -0
- package/src/components/terminal-pane.ts +199 -0
- package/src/components/theme-context.stories.tsx +46 -0
- package/src/components/theme-context.tsx +37 -0
- package/src/components/truncate-text.ts +7 -0
- package/src/config.test.ts +461 -31
- package/src/config.ts +389 -57
- package/src/diff-fold.test.ts +78 -0
- package/src/diff-fold.ts +126 -0
- package/src/diff-hunk-curate.test.ts +315 -0
- package/src/diff-hunk-curate.ts +153 -0
- package/src/diff-intraline.test.ts +165 -0
- package/src/diff-intraline.ts +146 -0
- package/src/diff-syntax.test.ts +112 -0
- package/src/diff-syntax.ts +179 -0
- package/src/discussions.ts +79 -0
- package/src/editor.test.ts +149 -0
- package/src/editor.ts +139 -9
- package/src/ghostty-terminal.test.ts +85 -0
- package/src/ghostty-terminal.ts +199 -0
- package/src/herdr.test.ts +9 -34
- package/src/herdr.ts +25 -21
- package/src/index.ts +11 -0
- package/src/integrations.test.ts +41 -0
- package/src/integrations.ts +32 -0
- package/src/intent-dispatch.test.ts +698 -0
- package/src/intent-dispatch.ts +700 -0
- package/src/key-bindings.test.ts +156 -0
- package/src/key-bindings.ts +465 -0
- package/src/keymap.test.ts +611 -0
- package/src/keymap.ts +410 -0
- package/src/kitty-image.test.ts +66 -0
- package/src/kitty-image.ts +138 -0
- package/src/mark-runs.ts +120 -0
- package/src/prototype-browser.test.ts +56 -0
- package/src/prototype-browser.ts +307 -0
- package/src/prototype-pixels.tsx +35 -0
- package/src/pty.test.ts +81 -0
- package/src/pty.ts +245 -0
- package/src/ready-signal.test.ts +85 -0
- package/src/ready-signal.ts +52 -0
- package/src/run.ts +30 -9
- package/src/serve.test.ts +24 -12
- package/src/serve.ts +20 -9
- package/src/share.ts +215 -0
- package/src/skills.test.ts +74 -0
- package/src/skills.ts +68 -0
- package/src/slash-palette.test.ts +54 -0
- package/src/slash-palette.ts +104 -0
- package/src/split-diff.test.ts +110 -0
- package/src/split-diff.ts +149 -0
- package/src/test-support.test.ts +264 -0
- package/src/test-support.ts +355 -0
- package/src/theme-presets.test.ts +51 -0
- package/src/theme-presets.ts +214 -0
- package/src/theme.ts +84 -19
- package/src/thread-chords.test.ts +170 -0
- package/src/thread-chords.ts +169 -0
- package/src/thread-controller.curate.test.ts +438 -0
- package/src/thread-controller.live-diff.test.ts +199 -0
- package/src/thread-controller.share.test.ts +472 -0
- package/src/thread-controller.tree.test.ts +255 -0
- package/src/thread-controller.ts +1509 -0
- package/src/thread-selection.test.ts +210 -0
- package/src/thread-selection.ts +243 -0
- package/src/tree-view.test.ts +128 -0
- package/src/tree-view.ts +148 -0
- package/src/use-annotation-surface.tsx +851 -0
- package/src/use-changes-workbench.ts +151 -0
- package/src/use-frame-measure.ts +38 -0
- package/src/use-settings-dialog.tsx +274 -0
- package/src/use-terminal-virtualizer.ts +233 -0
- package/src/version.ts +5 -0
- package/src/view-diff.test.ts +66 -9
- package/src/view-diff.ts +231 -23
- package/src/view-plan.regression.test.ts +60 -0
- package/src/view-plan.test.ts +406 -0
- package/src/view-plan.ts +570 -0
- package/src/walk.test.ts +121 -0
- package/src/walk.ts +74 -0
- package/src/syntax.test.ts +0 -41
- package/src/syntax.ts +0 -88
- package/src/view.test.ts +0 -157
- package/src/view.ts +0 -312
package/src/view-plan.ts
ADDED
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plan projection pipeline: parse → display blocks (base vs working
|
|
3
|
+
* copy reconciled) → styled runs. Pure functions - the TUI renders the runs
|
|
4
|
+
* (the native text primitive wraps them), tests assert on them directly.
|
|
5
|
+
* One planning layer: rendering, navigation, and selection all derive from
|
|
6
|
+
* this module; the rendered/work offset mappings keep the native selection
|
|
7
|
+
* addressable over word-diffed blocks.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
inlineRuns,
|
|
12
|
+
isAddressed,
|
|
13
|
+
lcsDiff,
|
|
14
|
+
parseBlocks,
|
|
15
|
+
resolveAnchor,
|
|
16
|
+
type Annotation,
|
|
17
|
+
type Block,
|
|
18
|
+
} from "@cueloop/schema";
|
|
19
|
+
import { wordLevelChanges } from "./diff-intraline";
|
|
20
|
+
import { spanRangeInBlock, type TextSpan } from "./thread-selection";
|
|
21
|
+
|
|
22
|
+
// ── display model ─────────────────────────────
|
|
23
|
+
|
|
24
|
+
export type DisplayType = "same" | "mod" | "del" | "add";
|
|
25
|
+
|
|
26
|
+
export interface DisplayBlock {
|
|
27
|
+
type: DisplayType;
|
|
28
|
+
kind: Block["kind"];
|
|
29
|
+
/** Block in the working copy (absent for del). */
|
|
30
|
+
work?: Block;
|
|
31
|
+
/** Block in the submitted revision (absent for add). */
|
|
32
|
+
base?: Block;
|
|
33
|
+
orderedItemNumber?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function displayText(block: DisplayBlock): string {
|
|
37
|
+
return (block.work ?? block.base)!.text;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Word-overlap similarity gate: an unrelated cut + insert must not merge. */
|
|
41
|
+
function similar(baseBlock: Block, workBlock: Block): boolean {
|
|
42
|
+
if (baseBlock.kind !== workBlock.kind) return false;
|
|
43
|
+
const words = (text: string) => new Set(text.toLowerCase().split(/\s+/).filter(Boolean));
|
|
44
|
+
const baseWords = words(baseBlock.text);
|
|
45
|
+
const workWords = words(workBlock.text);
|
|
46
|
+
let intersection = 0;
|
|
47
|
+
|
|
48
|
+
for (const word of baseWords) if (workWords.has(word)) intersection++;
|
|
49
|
+
const union = baseWords.size + workWords.size - intersection;
|
|
50
|
+
|
|
51
|
+
return union === 0 ? true : intersection / union >= 0.3;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Reconcile base blocks vs working blocks into the display list. */
|
|
55
|
+
export function buildDisplay(baseContent: string, workingContent?: string): DisplayBlock[] {
|
|
56
|
+
const baseBlocks = parseBlocks(baseContent);
|
|
57
|
+
|
|
58
|
+
if (workingContent === undefined) {
|
|
59
|
+
const display: DisplayBlock[] = baseBlocks.map((block) => ({
|
|
60
|
+
type: "same",
|
|
61
|
+
kind: block.kind,
|
|
62
|
+
work: block,
|
|
63
|
+
base: block,
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
numberOrderedListItems(display);
|
|
67
|
+
|
|
68
|
+
return display;
|
|
69
|
+
}
|
|
70
|
+
const workBlocks = parseBlocks(workingContent);
|
|
71
|
+
const signature = (block: Block) => block.kind + "\0" + block.text;
|
|
72
|
+
const ops = lcsDiff(
|
|
73
|
+
baseBlocks,
|
|
74
|
+
workBlocks,
|
|
75
|
+
(baseBlock, workBlock) => signature(baseBlock) === signature(workBlock),
|
|
76
|
+
);
|
|
77
|
+
const display: DisplayBlock[] = [];
|
|
78
|
+
let opIndex = 0;
|
|
79
|
+
|
|
80
|
+
while (opIndex < ops.length) {
|
|
81
|
+
const op = ops[opIndex]!;
|
|
82
|
+
|
|
83
|
+
if (op.kind === "ctx") {
|
|
84
|
+
display.push({ type: "same", kind: op.newValue!.kind, work: op.newValue, base: op.oldValue });
|
|
85
|
+
opIndex++;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const deletedBlocks: Block[] = [];
|
|
89
|
+
const addedBlocks: Block[] = [];
|
|
90
|
+
|
|
91
|
+
while (opIndex < ops.length && ops[opIndex]!.kind !== "ctx") {
|
|
92
|
+
const changeOp = ops[opIndex]!;
|
|
93
|
+
|
|
94
|
+
if (changeOp.kind === "del") deletedBlocks.push(changeOp.oldValue!);
|
|
95
|
+
else addedBlocks.push(changeOp.newValue!);
|
|
96
|
+
opIndex++;
|
|
97
|
+
}
|
|
98
|
+
let deletedIndex = 0;
|
|
99
|
+
let addedIndex = 0;
|
|
100
|
+
|
|
101
|
+
while (deletedIndex < deletedBlocks.length && addedIndex < addedBlocks.length) {
|
|
102
|
+
if (similar(deletedBlocks[deletedIndex]!, addedBlocks[addedIndex]!)) {
|
|
103
|
+
display.push({
|
|
104
|
+
type: "mod",
|
|
105
|
+
kind: addedBlocks[addedIndex]!.kind,
|
|
106
|
+
base: deletedBlocks[deletedIndex]!,
|
|
107
|
+
work: addedBlocks[addedIndex]!,
|
|
108
|
+
});
|
|
109
|
+
deletedIndex++;
|
|
110
|
+
addedIndex++;
|
|
111
|
+
} else if (deletedBlocks.length - deletedIndex >= addedBlocks.length - addedIndex) {
|
|
112
|
+
display.push({
|
|
113
|
+
type: "del",
|
|
114
|
+
kind: deletedBlocks[deletedIndex]!.kind,
|
|
115
|
+
base: deletedBlocks[deletedIndex]!,
|
|
116
|
+
});
|
|
117
|
+
deletedIndex++;
|
|
118
|
+
} else {
|
|
119
|
+
display.push({
|
|
120
|
+
type: "add",
|
|
121
|
+
kind: addedBlocks[addedIndex]!.kind,
|
|
122
|
+
work: addedBlocks[addedIndex]!,
|
|
123
|
+
});
|
|
124
|
+
addedIndex++;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
while (deletedIndex < deletedBlocks.length) {
|
|
128
|
+
display.push({
|
|
129
|
+
type: "del",
|
|
130
|
+
kind: deletedBlocks[deletedIndex]!.kind,
|
|
131
|
+
base: deletedBlocks[deletedIndex++]!,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
while (addedIndex < addedBlocks.length) {
|
|
135
|
+
display.push({
|
|
136
|
+
type: "add",
|
|
137
|
+
kind: addedBlocks[addedIndex]!.kind,
|
|
138
|
+
work: addedBlocks[addedIndex++]!,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
numberOrderedListItems(display);
|
|
143
|
+
|
|
144
|
+
return display;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function numberOrderedListItems(display: DisplayBlock[]): void {
|
|
148
|
+
let runLength = 0;
|
|
149
|
+
|
|
150
|
+
for (const block of display) {
|
|
151
|
+
if (block.kind === "oli") block.orderedItemNumber = ++runLength;
|
|
152
|
+
else runLength = 0;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ── marks (annotation highlights + keyboard span) ──
|
|
157
|
+
|
|
158
|
+
export type RunRole =
|
|
159
|
+
| "plain"
|
|
160
|
+
| "ins"
|
|
161
|
+
| "del"
|
|
162
|
+
| "mark-comment"
|
|
163
|
+
| "kspan"
|
|
164
|
+
| "mark-focus"
|
|
165
|
+
| "strong"
|
|
166
|
+
| "em"
|
|
167
|
+
| "code"
|
|
168
|
+
| "strike"
|
|
169
|
+
| "link";
|
|
170
|
+
|
|
171
|
+
export interface StyleRun {
|
|
172
|
+
text: string;
|
|
173
|
+
role: RunRole;
|
|
174
|
+
/** Offset of this run in the block's working text; null for del runs. */
|
|
175
|
+
start: number | null;
|
|
176
|
+
annotationId?: string;
|
|
177
|
+
/** Link target for `link` runs. */
|
|
178
|
+
href?: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface Mark {
|
|
182
|
+
start: number;
|
|
183
|
+
end: number;
|
|
184
|
+
role: RunRole;
|
|
185
|
+
annotationId?: string;
|
|
186
|
+
/** The whole anchored stretch in display coordinates; one thread per span. */
|
|
187
|
+
span?: TextSpan;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Resolve annotations against the working blocks and group marks per display
|
|
192
|
+
* index. Working blocks are the blocks of (workingCopy ?? artifact) - the
|
|
193
|
+
* same list buildDisplay derived work entries from.
|
|
194
|
+
*/
|
|
195
|
+
export function marksByDisplay(
|
|
196
|
+
annotations: Annotation[],
|
|
197
|
+
display: DisplayBlock[],
|
|
198
|
+
focusedId?: string,
|
|
199
|
+
): Map<number, Mark[]> {
|
|
200
|
+
// block list in "work space": display entries that carry a work block, in order
|
|
201
|
+
const workEntries = display
|
|
202
|
+
.map((block, displayIndex) => ({ block, displayIndex }))
|
|
203
|
+
.filter((entry) => entry.block.work !== undefined);
|
|
204
|
+
const workBlocks = workEntries.map((entry) => entry.block.work!);
|
|
205
|
+
const marksByIndex = new Map<number, Mark[]>();
|
|
206
|
+
|
|
207
|
+
for (const annotation of annotations) {
|
|
208
|
+
// an addressed annotation keeps its record but paints no highlight
|
|
209
|
+
if (isAddressed(annotation)) continue;
|
|
210
|
+
const resolved = resolveAnchor(annotation.anchor, workBlocks);
|
|
211
|
+
|
|
212
|
+
if (!resolved) continue;
|
|
213
|
+
const startEntry = workEntries[resolved.blockIndex];
|
|
214
|
+
const endEntry = workEntries[resolved.endBlockIndex];
|
|
215
|
+
|
|
216
|
+
if (!startEntry || !endEntry) continue;
|
|
217
|
+
const span: TextSpan = {
|
|
218
|
+
start: { blockIndex: startEntry.displayIndex, char: resolved.start },
|
|
219
|
+
end: { blockIndex: endEntry.displayIndex, char: resolved.end },
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// a span paints on every block it covers; the mark carries the whole span
|
|
223
|
+
for (let workIndex = resolved.blockIndex; workIndex <= resolved.endBlockIndex; workIndex++) {
|
|
224
|
+
const entry = workEntries[workIndex]!;
|
|
225
|
+
const range = spanRangeInBlock(span, entry.displayIndex, entry.block.work!.text.length);
|
|
226
|
+
|
|
227
|
+
if (!range) continue;
|
|
228
|
+
const marks = marksByIndex.get(entry.displayIndex) ?? [];
|
|
229
|
+
|
|
230
|
+
marks.push({
|
|
231
|
+
start: range.start,
|
|
232
|
+
end: range.end,
|
|
233
|
+
role: annotation.id === focusedId ? "mark-focus" : "mark-comment",
|
|
234
|
+
annotationId: annotation.id,
|
|
235
|
+
span,
|
|
236
|
+
});
|
|
237
|
+
marksByIndex.set(entry.displayIndex, marks);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return marksByIndex;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Base runs for a display block: plain text, or word-diff for mod blocks. */
|
|
245
|
+
export function blockRuns(block: DisplayBlock, markup: boolean): StyleRun[] {
|
|
246
|
+
const literal = block.kind === "code" || block.kind === "hr";
|
|
247
|
+
|
|
248
|
+
if (block.type === "mod" && markup) {
|
|
249
|
+
const changes = wordLevelChanges(block.base!.text, block.work!.text);
|
|
250
|
+
const runs: StyleRun[] = [];
|
|
251
|
+
let workOffset = 0;
|
|
252
|
+
|
|
253
|
+
for (const change of changes) {
|
|
254
|
+
if (change.kind === "removed") {
|
|
255
|
+
runs.push({ text: change.text, role: "del", start: null });
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
// A code/rule block stays literal; prose segments inline-tokenize so their
|
|
259
|
+
// markers conceal while their work offsets stay intact. Added text keeps
|
|
260
|
+
// the green diff role (it wins over emphasis); context text shows emphasis.
|
|
261
|
+
const segment = literal
|
|
262
|
+
? [{ text: change.text, role: "plain" as const, start: workOffset }]
|
|
263
|
+
: inlineStyleRuns(change.text, workOffset);
|
|
264
|
+
|
|
265
|
+
for (const run of segment) {
|
|
266
|
+
runs.push(change.kind === "added" ? { ...run, role: "ins" } : run);
|
|
267
|
+
}
|
|
268
|
+
workOffset += change.text.length;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return runs;
|
|
272
|
+
}
|
|
273
|
+
const text = displayText(block);
|
|
274
|
+
|
|
275
|
+
// Prose carries inline markup; code fences and rules are literal. Concealed
|
|
276
|
+
// markers are dropped, so every rendered cell still maps to a work offset.
|
|
277
|
+
if (markup && !literal) {
|
|
278
|
+
return inlineStyleRuns(text, 0);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return [{ text, role: "plain", start: 0 }];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** A link href safe to hand a terminal as an OSC 8 target, or undefined. Only
|
|
285
|
+
* http(s) and mailto are trusted; a scheme like javascript: is dropped. The
|
|
286
|
+
* target must stay printable ASCII: a control byte (ESC, BEL) in a reviewed
|
|
287
|
+
* document could otherwise splice into the terminal escape stream. */
|
|
288
|
+
export function safeLinkHref(href: string | undefined): string | undefined {
|
|
289
|
+
if (href === undefined) return undefined;
|
|
290
|
+
if (!/^(https?:|mailto:)/i.test(href)) return undefined;
|
|
291
|
+
|
|
292
|
+
return /^[\x21-\x7e]+$/.test(href) ? href : undefined;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Map the schema inline tokens to positioned StyleRuns, dropping the concealed
|
|
297
|
+
* markers. `base` is the run's offset within the block's working text (0 for a
|
|
298
|
+
* whole prose block; a segment's start for a word-diff piece).
|
|
299
|
+
*/
|
|
300
|
+
export function inlineStyleRuns(text: string, base: number): StyleRun[] {
|
|
301
|
+
const runs: StyleRun[] = [];
|
|
302
|
+
|
|
303
|
+
for (const run of inlineRuns(text)) {
|
|
304
|
+
if (run.role === "marker" || run.start === null) continue;
|
|
305
|
+
const styleRun: StyleRun = {
|
|
306
|
+
text: run.text,
|
|
307
|
+
role: run.role === "text" ? "plain" : run.role,
|
|
308
|
+
start: base + run.start,
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
if (run.href !== undefined) styleRun.href = run.href;
|
|
312
|
+
runs.push(styleRun);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return runs;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Split runs at mark boundaries; marks only bind to runs with offsets. */
|
|
319
|
+
export function overlayMarks(runs: StyleRun[], marks: Mark[]): StyleRun[] {
|
|
320
|
+
if (!marks.length) return runs;
|
|
321
|
+
const splitRuns: StyleRun[] = [];
|
|
322
|
+
|
|
323
|
+
for (const run of runs) {
|
|
324
|
+
if (run.start === null) {
|
|
325
|
+
splitRuns.push(run);
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const bounds = new Set<number>([0, run.text.length]);
|
|
329
|
+
|
|
330
|
+
for (const mark of marks) {
|
|
331
|
+
const boundStart = Math.max(0, mark.start - run.start);
|
|
332
|
+
const boundEnd = Math.min(run.text.length, mark.end - run.start);
|
|
333
|
+
|
|
334
|
+
if (boundStart < boundEnd) {
|
|
335
|
+
bounds.add(boundStart);
|
|
336
|
+
bounds.add(boundEnd);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const runStart = run.start;
|
|
340
|
+
const boundaries = [...bounds].sort((left, right) => left - right);
|
|
341
|
+
|
|
342
|
+
for (let boundaryIndex = 0; boundaryIndex < boundaries.length - 1; boundaryIndex++) {
|
|
343
|
+
const sliceStart = boundaries[boundaryIndex]!;
|
|
344
|
+
const sliceEnd = boundaries[boundaryIndex + 1]!;
|
|
345
|
+
|
|
346
|
+
if (sliceStart >= sliceEnd) continue;
|
|
347
|
+
const absoluteStart = runStart + sliceStart;
|
|
348
|
+
const mark = marks.find(
|
|
349
|
+
(candidate) => candidate.start <= absoluteStart && runStart + sliceEnd <= candidate.end,
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
splitRuns.push({
|
|
353
|
+
text: run.text.slice(sliceStart, sliceEnd),
|
|
354
|
+
// a mark never overrides ins/del emphasis; it rides on plain text
|
|
355
|
+
role: mark && run.role === "plain" ? mark.role : run.role,
|
|
356
|
+
start: absoluteStart,
|
|
357
|
+
annotationId: mark?.annotationId ?? run.annotationId,
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return splitRuns;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Rendered-text offset of a work-text offset within a block's runs. The
|
|
367
|
+
* rendered text is every run's text in order (inline del runs included);
|
|
368
|
+
* only positioned runs carry work offsets. Drives the renderer's native
|
|
369
|
+
* selection from keyboard span offsets - the quote-anchor path depends on
|
|
370
|
+
* this mapping staying exact.
|
|
371
|
+
*/
|
|
372
|
+
export function renderedOffsetFor(runs: StyleRun[], workOffset: number): number | null {
|
|
373
|
+
let rendered = 0;
|
|
374
|
+
|
|
375
|
+
for (const run of runs) {
|
|
376
|
+
if (run.start !== null && workOffset >= run.start && workOffset < run.start + run.text.length) {
|
|
377
|
+
return rendered + (workOffset - run.start);
|
|
378
|
+
}
|
|
379
|
+
rendered += run.text.length;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Rendered offset of the first positioned character at or after `workOffset`.
|
|
387
|
+
* A word span may start on a concealed marker (the `**` of an emphasized
|
|
388
|
+
* word), which has no rendered cell; the span visuals snap to the first
|
|
389
|
+
* character that does. Positioned runs appear in ascending work order.
|
|
390
|
+
*/
|
|
391
|
+
export function renderedOffsetAtOrAfter(runs: StyleRun[], workOffset: number): number | null {
|
|
392
|
+
let rendered = 0;
|
|
393
|
+
|
|
394
|
+
for (const run of runs) {
|
|
395
|
+
if (run.start !== null && run.start + run.text.length > workOffset) {
|
|
396
|
+
return rendered + Math.max(0, workOffset - run.start);
|
|
397
|
+
}
|
|
398
|
+
rendered += run.text.length;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Rendered offset of the last positioned character at or before `workOffset` -
|
|
406
|
+
* the closing-marker counterpart of `renderedOffsetAtOrAfter`.
|
|
407
|
+
*/
|
|
408
|
+
export function renderedOffsetAtOrBefore(runs: StyleRun[], workOffset: number): number | null {
|
|
409
|
+
let rendered = 0;
|
|
410
|
+
let best: number | null = null;
|
|
411
|
+
|
|
412
|
+
for (const run of runs) {
|
|
413
|
+
if (run.start !== null && run.start <= workOffset) {
|
|
414
|
+
best = rendered + Math.min(workOffset - run.start, run.text.length - 1);
|
|
415
|
+
}
|
|
416
|
+
rendered += run.text.length;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return best;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Work-text range covered by a rendered-text selection [start, end). Del runs
|
|
424
|
+
* and other unpositioned text inside the selection contribute nothing; the
|
|
425
|
+
* result is the tightest work range whose text the selection touched.
|
|
426
|
+
*/
|
|
427
|
+
export function workRangeForRendered(
|
|
428
|
+
runs: StyleRun[],
|
|
429
|
+
renderedStart: number,
|
|
430
|
+
renderedEnd: number,
|
|
431
|
+
): { start: number; end: number } | null {
|
|
432
|
+
let rendered = 0;
|
|
433
|
+
let range: { start: number; end: number } | null = null;
|
|
434
|
+
|
|
435
|
+
for (const run of runs) {
|
|
436
|
+
const runRenderedStart = rendered;
|
|
437
|
+
const runRenderedEnd = rendered + run.text.length;
|
|
438
|
+
|
|
439
|
+
rendered = runRenderedEnd;
|
|
440
|
+
if (run.start === null) continue;
|
|
441
|
+
const overlapStart = Math.max(renderedStart, runRenderedStart);
|
|
442
|
+
const overlapEnd = Math.min(renderedEnd, runRenderedEnd);
|
|
443
|
+
|
|
444
|
+
if (overlapEnd <= overlapStart) continue;
|
|
445
|
+
const workStart = run.start + (overlapStart - runRenderedStart);
|
|
446
|
+
const workEnd = run.start + (overlapEnd - runRenderedStart);
|
|
447
|
+
|
|
448
|
+
if (!range) range = { start: workStart, end: workEnd };
|
|
449
|
+
else {
|
|
450
|
+
range.start = Math.min(range.start, workStart);
|
|
451
|
+
range.end = Math.max(range.end, workEnd);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return range;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/** Line delta between two revision contents, for the sheet-header summary. */
|
|
459
|
+
export function revisionDelta(previousContent: string, nextContent: string) {
|
|
460
|
+
const ops = lcsDiff(previousContent.split("\n"), nextContent.split("\n"));
|
|
461
|
+
let added = 0;
|
|
462
|
+
let removed = 0;
|
|
463
|
+
|
|
464
|
+
for (const op of ops) {
|
|
465
|
+
if (op.kind === "add") added++;
|
|
466
|
+
else if (op.kind === "del") removed++;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return { added, removed };
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// ── keyboard span mode ────────────────────────
|
|
473
|
+
|
|
474
|
+
export interface SpanState {
|
|
475
|
+
displayIndex: number;
|
|
476
|
+
wordIndex: number;
|
|
477
|
+
wordEnd: number;
|
|
478
|
+
start: number;
|
|
479
|
+
end: number;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export function wordRanges(text: string): [number, number][] {
|
|
483
|
+
const ranges: [number, number][] = [];
|
|
484
|
+
const wordPattern = /\S+/g;
|
|
485
|
+
let match: RegExpExecArray | null;
|
|
486
|
+
|
|
487
|
+
while ((match = wordPattern.exec(text)))
|
|
488
|
+
ranges.push([match.index, match.index + match[0]!.length]);
|
|
489
|
+
|
|
490
|
+
return ranges;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export function startSpan(displayIndex: number, text: string): SpanState | null {
|
|
494
|
+
const words = wordRanges(text);
|
|
495
|
+
|
|
496
|
+
if (!words.length) return null;
|
|
497
|
+
|
|
498
|
+
return { displayIndex, wordIndex: 0, wordEnd: 0, start: words[0]![0], end: words[0]![1] };
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Build a word-granular span from a raw char range (a mouse drag-selection),
|
|
503
|
+
* snapping to every word the range overlaps so w/b/l/h keep working after. Null
|
|
504
|
+
* when the range covers no word.
|
|
505
|
+
*/
|
|
506
|
+
export function spanFromRange(
|
|
507
|
+
displayIndex: number,
|
|
508
|
+
text: string,
|
|
509
|
+
start: number,
|
|
510
|
+
end: number,
|
|
511
|
+
): SpanState | null {
|
|
512
|
+
const words = wordRanges(text);
|
|
513
|
+
const wordIndex = words.findIndex((word) => word[1] > start);
|
|
514
|
+
|
|
515
|
+
if (wordIndex === -1) return null;
|
|
516
|
+
let wordEnd = wordIndex;
|
|
517
|
+
|
|
518
|
+
for (let index = wordIndex; index < words.length && words[index]![0] < end; index++) {
|
|
519
|
+
wordEnd = index;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return {
|
|
523
|
+
displayIndex,
|
|
524
|
+
wordIndex,
|
|
525
|
+
wordEnd,
|
|
526
|
+
start: words[wordIndex]![0],
|
|
527
|
+
end: words[wordEnd]![1],
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export function spanKey(span: SpanState, key: string, text: string): SpanState {
|
|
532
|
+
const words = wordRanges(text);
|
|
533
|
+
const nextSpan = { ...span };
|
|
534
|
+
const width = nextSpan.wordEnd - nextSpan.wordIndex;
|
|
535
|
+
|
|
536
|
+
if (key === "l") nextSpan.wordEnd = Math.min(words.length - 1, nextSpan.wordEnd + 1);
|
|
537
|
+
else if (key === "h") nextSpan.wordEnd = Math.max(nextSpan.wordIndex, nextSpan.wordEnd - 1);
|
|
538
|
+
else if (key === "w") {
|
|
539
|
+
const slidTo = Math.min(words.length - 1 - width, nextSpan.wordIndex + 1);
|
|
540
|
+
|
|
541
|
+
nextSpan.wordIndex = slidTo;
|
|
542
|
+
nextSpan.wordEnd = slidTo + width;
|
|
543
|
+
} else if (key === "b") {
|
|
544
|
+
const slidTo = Math.max(0, nextSpan.wordIndex - 1);
|
|
545
|
+
|
|
546
|
+
nextSpan.wordIndex = slidTo;
|
|
547
|
+
nextSpan.wordEnd = slidTo + width;
|
|
548
|
+
} else if (key === "$") nextSpan.wordEnd = words.length - 1;
|
|
549
|
+
else if (key === "0") {
|
|
550
|
+
nextSpan.wordEnd = width;
|
|
551
|
+
nextSpan.wordIndex = 0;
|
|
552
|
+
} else return span;
|
|
553
|
+
nextSpan.start = words[nextSpan.wordIndex]![0];
|
|
554
|
+
nextSpan.end = words[nextSpan.wordEnd]![1];
|
|
555
|
+
|
|
556
|
+
return nextSpan;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// ── working-copy block operations ─────────────
|
|
560
|
+
|
|
561
|
+
/** The next work block after a display index (a del block re-enters before it). */
|
|
562
|
+
export function nextWorkBlock(display: DisplayBlock[], displayIndex: number): Block | undefined {
|
|
563
|
+
for (let candidateIndex = displayIndex + 1; candidateIndex < display.length; candidateIndex++) {
|
|
564
|
+
const workBlock = display[candidateIndex]!.work;
|
|
565
|
+
|
|
566
|
+
if (workBlock) return workBlock;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
return undefined;
|
|
570
|
+
}
|
package/src/walk.test.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/** Pure walk projections: file steps, resume index, viewed counts, notes. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, test } from "bun:test";
|
|
4
|
+
import type { Annotation } from "@cueloop/schema";
|
|
5
|
+
import { diffRows } from "./view-diff";
|
|
6
|
+
import { firstUnviewedIndex, noteForFile, viewedCount, walkFiles, WALK_PREVIEW_ROWS } from "./walk";
|
|
7
|
+
|
|
8
|
+
const PATCH = `diff --git a/src/a.ts b/src/a.ts
|
|
9
|
+
index 111..222 100644
|
|
10
|
+
--- a/src/a.ts
|
|
11
|
+
+++ b/src/a.ts
|
|
12
|
+
@@ -1,3 +1,4 @@
|
|
13
|
+
export const a = 1;
|
|
14
|
+
-export const b = 2;
|
|
15
|
+
+export const b = 3;
|
|
16
|
+
+export const c = 4;
|
|
17
|
+
diff --git a/src/b.ts b/src/b.ts
|
|
18
|
+
index 333..444 100644
|
|
19
|
+
--- a/src/b.ts
|
|
20
|
+
+++ b/src/b.ts
|
|
21
|
+
@@ -1,2 +1,2 @@
|
|
22
|
+
// header
|
|
23
|
+
-old line
|
|
24
|
+
+new line
|
|
25
|
+
diff --git a/src/c.ts b/src/c.ts
|
|
26
|
+
index 555..666 100644
|
|
27
|
+
--- a/src/c.ts
|
|
28
|
+
+++ b/src/c.ts
|
|
29
|
+
@@ -1,1 +1,8 @@
|
|
30
|
+
-gone
|
|
31
|
+
+one
|
|
32
|
+
+two
|
|
33
|
+
+three
|
|
34
|
+
+four
|
|
35
|
+
+five
|
|
36
|
+
+six
|
|
37
|
+
+seven
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const rows = diffRows(PATCH);
|
|
41
|
+
const files = walkFiles(rows);
|
|
42
|
+
|
|
43
|
+
describe("walkFiles", () => {
|
|
44
|
+
test("one step per changed file, in patch order, with counted stats", () => {
|
|
45
|
+
expect(files.map((file) => file.path)).toEqual(["src/a.ts", "src/b.ts", "src/c.ts"]);
|
|
46
|
+
expect(files[0]).toMatchObject({ added: 2, removed: 1 });
|
|
47
|
+
expect(files[1]).toMatchObject({ added: 1, removed: 1 });
|
|
48
|
+
expect(files[2]).toMatchObject({ added: 7, removed: 1 });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("previews carry signed changed lines and cap at the preview budget", () => {
|
|
52
|
+
expect(files[0]!.preview).toEqual([
|
|
53
|
+
{ sign: "-", text: "export const b = 2;" },
|
|
54
|
+
{ sign: "+", text: "export const b = 3;" },
|
|
55
|
+
{ sign: "+", text: "export const c = 4;" },
|
|
56
|
+
]);
|
|
57
|
+
expect(files[2]!.preview.length).toBe(WALK_PREVIEW_ROWS);
|
|
58
|
+
expect(files[2]!.preview[0]).toEqual({ sign: "-", text: "gone" });
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("firstUnviewedIndex", () => {
|
|
63
|
+
test("starts at the first file when nothing is viewed", () => {
|
|
64
|
+
expect(firstUnviewedIndex(files, new Set())).toBe(0);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("skips viewed files - a resumed review lands on its first gap", () => {
|
|
68
|
+
expect(firstUnviewedIndex(files, new Set(["src/a.ts"]))).toBe(1);
|
|
69
|
+
expect(firstUnviewedIndex(files, new Set(["src/a.ts", "src/b.ts"]))).toBe(2);
|
|
70
|
+
// a viewed file later in the list does not block the earlier gap
|
|
71
|
+
expect(firstUnviewedIndex(files, new Set(["src/c.ts"]))).toBe(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("all viewed resumes on the end card, not the first file", () => {
|
|
75
|
+
expect(firstUnviewedIndex(files, new Set(["src/a.ts", "src/b.ts", "src/c.ts"]))).toBe(
|
|
76
|
+
files.length,
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("viewedCount", () => {
|
|
82
|
+
test("counts only paths present in the current file set", () => {
|
|
83
|
+
expect(viewedCount(files, new Set(["src/a.ts", "src/gone-in-rev-2.ts"]))).toBe(1);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe("noteForFile", () => {
|
|
88
|
+
const note = (path: string, body: string): Annotation => ({
|
|
89
|
+
id: `a_${path}`,
|
|
90
|
+
kind: "note",
|
|
91
|
+
anchor: { quote: path, prefix: "", suffix: "" },
|
|
92
|
+
body,
|
|
93
|
+
createdAt: "now",
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("finds the note anchored at the file path", () => {
|
|
97
|
+
// Arrange
|
|
98
|
+
const annotations = [
|
|
99
|
+
note("src/a.ts", "Renames b and adds c."),
|
|
100
|
+
note("src/b.ts", "Swaps the line."),
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
// Assert
|
|
104
|
+
expect(noteForFile(annotations, "src/b.ts")).toBe("Swaps the line.");
|
|
105
|
+
expect(noteForFile(annotations, "src/c.ts")).toBeUndefined();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("ignores non-note annotations that happen to quote the path", () => {
|
|
109
|
+
// Arrange
|
|
110
|
+
const comment: Annotation = {
|
|
111
|
+
id: "a_1",
|
|
112
|
+
kind: "comment",
|
|
113
|
+
anchor: { quote: "src/a.ts", prefix: "", suffix: "" },
|
|
114
|
+
body: "not a note",
|
|
115
|
+
createdAt: "now",
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// Assert
|
|
119
|
+
expect(noteForFile([comment], "src/a.ts")).toBeUndefined();
|
|
120
|
+
});
|
|
121
|
+
});
|