Skip to content

Commit 736a8ff

Browse files
committed
Fixed AI Menu position for empty blocks
1 parent 251e82b commit 736a8ff

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/ai/src/core/extensions/AIMenu/AIMenuPlugin.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
import { Plugin, PluginKey, PluginView } from "prosemirror-state";
77
import { EditorView } from "prosemirror-view";
88

9-
export type AIMenuState = UiElementPosition;
9+
export type AIMenuState = UiElementPosition & {
10+
blockIsEmpty: boolean;
11+
};
1012

1113
export class AIMenuView implements PluginView {
1214
public state?: AIMenuState;
@@ -100,6 +102,7 @@ export class AIMenuView implements PluginView {
100102
this.state = {
101103
show: true,
102104
referencePos: this.domElement.getBoundingClientRect(),
105+
blockIsEmpty: blockInfo.contentNode.content.size === 0,
103106
};
104107

105108
this.emitUpdate();

packages/ai/src/react/components/AIMenu/AIMenuController.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ export const AIMenuController = (props: { aiMenu?: FC<AIMenuProps> }) => {
4141
return (
4242
<div
4343
ref={ref}
44-
style={{ ...style, width: state.referencePos.width }}
44+
style={{
45+
...style,
46+
width: state.referencePos.width,
47+
top: state.blockIsEmpty ? -state.referencePos.height - 3 : style.top,
48+
}}
4549
{...getFloatingProps()}>
4650
<Component />
4751
</div>

0 commit comments

Comments
 (0)