Skip to content

Commit 8ee0dcb

Browse files
committed
fix inconsistencies in jupyter cells
1 parent f4deb94 commit 8ee0dcb

File tree

9 files changed

+66
-59
lines changed

9 files changed

+66
-59
lines changed

src/packages/frontend/_jupyter.sass

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,4 @@
110110

111111
.cc-jupyter-buttonbar-dropdown
112112
.ant-dropdown-menu-item
113-
font-size: 12px !important
114113
color: $COL_GRAY_D !important

src/packages/frontend/jupyter/cell-buttonbar-menu.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,14 @@ export function CodeBarDropdownMenu({ actions, frameActions, id, cell }) {
174174
icon: <Icon name="arrow-down" />,
175175
onClick: () => move_cell(1),
176176
},
177-
];
177+
].map(({ key, label, icon, onClick }) => {
178+
return {
179+
key,
180+
label,
181+
onClick,
182+
icon: <span style={{ width: "24px" }}>{icon}</span>,
183+
};
184+
});
178185

179186
return (
180187
<Dropdown
@@ -184,13 +191,8 @@ export function CodeBarDropdownMenu({ actions, frameActions, id, cell }) {
184191
mouseLeaveDelay={1.5}
185192
overlayClassName={"cc-jupyter-buttonbar-dropdown"}
186193
>
187-
<Button
188-
type="text"
189-
size="small"
190-
style={CODE_BAR_BTN_STYLE}
191-
icon={<Icon name="ellipsis" rotate="90" />}
192-
>
193-
More
194+
<Button type="text" size="small" style={CODE_BAR_BTN_STYLE}>
195+
<Icon name="ellipsis" rotate="90" style={{ fontSize: "20px" }} />
194196
</Button>
195197
</Dropdown>
196198
);

src/packages/frontend/jupyter/cell-buttonbar.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ export const CellButtonBar: React.FC<Props> = React.memo(
168168
id={id}
169169
actions={actions}
170170
llmTools={llmTools}
171-
is_current={is_current}
172171
/>
173172
);
174173
}

src/packages/frontend/jupyter/cell-list.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,11 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
346346
index: index + EXTRA_TOP_CELLS,
347347
});
348348
// hack which seems necessary for jupyter at least.
349-
requestAnimationFrame(() =>
350-
virtuosoRef.current?.scrollToIndex({
351-
index: index + EXTRA_TOP_CELLS,
352-
}),
349+
requestAnimationFrame(
350+
() =>
351+
virtuosoRef.current?.scrollToIndex({
352+
index: index + EXTRA_TOP_CELLS,
353+
}),
353354
);
354355
}
355356
} else if (scroll.startsWith("list")) {
@@ -359,23 +360,25 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
359360
index: index + EXTRA_TOP_CELLS,
360361
align: "end",
361362
});
362-
requestAnimationFrame(() =>
363-
virtuosoRef.current?.scrollToIndex({
364-
index: index + EXTRA_TOP_CELLS,
365-
align: "end",
366-
}),
363+
requestAnimationFrame(
364+
() =>
365+
virtuosoRef.current?.scrollToIndex({
366+
index: index + EXTRA_TOP_CELLS,
367+
align: "end",
368+
}),
367369
);
368370
} else if (scroll == "list down") {
369371
const index = virtuosoRangeRef.current?.endIndex;
370372
virtuosoRef.current?.scrollToIndex({
371373
index: index + EXTRA_TOP_CELLS,
372374
align: "start",
373375
});
374-
requestAnimationFrame(() =>
375-
virtuosoRef.current?.scrollToIndex({
376-
index: index + EXTRA_TOP_CELLS,
377-
align: "start",
378-
}),
376+
requestAnimationFrame(
377+
() =>
378+
virtuosoRef.current?.scrollToIndex({
379+
index: index + EXTRA_TOP_CELLS,
380+
align: "start",
381+
}),
379382
);
380383
}
381384
}
@@ -795,7 +798,6 @@ function DivTempHeight({ children, height }) {
795798

796799
const style: CSS = {
797800
minHeight: height,
798-
paddingTop: "5px", // for the cell buttons on top of the input, otherwise they're cut off
799801
};
800802

801803
return (

src/packages/frontend/jupyter/cell-output-toggle.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import { Button, Tooltip } from "antd";
1313
const SCROLLED_STYLE: React.CSSProperties = {
1414
fontSize: "inherit",
1515
padding: 0,
16-
display: "flex", // flex used to move output prompt to bottom.
17-
flexDirection: "column",
1816
height: "auto",
19-
cursor: "pointer",
17+
display: "flex",
18+
flexDirection: "column",
2019
} as const;
2120

2221
const NORMAL_STYLE: React.CSSProperties = {
@@ -52,11 +51,11 @@ export const OutputToggle: React.FC<OutputToggleProps> = React.memo(
5251
onDoubleClick={collapse_output}
5352
>
5453
{children}
55-
<div style={{ flex: 1 }} /> {/* use up all space */}
54+
<span style={{ flex: 1 }} />
5655
</Button>
5756
</Tooltip>
5857
);
59-
}
58+
},
6059
);
6160

