Skip to content

Commit 01d80d6

Browse files
committed
codex: address PR review feedback (#1124)
1 parent 74fec55 commit 01d80d6

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

src/engine/CaptureChoiceEngine.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,19 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
8989
case "currentLine":
9090
msg = `Captured to current line in ${fileName}`;
9191
break;
92+
case "newLineAbove":
93+
msg = `Captured on a new line above cursor in ${fileName}`;
94+
break;
95+
case "newLineBelow":
96+
msg = `Captured on a new line below cursor in ${fileName}`;
97+
break;
9298
case "prepend":
9399
case "activeFileTop":
94100
msg = `Captured to top of ${fileName}`;
95101
break;
102+
case "activeFileBottom":
103+
msg = `Captured to bottom of ${fileName}`;
104+
break;
96105
case "append":
97106
msg = `Captured to ${fileName}`;
98107
break;
@@ -103,6 +112,9 @@ export class CaptureChoiceEngine extends QuickAddChoiceEngine {
103112
: `Captured to ${fileName}`;
104113
break;
105114
}
115+
default:
116+
msg = `Captured to ${fileName}`;
117+
break;
106118
}
107119

108120
new Notice(msg, DEFAULT_NOTICE_DURATION);

src/engine/canvasCapture.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type WorkspaceLeafLike = {
3838
};
3939

4040
type WorkspaceLike = {
41-
activeLeaf?: WorkspaceLeafLike;
41+
getMostRecentLeaf?: () => WorkspaceLeafLike | null;
4242
getActiveFile?: () => TFile | null;
4343
};
4444

@@ -166,7 +166,7 @@ function isTFileLike(file: TAbstractFile | null): file is TFile {
166166
}
167167

168168
function getActiveCanvasView(app: CanvasAppLike): CanvasViewLike | null {
169-
const activeView = app.workspace.activeLeaf?.view;
169+
const activeView = app.workspace.getMostRecentLeaf?.()?.view;
170170
if (!activeView || activeView.getViewType?.() !== "canvas") return null;
171171
return activeView;
172172
}

src/gui/ChoiceBuilder/captureChoiceBuilder.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
324324

325325
clearButton.addEventListener("click", () => {
326326
applyNodeId("");
327+
renderList(filterInput.getValue());
327328
});
328329

329330
useActiveSelectionButton.addEventListener("click", () => {
@@ -464,17 +465,19 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
464465
private getActiveCanvasSelectionNodeIdForPath(
465466
canvasPath: string,
466467
): string | null {
467-
const activeLeaf = this.app.workspace.activeLeaf as
468-
{
469-
view?: {
470-
getViewType?: () => string;
471-
file?: { path?: string };
472-
canvas?: {
473-
selection?: Set<{ id?: string }>;
468+
const mostRecentLeaf = this.app.workspace.getMostRecentLeaf?.() as
469+
| {
470+
view?: {
471+
getViewType?: () => string;
472+
file?: { path?: string };
473+
canvas?: {
474+
selection?: Set<{ id?: string }>;
475+
};
474476
};
475-
};
476-
} | undefined;
477-
const view = activeLeaf?.view;
477+
}
478+
| null
479+
| undefined;
480+
const view = mostRecentLeaf?.view;
478481
if (!view || view.getViewType?.() !== "canvas") {
479482
return null;
480483
}
@@ -550,8 +553,8 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
550553
(node): node is {
551554
id: string;
552555
type?: string;
553-
text?: string;
554-
file?: string | { path?: string };
556+
text?: unknown;
557+
file?: unknown;
555558
x?: number;
556559
y?: number;
557560
width?: number;
@@ -571,7 +574,8 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
571574

572575
const coords = this.describeCanvasNodeCoordinates(node);
573576
if (nodeType === "text") {
574-
const lines = (node.text ?? "")
577+
const rawText = typeof node.text === "string" ? node.text : "";
578+
const lines = rawText
575579
.split("\n")
576580
.map((line) => line.trim())
577581
.filter((line) => line.length > 0);
@@ -594,10 +598,7 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
594598
}
595599

596600
if (nodeType === "file") {
597-
const filePath =
598-
typeof node.file === "string"
599-
? node.file
600-
: node.file?.path ?? "(missing file path)";
601+
const filePath = this.getCanvasNodeFilePath(node.file);
601602
const title = this.truncatePickerText(
602603
filePath.split("/").pop() ?? filePath,
603604
90,
@@ -616,7 +617,11 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
616617
};
617618
}
618619

619-
const title = `Unsupported node (${node.type ?? "unknown"})`;
620+
const nodeTypeLabel =
621+
typeof node.type === "string" && node.type.length > 0
622+
? node.type
623+
: "unknown";
624+
const title = `Unsupported node (${nodeTypeLabel})`;
620625
const subtitle = coords || "Type is not currently capturable";
621626
return {
622627
id: node.id,
@@ -646,6 +651,23 @@ export class CaptureChoiceBuilder extends ChoiceBuilder {
646651
}
647652
}
648653

654+
private getCanvasNodeFilePath(fileField: unknown): string {
655+
if (typeof fileField === "string") {
656+
return fileField;
657+
}
658+
659+
if (
660+
fileField &&
661+
typeof fileField === "object" &&
662+
"path" in fileField &&
663+
typeof (fileField as { path?: unknown }).path === "string"
664+
) {
665+
return (fileField as { path: string }).path;
666+
}
667+
668+
return "(missing file path)";
669+
}
670+
649671
private describeCanvasNodeCoordinates(node: {
650672
x?: number;
651673
y?: number;

0 commit comments

Comments
 (0)