From d25a74a20ad5ca5151b0871eedb2f56d29dbae07 Mon Sep 17 00:00:00 2001 From: Sebastien Benard Date: Wed, 29 Nov 2023 13:04:47 +0100 Subject: [PATCH] Cleanup ctx menu positionner --- src/electron.renderer/ui/Modal.hx | 6 ++-- src/electron.renderer/ui/modal/ContextMenu.hx | 30 +++++++------------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/electron.renderer/ui/Modal.hx b/src/electron.renderer/ui/Modal.hx index f8d447156..ab3d3c408 100644 --- a/src/electron.renderer/ui/Modal.hx +++ b/src/electron.renderer/ui/Modal.hx @@ -66,6 +66,8 @@ class Modal extends dn.Process { function applyAnchor() { + anchorInvalidated = false; + var docHei = App.ME.jDoc.innerHeight(); switch anchor { @@ -304,9 +306,7 @@ class Modal extends dn.Process { override function postUpdate() { super.postUpdate(); - if( anchorInvalidated ) { - anchorInvalidated = false; + if( anchorInvalidated ) applyAnchor(); - } } } diff --git a/src/electron.renderer/ui/modal/ContextMenu.hx b/src/electron.renderer/ui/modal/ContextMenu.hx index 7adde3c6a..a7093b725 100644 --- a/src/electron.renderer/ui/modal/ContextMenu.hx +++ b/src/electron.renderer/ui/modal/ContextMenu.hx @@ -26,6 +26,9 @@ class ContextMenu extends ui.Modal { ME.destroy(); ME = this; + setTransparentMask(); + addClass("contextMenu"); + if( openEvent!=null || jNear!=null ) { var jEventTarget = jNear!=null ? jNear : new J(openEvent.target); jAttachTarget = jEventTarget; @@ -34,28 +37,21 @@ class ContextMenu extends ui.Modal { jAttachTarget.addClass("contextMenuOpen"); if( jEventTarget.is("button") || jEventTarget.parent().is("button") || jNear!=null ) - placer = ()->setAnchor( MA_JQuery(jEventTarget) ); + setAnchor( MA_JQuery(jEventTarget) ); else if( openEvent!=null ) - placer = ()->setAnchor( MA_Coords(new Coords(openEvent.pageX, openEvent.pageY)) ); - + setAnchor( MA_Coords(new Coords(openEvent.pageX, openEvent.pageY)) ); } else { jAttachTarget = new J(""); if( m!=null ) - placer = ()->setAnchor( MA_Coords(m) ); + setAnchor( MA_Coords(m) ); } - - setTransparentMask(); - addClass("contextMenu"); - placer(); } public function enableNoWrap() { jContent.addClass("noWrap"); } - dynamic function placer() {} - public static inline function isOpen() return ME!=null && !ME.destroyed; override function onDispose() { @@ -104,14 +100,8 @@ class ContextMenu extends ui.Modal { } - override function onResize() { - super.onResize(); - checkPosition(); - } - - - function checkPosition() { - placer(); + override function applyAnchor() { + super.applyAnchor(); var pad = 16; var docHei = App.ME.jDoc.innerHeight(); @@ -127,7 +117,7 @@ class ContextMenu extends ui.Modal { public function addTitle(str:LocaleString) { var jTitle = new J('
$str
'); jTitle.appendTo(jContent); - checkPosition(); + applyAnchor(); } public function add(a:ContextAction) { @@ -160,7 +150,7 @@ class ContextMenu extends ui.Modal { if( a.separatorAfter ) jButton.addClass("separatorAfter"); - checkPosition(); + applyAnchor(); return jButton; } } \ No newline at end of file