6261
interface CollapsedOutputProps {
@@ -85,5 +84,5 @@ export const CollapsedOutput: React.FC<CollapsedOutputProps> = React.memo(
8584
</Button>
8685
</div>
8786
);
88-
}
87+
},
8988
);

src/packages/frontend/jupyter/cell.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,26 @@ export const Cell: React.FC<Props> = React.memo((props: Props) => {
256256
borderLeft: `10px solid ${color}`,
257257
borderRight: `10px solid ${color}`,
258258
borderRadius: "10px",
259-
padding: "2px",
260-
// The bigger top margin when in fully read only mode (no props.actions, e.g., timetravel view)
261-
// is to deal with the fact that the insert cell bar isn't rendered, but some of the controls off
262-
// to the right assume it is.
263-
margin: props.actions != null ? "10px 15px 2px 5px" : "20px 15px 2px 5px",
264259
position: "relative",
260+
// The bigger top margin when in fully read only mode (no props.actions,
261+
// e.g., timetravel view) is to deal with the fact that the insert cell
262+
// bar isn't rendered, but some of the controls off
263+
// to the right assume it is.
264+
// The bigger BOTTOM margin when no output is because otherwise the big
265+
// top margin makes things look very weirdly unbalanced.
266+
...(props.cell.get("output") || props.actions == null
267+
? {
268+
padding: "2px",
269+
margin:
270+
props.actions != null ? "10px 15px 2px 5px" : "20px 15px 2px 5px",
271+
}
272+
: {
273+
padding: "2px 2px 15px 2px",
274+
margin:
275+
props.actions != null
276+
? "10px 15px -15px 5px"
277+
: "20px 15px -15px 5px",
278+
}),
265279
};
266280

267281
if (props.is_selected) {

src/packages/frontend/jupyter/codemirror-editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ export const CodeMirrorEditor: React.FC<CodeMirrorEditorProps> = ({
769769
}
770770

771771
function renderPlaceholder() {
772-
if (!is_current || cmValue) {
772+
if (!is_current || cmValue || !setShowAICellGen) {
773773
return;
774774
}
775775
return (

src/packages/frontend/jupyter/commands.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,23 +445,31 @@ export function commands(actions: AllActions): {
445445
},
446446

447447
"merge cell with next cell": {
448+
i: "merge-cells-outlined",
449+
ir: "90",
448450
m: "Merge Cell Below",
449451
f: () => actions.frame_actions?.merge_cell_below(),
450452
},
451453

452454
"merge cell with previous cell": {
455+
i: "merge-cells-outlined",
456+
ir: "90",
453457
m: "Merge Cell Above",
454458
f: () => actions.frame_actions?.merge_cell_above(),
455459
},
456460

457461
"merge cells": {
462+
i: "merge-cells-outlined",
463+
ir: "90",
458464
m: "Merge Selected Cells",
459465
k: [{ mode: "escape", shift: true, which: 77 }],
460466
f: () => actions.frame_actions?.merge_selected_cells(),
461467
},
462468

463469
"merge selected cells": {
464470
// why is this in jupyter; it's the same as the above?
471+
i: "merge-cells-outlined",
472+
ir: "90",
465473
m: "Merge selected cells",
466474
f: () => actions.frame_actions?.merge_selected_cells(),
467475
},

src/packages/frontend/jupyter/llm/cell-tool.tsx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import {
1818
} from "antd";
1919
import { CSSProperties, useEffect, useMemo, useState } from "react";
2020
import { Entries } from "type-fest";
21-
22-
import { CSS, useAsyncEffect } from "@cocalc/frontend/app-framework";
21+
import { useAsyncEffect } from "@cocalc/frontend/app-framework";
2322
import getChatActions from "@cocalc/frontend/chat/get-actions";
2423
import { A, Paragraph, RawPrompt, Text } from "@cocalc/frontend/components";
2524
import AIAvatar from "@cocalc/frontend/components/ai-avatar";
@@ -38,7 +37,6 @@ import track from "@cocalc/frontend/user-tracking";
3837
import { LLMTools } from "@cocalc/jupyter/types";
3938
import { LanguageModel } from "@cocalc/util/db-schema/llm-utils";
4039
import { capitalize, getRandomColor, unreachable } from "@cocalc/util/misc";
41-
import { COLORS } from "@cocalc/util/theme";
4240
import { JupyterActions } from "../browser-actions";
4341
import { CODE_BAR_BTN_STYLE } from "../consts";
4442
import { cellOutputToText } from "../output-messages/ansi";
@@ -48,7 +46,6 @@ interface Props {
4846
id: string;
4947
style?: CSSProperties;
5048
llmTools?: LLMTools;
51-
is_current?: boolean;
5249
}
5350

5451
const CONTENT_WIDTH = 600;
@@ -213,7 +210,6 @@ export function LLMCellTool({
213210
id,
214211
style,
215212
llmTools,
216-
is_current,
217213
}: Props) {
218214
const { actions: project_actions, onCoCalcCom } = useProjectContext();
219215
const { project_id, path } = useFrameContext();
@@ -388,13 +384,6 @@ export function LLMCellTool({
388384
}
389385

390386
function renderDropdown() {
391-
const txtStyle: CSS = is_current
392-
? {
393-
color: COLORS.AI_ASSISTANT_FONT,
394-
fontWeight: "bold",
395-
}
396-
: {};
397-
398387
return (
399388
<Dropdown
400389
trigger={["click"]}
@@ -406,7 +395,8 @@ export function LLMCellTool({
406395
key: mode,
407396
label: (
408397
<Tooltip title={action.descr} placement={"left"}>
409-
<Icon name={action.icon} /> {capitalize(mode)}
398+
<Icon name={action.icon} style={{ marginRight: "5px" }} />{" "}
399+
{capitalize(mode)}
410400
</Tooltip>
411401
),
412402
onClick: () => setMode(mode as Mode),
@@ -415,22 +405,16 @@ export function LLMCellTool({
415405
),
416406
}}
417407
>
418-
<Tooltip title="Use AI assistance on this cell">
408+
<Tooltip title="Use AI assitant on this cell">
419409
<Button
420410
disabled={isQuerying}
421411
type="text"
422412
size="small"
423413
style={CODE_BAR_BTN_STYLE}
424-
icon={
425-
<AIAvatar
426-
size={14}
427-
style={{ top: "1px" }}
428-
iconColor={is_current ? COLORS.AI_ASSISTANT_FONT : undefined}
429-
/>
430-
}
414+
icon={<AIAvatar size={14} style={{ top: "1px" }} />}
431415
>
432416
<Space size="small">
433-
<span style={txtStyle}>Tools</span>
417+
Assistant
434418
<Icon name="angle-down" />
435419
</Space>
436420
</Button>

0 commit comments

Comments
 (0)