Skip to content

Commit

Permalink
Add attribute panel widget to inline math
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonking committed Mar 3, 2025
1 parent 84f2bd5 commit eb0e266
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/context-editor/src/components/AttributePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export function AttributePanel({ panelPosition, viewRef }: AttributePanelProps)
)
);
};
// Marks will automatically show names, so it is only the 'inline' types
// that are not marks that need to be specifically rendered
const showName = node.type?.name === "math_inline";

return (
<>
{node && (
Expand Down Expand Up @@ -135,6 +139,9 @@ export function AttributePanel({ panelPosition, viewRef }: AttributePanelProps)
}}
>
<div className="text-sm">Attributes</div>
{showName ? (
<div className="mt-4 text-sm font-bold">{node.type?.name}</div>
) : null}
{Object.keys(nodeAttrs).map((attrKey) => {
if (attrKey === "data") {
return null;
Expand Down
7 changes: 5 additions & 2 deletions packages/context-editor/src/plugins/structureDecorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ export default () => {
Decoration.widget(pos, wrapWidget(state, node, pos, setPanelPosition))
);
}
if (!node.type.isBlock && node.marks.length) {
/* If it's an inline node with marks */
const isInline = !node.type.isBlock;
const hasMarks = !!node.marks.length;
const isMath = node.type.name === "math_inline";
if (isInline && (hasMarks || isMath)) {
/* If it's an inline node with marks OR is inline math */
decorations.push(
Decoration.widget(pos, wrapWidget(state, node, pos, setPanelPosition))
);
Expand Down
4 changes: 4 additions & 0 deletions packages/context-editor/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,7 @@
padding-left: 1rem;
border-left: solid 4px rgba(181, 181, 181, 0.5);
}
.ProseMirror math-inline {
/* Otherwise the widget button is too hard to click without triggering math */
margin-left: 4px;
}

0 comments on commit eb0e266

Please sign in to comment.