Skip to content

Commit eb02e49

Browse files
committed
board: ensure z index always set
1 parent 032d552 commit eb02e49

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { Tool } from "./tools/spec";
1717
import { Element, Elements } from "./types";
1818
import { uuid } from "@cocalc/util/misc";
19+
import { getPageSpan } from "./math";
1920

2021
export interface State extends CodeEditorState {
2122
elements: Elements;
@@ -62,6 +63,14 @@ export class Actions extends BaseActions<State> {
6263
const id = uuid().slice(0, 8);
6364
obj = { id, ...obj };
6465
}
66+
if (obj.z == null) {
67+
// most calls to createElement should NOT resort to having to do this.
68+
let { zMax } = getPageSpan(
69+
this.store.get("elements").toJS() as Element[],
70+
0
71+
);
72+
obj.z = zMax + 1;
73+
}
6574
this.setElement(obj, commit);
6675
return obj as Element;
6776
}

src/packages/frontend/frame-editors/whiteboard-editor/canvas.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ export default function Canvas({
387387
) {
388388
const { id } = actions.createElement(
389389
{
390+
z: transforms.zMax + 1,
390391
...data,
391392
type: selectedTool,
392393
str: "",
@@ -472,6 +473,7 @@ export default function Canvas({
472473
{
473474
x: xMin,
474475
y: yMin,
476+
z: transforms.zMax + 1,
475477
w: xMax - xMin + 1,
476478
h: yMax - yMin + 1,
477479
data: { path: compressPath(path), ...getPenParams() },

src/packages/frontend/frame-editors/whiteboard-editor/elements/code.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,26 @@ export default function Code({ element, focused }: Props) {
1414
const [value, setValue] = useState<string>(element.str ?? "");
1515
const frame = useFrameContext();
1616

17+
const style = {
18+
fontSize: element.data?.fontSize,
19+
border: element.data?.color
20+
? `2px solid ${element.data?.color}`
21+
: undefined,
22+
};
23+
1724
if (!focused) {
1825
const val =
1926
"```py\n" + (element.str?.trim() ? element.str : "Type code") + "\n```";
2027
return (
21-
<Markdown
22-
value={val}
23-
style={{
24-
width: "100%",
25-
height: "100%",
26-
color: element.data?.color,
27-
fontSize: element.data?.fontSize,
28-
}}
29-
/>
28+
<div style={style}>
29+
<Markdown
30+
value={val}
31+
style={{
32+
width: "100%",
33+
height: "100%",
34+
}}
35+
/>
36+
</div>
3037
);
3138
}
3239

@@ -37,6 +44,7 @@ export default function Code({ element, focused }: Props) {
3744

3845
return (
3946
<Input.TextArea
47+
style={style}
4048
className="nodrag"
4149
placeholder="Type code"
4250
autoFocus

src/packages/frontend/frame-editors/whiteboard-editor/math.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export function getPageSpan(
8383
yMin -= margin;
8484
xMax += margin;
8585
yMax += margin;
86+
// do NOT add to z!
8687
}
8788
return { xMin, xMax, yMin, yMax, zMin, zMax };
8889
}
@@ -131,3 +132,4 @@ export function scalePath(path: Point[], scale): Point[] {
131132
}
132133
return v;
133134
}
135+

0 commit comments

Comments
 (0)