Skip to content

Commit 2e911b0

Browse files
committed
fix #4392 -- font size of text in the popup margin notes in the latex
- also use markdown usually for showing LLM prompt details...
1 parent 87b028b commit 2e911b0

File tree

6 files changed

+85
-51
lines changed

6 files changed

+85
-51
lines changed
Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
11
import { CSS } from "@cocalc/frontend/app-framework";
22
import { useBottomScroller } from "@cocalc/frontend/app-framework/use-bottom-scroller";
3-
import { Paragraph } from "@cocalc/frontend/components";
43
import { COLORS } from "@cocalc/util/theme";
4+
import StaticMarkdown from "@cocalc/frontend/editors/slate/static-markdown";
5+
import { Paragraph } from "@cocalc/frontend/components";
6+
7+
const STYLE = {
8+
border: "1px solid lightgrey",
9+
borderRadius: "5px",
10+
margin: "5px 0",
11+
padding: "10px",
12+
overflowY: "auto",
13+
maxHeight: "150px",
14+
fontSize: "85%",
15+
fontFamily: "monospace",
16+
whiteSpace: "pre-wrap",
17+
color: COLORS.GRAY_M,
18+
} as const;
519

620
interface Props {
721
input: JSX.Element | string;
822
style?: CSS;
923
scrollBottom?: boolean;
1024
}
1125

12-
export function RawPrompt({ input, style, scrollBottom = false }: Props) {
26+
export function RawPrompt({
27+
input,
28+
style: style0,
29+
scrollBottom = false,
30+
}: Props) {
1331
const ref = useBottomScroller(scrollBottom, input);
14-
15-
return (
16-
<Paragraph
17-
ref={ref}
18-
style={{
19-
border: "1px solid lightgrey",
20-
borderRadius: "5px",
21-
margin: "5px 0",
22-
padding: "10px",
23-
overflowY: "auto",
24-
maxHeight: "150px",
25-
fontSize: "85%",
26-
fontFamily: "monospace",
27-
whiteSpace: "pre-wrap",
28-
color: COLORS.GRAY_M,
29-
...style,
30-
}}
31-
>
32-
{input}
33-
</Paragraph>
34-
);
32+
const style = { ...STYLE, ...style0 };
33+
if (typeof input == "string") {
34+
// this looks so much nicer; I realize it doesn't implement scrollBottom.
35+
// But just dropping the input as plain text like below just seems
36+
// utterly broken!
37+
return <StaticMarkdown style={style} value={input} />;
38+
} else {
39+
return (
40+
<Paragraph ref={ref} style={style}>
41+
{input}
42+
</Paragraph>
43+
);
44+
}
3545
}

src/packages/frontend/frame-editors/code-editor/actions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,7 @@ export class Actions<
13741374
// to make typescript happy
13751375
return;
13761376
}
1377-
this.set_frame_tree({ id, font_size });
1378-
this.focus(id);
1377+
this.set_font_size(id, font_size);
13791378
}
13801379

13811380
increase_font_size(id: string): void {
@@ -1386,6 +1385,9 @@ export class Actions<
13861385
this.change_font_size(-1, id);
13871386
}
13881387

