Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cell Numbers #320

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions packages/frontend/src/notebook/notebook_cell.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,48 @@
height: auto;
max-width: 100%;
}

.cell-number {
display: flex;
align-items: center;
position: relative;
}

.cell-number-gutter p {
width: 100%;
padding: 0 -1.2rem 0 1.2rem;
font-size: 0.85rem;
color: --link-color;
background-color: transparent;
border-radius: 0.125rem;
transition: background-color 100ms ease-in-out;
color: gray;
font-family: monospace;
}

.cell {
position: relative;
margin: 0.25em;
display: flex;
flex-direction: row;
}

.cell-gutter {
position: absolute;
transform: translate(-100%, -50%);
left: -0.75rem;
/* Adjusted to sit between number and content */
display: flex;
flex-direction: row;
}

.cell-tag {
color: rgb(156, 163, 175);
font-size: 11pt;
}

.cell-content {
flex-grow: 1;
height: auto;
max-width: 100%;
}
90 changes: 50 additions & 40 deletions packages/frontend/src/notebook/notebook_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ A notebook has two types of cells:
Rich text cells are the same in all notebooks, whereas formal cells are handled
by custom components supplied to the notebook.
*/

export function NotebookEditor<T>(props: {
handle: DocHandle<unknown>;
path: Prop[];
Expand Down Expand Up @@ -225,6 +226,7 @@ export function NotebookEditor<T>(props: {
<span>Click button or press Shift-Enter to create a cell</span>
</div>
</Show>

<ul class="notebook-cells">
<For each={props.notebook.cells}>
{(cell, i) => {
Expand Down Expand Up @@ -290,46 +292,54 @@ export function NotebookEditor<T>(props: {

return (
<li>
<NotebookCell
cellId={cell.id}
actions={cellActions}
tag={
cell.tag === "formal"
? props.cellLabel?.(cell.content)
: undefined
}
>
<Switch>
<Match when={cell.tag === "rich-text"}>
<RichTextCellEditor
cellId={cell.id}
handle={props.handle}
path={[...props.path, "cells", i()]}
isActive={isActive()}
actions={cellActions}
/>
</Match>
<Match when={cell.tag === "formal"}>
<props.formalCellEditor
content={(cell as FormalCell<T>).content}
changeContent={(f) => {
props.changeNotebook((nb) => {
f((nb.cells[i()] as FormalCell<T>).content);
});
}}
isActive={isActive()}
actions={cellActions}
/>
</Match>
<Match when={cell.tag === "stem"}>
<StemCellEditor
completions={replaceCommands(i())}
isActive={isActive()}
actions={cellActions}
/>
</Match>
</Switch>
</NotebookCell>
<div class="cell-number">
<div class="cell-number-gutter">
<p>{i() + 1}</p>
</div>
<NotebookCell
cellId={cell.id}
actions={cellActions}
tag={
cell.tag === "formal"
? props.cellLabel?.(cell.content)
: undefined
}
>
<Switch>
<Match when={cell.tag === "rich-text"}>
<RichTextCellEditor
cellId={cell.id}
handle={props.handle}
path={[...props.path, "cells", i()]}
isActive={isActive()}
actions={cellActions}
/>
</Match>
<Match when={cell.tag === "formal"}>
<props.formalCellEditor
content={(cell as FormalCell<T>).content}
changeContent={(f) => {
props.changeNotebook((nb) => {
f(
(nb.cells[i()] as FormalCell<T>)
.content,
);
});
}}
isActive={isActive()}
actions={cellActions}
/>
</Match>
<Match when={cell.tag === "stem"}>
<StemCellEditor
completions={replaceCommands(i())}
isActive={isActive()}
actions={cellActions}
/>
</Match>
</Switch>
</NotebookCell>
</div>
</li>
);
}}
Expand Down
Loading