Procházet zdrojové kódy

[scene] Fix scene comp from stealing focus when editing inputs

Also added mouse capture during drags
Clément Espeute před 9 měsíci
rodič
revize
687cb20cb1
1 změnil soubory, kde provedl 25 přidání a 1 odebrání
  1. 25 1
      hide/comp/Scene.hx

+ 25 - 1
hide/comp/Scene.hx

@@ -36,7 +36,31 @@ class Scene extends hide.comp.Component implements h3d.IDrawable {
 		element.addClass("hide-scene-container");
 		canvas = cast new Element("<canvas class='hide-scene' style='width:100%;height:100%'/>").appendTo(element)[0];
 
-		canvas.addEventListener("mousemove",function(_) canvas.focus());
+		canvas.addEventListener("mousemove",function(_) {
+			switch(js.Browser.document.activeElement?.tagName) {
+				// Don't steal focus if we are curently editing an <input>
+				case "INPUT":
+					return;
+				default:
+					canvas.focus();
+			}
+		});
+
+		// Prevent mouse from disapearing when clicking on the canvas when it wasn't focused (when an input node was focused for example)
+		canvas.addEventListener("mousedown",function(e: js.html.MouseEvent) {
+			if(js.Browser.document.activeElement != canvas) {
+				canvas.focus();
+				e.preventDefault();
+			}
+		});
+
+		// Capture mouse during drags (usefull when dragging the gizmo around so it doesn't loose focus)
+		canvas.addEventListener("pointerdown", function(e: js.html.PointerEvent) {
+			if(js.Browser.document.activeElement == canvas) {
+				canvas.setPointerCapture(e.pointerId);
+			}
+		});
+
 		canvas.addEventListener("mouseleave",function(_) canvas.blur());
 		canvas.oncontextmenu = function(e){
 			e.stopPropagation();