Skip to content

Commit f725bb9

Browse files
committed
fix(web): keep a document link inline in the coordinator's sentence
1 parent 4db95c1 commit f725bb9

4 files changed

Lines changed: 50 additions & 16 deletions

File tree

‎apps/web/src/markdown.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,20 @@ function inline(
7373
const href = match[5].replace(MARKS, "");
7474
if (href.startsWith(DOCUMENT_LINK) && openDocument !== undefined) {
7575
const id = decodeURIComponent(href.slice(DOCUMENT_LINK.length));
76+
// A link rather than a button: a button never breaks across lines, so a
77+
// title in a sentence would jump to its own line and shed its punctuation.
7678
out.push(
77-
<button
79+
<a
7880
key={key}
79-
type="button"
81+
href="#"
8082
className="artifact-mention"
81-
onClick={() => openDocument(id)}
83+
onClick={(event) => {
84+
event.preventDefault();
85+
openDocument(id);
86+
}}
8287
>
8388
{label}
84-
</button>,
89+
</a>,
8590
);
8691
} else if (href.startsWith("https://") || href.startsWith("http://")) {
8792
out.push(

‎apps/web/src/pages/workspace-layout.css‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,9 @@
145145
}
146146

147147
.artifact-mention {
148-
display: inline-flex;
149-
align-items: center;
150-
min-height: 44px;
151-
min-width: 44px;
152-
margin: 0;
153-
padding: 0 var(--space-1);
154-
border: 0;
155-
background: transparent;
156148
color: var(--wb-foreground);
157-
font: inherit;
158149
text-decoration: underline;
159150
text-underline-offset: 0.15em;
160-
cursor: pointer;
161151
}
162152

163153
.artifact-mention:focus-visible {

‎apps/web/src/pages/workspace/print-document.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const SHEET_CLASS = "print-sheet";
2-
// Controls and selection affordances stay on screen; a document mention prints as its text.
3-
const SCREEN_ONLY = ".pane-bar, .passage-offer, button:not(.artifact-mention)";
2+
// Controls and selection affordances stay on screen.
3+
const SCREEN_ONLY = ".pane-bar, .passage-offer, button";
44

55
/**
66
* Prints the document a pane shows through the browser's dialog, whose "Save as PDF"

‎apps/web/src/pages/workspace/transcript.test.tsx‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
maxTurnText,
77
} from "@corbits-builder/schemas/conversation";
88
import { wording } from "../../config.ts";
9+
import { Markdown } from "../../markdown.tsx";
910
import { DocumentDecision } from "./document-decision.tsx";
1011
import {
1112
awaitingCommit,
@@ -96,6 +97,44 @@ describe("conversation transcript", () => {
9697
expect(html).not.toContain("sha256");
9798
});
9899

100+
test("a bold document name stays a link inside its sentence and still opens", () => {
101+
const source =
102+
"Already written into **Ways to build your list**. What the app does is next.";
103+
const documents = [{ id: "approaches", title: "Ways to build your list" }];
104+
const html = renderToStaticMarkup(
105+
<RoomThread
106+
turns={[{ role: "assistant", text: source, at: 2 }]}
107+
documents={documents}
108+
onOpenDocument={() => {}}
109+
/>,
110+
);
111+
// A link, not a button: a button is one unbreakable box, so the title would leave the line.
112+
expect(html).toContain(
113+
'into <strong><a href="#" class="artifact-mention">Ways to build your list</a></strong>. What',
114+
);
115+
116+
const opened: string[] = [];
117+
const link = findElement(
118+
Markdown({
119+
source: "See [Ways to build your list](document:approaches).",
120+
openDocument: (id) => opened.push(id),
121+
}),
122+
"a",
123+
);
124+
let prevented = false;
125+
(
126+
link?.props["onClick"] as
127+
| ((event: { preventDefault(): void }) => void)
128+
| undefined
129+
)?.({
130+
preventDefault: () => {
131+
prevented = true;
132+
},
133+
});
134+
expect(opened).toEqual(["approaches"]);
135+
expect(prevented).toBe(true);
136+
});
137+
99138
test("an approval asks about the document in words", () => {
100139
const html = renderToStaticMarkup(
101140
<RoomThread

0 commit comments

Comments
 (0)