1388+
// ATTN: this is overloaded in some derived classes, eg. latex to adjust settings
1389+
// based on font size changing. Code should call this to set the font size instead
1390+
// of directly modifying frame tree.
13891391
set_font_size(id: string, font_size: number): void {
13901392
this.set_frame_tree({ id, font_size });
13911393
this.focus(id);

src/packages/frontend/frame-editors/latex-editor/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,4 +1597,9 @@ export class Actions extends BaseActions<LatexEditorState> {
15971597
chatgptCodeDescription(): string {
15981598
return "Put any LaTeX you generate in the answer in a fenced code block with info string 'tex'.";
15991599
}
1600+
1601+
set_font_size(id: string, font_size: number): void {
1602+
super.set_font_size(id, font_size);
1603+
this.update_gutters_soon();
1604+
}
16001605
}

src/packages/frontend/frame-editors/latex-editor/editor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { CodemirrorEditor } from "../code-editor/codemirror-editor";
1414
import { createEditor } from "../frame-tree/editor";
1515
import { EditorDescription } from "../frame-tree/types";
1616
import { TableOfContents } from "../markdown-editor/table-of-contents";
17-
//import { SETTINGS_SPEC } from "../settings/editor";
1817
import { terminal } from "../terminal-editor/editor";
1918
import { time_travel } from "../time-travel-editor/editor";
2019
import { Build } from "./build";

src/packages/frontend/frame-editors/latex-editor/gutters.tsx

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
// one gets a gutter mark, with pref to errors. The main error log shows everything, so this should be OK.
1010

1111
import { Popover } from "antd";
12-
1312
import { Icon } from "@cocalc/frontend/components";
14-
//import { Actions } from "@cocalc/frontend/frame-editors/code-editor/actions";
1513
import { Localize } from "@cocalc/frontend/app/localize";
1614
import HelpMeFix from "@cocalc/frontend/frame-editors/llm/help-me-fix";
1715
import { capitalize } from "@cocalc/util/misc";
18-
import { Actions } from "./actions";
16+
import type { Actions } from "./actions";
1917
import { SPEC, SpecItem } from "./errors-and-warnings";
2018
import { Error, IProcessedLatexLog } from "./latex-log-parser";
19+
import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
2120

2221
export function update_gutters(opts: {
2322
log: IProcessedLatexLog;
@@ -36,27 +35,36 @@ export function update_gutters(opts: {
3635
opts.set_gutter(
3736
item.file,
3837
item.line - 1,
39-
component(
40-
item.level,
41-
item.message,
42-
item.content,
43-
opts.actions,
44-
group,
45-
item.line,
46-
),
38+
<Component
39+
level={item.level}
40+
message={item.message}
41+
content={item.content}
42+
actions={opts.actions}
43+
group={group}
44+
line={item.line}
45+
/>,
4746
);
4847
}
4948
}
5049
}
5150

52-
function component(
53-
level: string,
54-
message: string,
55-
content: string | undefined,
56-
actions: Actions,
57-
group: string,
58-
line: number,
59-
) {
51+
function Component({
52+
level,
53+
message,
54+
content,
55+
actions,
56+
group,
57+
line,
58+
}: {
59+
level: string;
60+
message: string;
61+
content: string | undefined;
62+
actions: Actions;
63+
group: string;
64+
line: number;
65+
}) {
66+
const { desc } = useFrameContext();
67+
const fontSize = desc?.get("font_size");
6068
const spec: SpecItem = SPEC[level];
6169
if (content === undefined) {
6270
content = message;
@@ -69,10 +77,9 @@ function component(
6977
return (
7078
<Localize>
7179
<Popover
72-
title={message}
73-
content={
74-
<div>
75-
{content}
80+
title={
81+
<span style={{ fontSize }}>
82+
{message}{" "}
7683
{group == "errors" && (
7784
<>
7885
<br />
@@ -97,14 +104,26 @@ function component(
97104
/>
98105
</>
99106
)}
107+
</span>
108+
}
109+
content={
110+
<div
111+
style={{
112+
fontSize,
113+
maxWidth: "70vw",
114+
maxHeight: "70vh",
115+
overflow: "auto",
116+
}}
117+
>
118+
{content}
100119
</div>
101120
}
102121
placement={"right"}
103122
mouseEnterDelay={0}
104123
>
105124
<Icon
106125
name={spec.icon}
107-
style={{ color: spec.color, cursor: "pointer" }}
126+
style={{ color: spec.color, cursor: "pointer", fontSize }}
108127
/>
109128
</Popover>
110129
</Localize>

src/packages/frontend/frame-editors/llm/help-me-fix.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Alert, Button, Space } from "antd";
77
import type { BaseButtonProps } from "antd/lib/button/button";
88
import { CSSProperties, useState } from "react";
99
import useAsyncEffect from "use-async-effect";
10-
1110
import { useLanguageModelSetting } from "@cocalc/frontend/account/useLanguageModelSetting";
1211
import getChatActions from "@cocalc/frontend/chat/get-actions";
1312
import { AIAvatar, RawPrompt } from "@cocalc/frontend/components";

0 commit comments

Comments
 (0)