Skip to content

Commit

Permalink
fix: Allows you to manage the context menu's position regardless of t…
Browse files Browse the repository at this point in the history
…he editor's position.
  • Loading branch information
starker-xp committed Jan 11, 2024
1 parent 15bc19c commit b3d9a04
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/renderer-vue/src/editor/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,19 @@ export function useContextMenu(viewModel: Ref<IBaklavaViewModel>) {

function open(ev: MouseEvent) {
show.value = true;
x.value = ev.pageX - 30;
y.value = ev.pageY - 40;
const target = ev.target as Element;
const element = target.closest(".baklava-node");
if (!element) {
x.value = ev.offsetX;
y.value = ev.offsetY;
return;
}
const bounding = target.getBoundingClientRect();
const editor = document.querySelector(".baklava-editor") as Element;

const editorBounding = editor.getBoundingClientRect();
x.value = bounding.x + ev.offsetX - editorBounding.x;
y.value = bounding.y + ev.offsetY - editorBounding.y;
}

function onClick(value: string) {
Expand Down

0 comments on commit b3d9a04

Please sign in to comment.