Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/chat/thread-anchor-button.tsx
14422 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020-2026 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Button, Tooltip } from "antd";
7
import { Icon } from "@cocalc/frontend/components";
8
import { COLORS } from "@cocalc/util/theme";
9
import type { ChatActions } from "./actions";
10
11
interface Props {
12
anchorId: string;
13
actions: ChatActions;
14
}
15
16
const BUTTON_STYLE = {
17
background: COLORS.BLUE_LLL,
18
borderColor: COLORS.BLUE_LL,
19
color: COLORS.BLUE_D,
20
} as const;
21
22
export function ThreadAnchorButton({ anchorId, actions }: Props) {
23
const editorActions = actions.frameTreeActions as any;
24
if (!editorActions || typeof editorActions.jumpToAnchor !== "function") {
25
return null;
26
}
27
// Prefer the location-only label (`path:line`); the opaque hash is
28
// not useful in a "Jump to ..." button. Fall back to the full label
29
// (which includes the hash) only when no jump-label is available, and
30
// finally to a bare "Jump to anchor".
31
const jumpTarget: string | undefined =
32
editorActions.getAnchorJumpLabel?.(anchorId) ??
33
editorActions.getAnchorLabel?.(anchorId);
34
const label = jumpTarget ? `Jump to ${jumpTarget}` : "Jump to anchor";
35
36
return (
37
<Tooltip title="Jump to this anchor in the source">
38
<Button
39
style={BUTTON_STYLE}
40
icon={<Icon name="comment" />}
41
onClick={() => editorActions.jumpToAnchor(anchorId)}
42
>
43
{label}
44
</Button>
45
</Tooltip>
46
);
47
}
48
49